If you want to learn advanced Linux commands and become a "Linux Ninja", you are in the right place. Now it's Kung Fu time!
Before starting this article, I recommend that you read Introduction to Linux Commands if you haven't already. In this way, those who know can refresh their knowledge, and those who do not know can learn new information. If you want to become a "Linux Ninja", you are in the right place. Now it's Kung Fu time!
Some of the commands that will be explained in this article Introduction to Linux Commands You must have seen it in the article. It's good to do lots of repetitions, grasshopper…
Again, as in the previous article, I will start this article with the Linux command structure. So if you're ready, let's get started!
Introduction to Kung Fu classes
In order to establish a solid connection and consolidate the subject thoroughly, I will start from the very basics under this title.
As you may remember from the previous article, Linux commands generally use the following syntax.
<-option(s)> <parameter (if any)>
Options are generally defined as single letters. These are the initials of the options. Long versions of these options can also be found. Even in some commands, the option with the same function can be found in both short and long form (-s
/ --size
as).
When typing options in Linux commands -
(hyphen) is used. If it is written in long form --
(two dashes) is used.
Let's continue with the examples.
--help
To get information about a command --help
option is used. To go into a little more detail:
ls --help
When you type the command, on the screen ls
You will see output listing the parameters the command can take and briefly explaining them. Here ls
command, --help
is an option.
cd /
working directory when you type the command /
(root) directory. Here cd
command, /
is the parameter.
You do not have to use options and parameters in all commands at the same time. Some commands can run without entering options and parameters.
To print command outputs in a more human-readable format (that's you) -h
(--human-readable
) option is used.
If you want to run commands one after another, the linked command (&&
) should be used. If any of the commands do not run, the script will stop and the next command will not work.
&& &&
For example, instead of typing one by one to update your Debian-based system, sudo apt update && sudo apt upgrade -y
you can use the linked script.
| |
If you want to use the output of one command as the input of another command, you must use sequential commands. For example:
| grep search
grep
command lets you search a file or the output of a command. For more detailed information, see the rest of the article. grep You can read the description of the command.
| more
If you want to examine the command result page by page, you can use this command.
| less
Its basic function is the same as the more command, but it includes additional features. For more detailed information man less
You can enter the command, learn the use of the command and all its parameters.
> file.txt
This command is used if you want to print the command output to a file.
>> file.txt
This command is used to add the command output to an existing file.
Now that we have talked about the basics of the job in detail, we can now move on to the commands.
Kung Fu with advanced Linux commands
grep
It is a command to search for expressions in a file. It is mostly used to search the output of another command. It can also be used alone.
grebe
If you want to make the search case insensitive -i
You should use parameter.
grep -i
If you want to do the search in all files and directories under the directory without being specific to a single file -r
You should use parameter.
grep -r
Beginning (^
) and ending ($
You can search using the ) characters. In the example below dosya.txt
in Merhaba
Searching for a place starting with .
grep -ir '^Hello' file.txt
As we mentioned at the beginning, the command is mostly used to search the output of consecutive commands.
ls -lah | grep '^d'
find
As it turns out, it's the command that helps you find what you're looking for. It allows you to find the file or directory you are looking for by scanning files and directories hierarchically. Its usage is as follows:
find -name
If you want to make the search case insensitive -iname
You should use parameter.
find -name
If you don't know the exact name of the file or directory to search, the asterisk (*
You can use the ) character. Star (*
The ) character is a character that encloses all expressions. Simply put, it means "it doesn't matter".
find -name
Likewise, if you want to find files with a specific extension, the asterisk (*
You must enter the desired extension after the ) character. for example .txt
To find files with the extension, you should type:
find -name <*.txt>
To list the files or directories found in the search by separating them -type
parameter is used.
as a parameter d
if you type only directories, f
if you type it will only list the files.
find -type d
To create a size filter when searching -size
parameter is used. Plus (+
) is greater than minus (-
) means less than. k
expression kilobyte, M
expression megabyte, G
The expression is used to mean gigabyte. In the example below, we say only list files larger than 10 kilobytes.
find -name -size +10k
To find empty files or directories -empty
You can use parameter.
find -name -empty
To find files or directories with specific rights -perm
You can use parameter.
find -name -perm 777
If you want to run a command to evaluate the files and directories found in the search result -exec
You should use parameter.
find -name -exec
For example, if you want to delete the files and / or directories you find as a result of the search, you can use the following command.
find -name -exec rm -rf {} \;
To specify the directory depth to be searched, ie how many subdirectories to enter -maxdepth
parameter is used.
find -name -maxdepth X
For example, /etc
searched in directory .conf
You can use the command below to search for all files with the extension extension only in the directory you specify and not search the subdirectories of that directory.
find /etc *.conf -maxdepth 1
find
You can use the command with different parameters according to your needs and make your searches easier. For more detailed information man find
You can use the command.
cat - concatenate-files
It is used to read the contents of the file. Use:
cat cat -n
-n
You can add line numbers to the output with the option.
touch
It is used to create a file. If an existing file is given to the command parameter, it resets the date-time information of the file and preserves its content.
touch filename.extension
threw out
It is used to print values and/or variables to the command line interface.
echo "Pardus"
to the screen Pardus
prints.
whoami
Returns the current user's information.
whoami
whats
It is used to get brief information about commands.
whatis
Mon
It is used to get detailed information about commands.
Man