stdin
), standard output (standard output, stdout
) and standard error output (standard error, stderr
).my_whatever
in the example commands below, this means that this snippet needs to be replaced with something yours. For example - the file name.man
: displays the user manual (help) for the command.pwd
: displays information about the working directory.ls
: displays the contents of a directory.ps
: allows you to view information about running processes.cd
: change working directory.touch
: create a file.mkdir
: create directory.cp
: copy file.mv
: move or delete a file.ln
: create link.<
: redirect stdin
.>
: redirect stdout
.|
: redirection using the pipeline of output of one command to the input of another command.head
: read the beginning of the file.tail
: read end of file.cat
: reading a file and displaying its contents on the screen or concatenating files.rm
: delete the file.kill
: stop the process.grep
: search for information.ag
: advanced search command.tar
: create archives and work with them.stdout
. Usually these results appear in a terminal window.man command_name
: display a manual for a command, that is, reference information.pwd
: display the path to the current working directory. In the course of working with the command line, the user often needs to find out exactly where he is in the system.ls
: output directory contents. This command is also used quite often.ls -a
: show hidden files. The ls
-a
flag is used here. Using flags helps customize the behavior of commands.ls -l
: display detailed information about files.ls -al
.ps
: view running processes.ps -e
: displays information about all running processes, and not just those related to the current user shell. This command is often used in this form.cd my_directory
: change working directory to my_directory
. To go one level higher in the directory tree, use the relative path ../
as my_directory
.touch my_file
: create a file my_file
in a specified path.mkdir my_directory
: create a folder my_directory
in the specified path.mv my_file target_directory
: moves the file my_file
to the target_directory
folder. When specifying the target directory, you must use the absolute path to it (and not a structure like ../
).mv
command can also be used to rename files or folders. For example, it may look like this:mv my_old_file_name.jpg my_new_file_name.jpg
cp my_source_file target_directory
mv my_old_file_name.jpg my_new_file_name.jpg
cp my_source_file target_directory
: create a copy of the my_source_file
file and place it in the target_directory
folder.ln -s my_source_file my_target_file
: create a symbolic link my_target_file
to the file my_source_file
. If you change the link, the source file will also change.my_source_file
is deleted, then my_target_file
will remain. The -s
flag of the ln
command allows you to create links for directories as well.my_command < my_file
: replaces the standard input file descriptor ( stdin
) with the file my_file
. This can be useful if the command is waiting for some data to be entered from the keyboard, and this data is stored in the file in advance.my_command > my_file
: redirects the results of the command, that is, what usually gets into stdout
and is displayed on the screen, in the file my_file
. If the file my_file
does not exist, it is created. If the file exists, it is overwritten.ls > my_folder_contents.txt
, a text file will be created containing a list of what is in the current working directory.>
symbol we use the construction >>
, then, provided that there exists a file to which the output of the command is redirected, this file will not be overwritten. Data will be added to the end of this file.first_command | second_command
first_command | second_command
: pipeline symbol, |
, is used to send the results of one team to another team. The fact that the command in the left part of the construction described sends to stdout
gets into the command stdin
, which is located to the right of the conveyor symbol. first_command | second_command | third_command
|
, prints something to stdout
, that which it output is immediately available as stdin
second command. That is, it turns out that using the pipeline, we are dealing with parallel execution of commands. Sometimes this can lead to unexpected results. Details about this can be found here .head my_file
: reads lines from the beginning of the file and displays them on the screen. You can read not only the contents of the files, but also the fact that the commands are output to stdin
, using this command as an element of the pipeline.tail my_file
: reads lines from the end of the file. This command can also be used in the pipeline.head
and tail
commands should be familiar to you. If this is not the case, take a look at the picture above and you can easily remember them.cat
.cat
either prints the contents of the file to the screen, or it concatenates several files. It depends on how many files are transferred to this command when called.cat my_one_file.txt
: when a single file is passed to this command, it outputs it to stdout
.cat my_file1.txt my_file2.txt
: receiving several files as input, this command concatenates their contents and prints what happened in stdout
.>
operator: cat my_file1.txt my_file2.txt > my_new_file.txt
rm my_file
: deletes the file my_file
.rm -r my_folder
: deletes the my_folder
folder and all the files and folders it contains. The -r
flag indicates that the command will work in recursive mode.-f
flag.kill 012345
: stops the specified running process, giving it time to kill 012345
correctly.kill -9 012345
: forcibly terminates the specified running process. The -s SIGKILL
flag is the same as the -9
flag.grep
, ag
and ack
. Let's begin our acquaintance with these teams with grep
. This is a time-tested, reliable team, which, however, is slower than the others and not the way they are, convenient to use.grep my_regex my_file
: performs a search for my_regex
in my_file
. When a match is found, for each one of them, the entire string is returned. By default, my_regex
treated as a regular expression.grep -i my_regex my_file
: the search is case-insensitive.grep -v my_regex my_file
: returns all lines that do not contain my_regex
. The -v
flag means inversion, it resembles the NOT
operator available in many programming languages.grep -c my_regex my_file
: returns information about the number of matches with the search pattern found in the file.grep -R my_regex my_folder
: performs a recursive search in all files located in the specified folder and in the folders nested in it.ag
team. She appeared later grep
, it is faster, it is more convenient to work with it.ag my_regex my_file
: returns information about line numbers, and the lines themselves, in which matches are found with my_regex
.ag -i my_regex my_file
: search is case insensitive.ag
command automatically processes the .gitignore
file and excludes from the output what is found in the folders or files listed in this file. It is very convenient.ag my_regex my_file -- skip-vcs-ignores
: the contents of files of automatic version control systems (like .gitignore
) are not taken into account during the search.ag
command which file paths to exclude from the search, you can create an .agignore
file.ack
command. The ack
and ag
commands are very similar, one can say that they are 99% interchangeable. However, the ag
command is faster, so I just described it.tar my_source_directory
: merges files from the my_source_directory
folder into a single tarball file. Such files are conveniently used to transfer large sets of files to someone..tar
files (Tape ARchive). The fact that the word “tape” is hidden in the name of the command and in the extension of the names of the files created by it indicates how long this command has existed.tar -cf my_file.tar my_source_directory
: creates a tarball file called my_file.tar
with the contents of the folder my_source_directory
. The -c
flag stands for “create” (creation), and the -f
flag as “file” (file)..tar
file, use the tar
command with the -x
(“extract”, extract) and -f
(“file”, file) flags.tar -xf my_file.tar
: extracts files from my_file.tar
to the current working directory..tar
files.tar -cfz my_file.tar.gz my_source_directory
: here, using the -z
flag ("zip", compression algorithm), it is indicated that the gzip
algorithm (GNU zip) should be used to compress files. Compressing files saves disk space when storing such files. If the files are planned, for example, to transfer to other users, this contributes to a faster download of such files..tar.gz
file by adding the -z
flag to the command for extracting the contents of .tar
files, which we discussed above. It looks like this:tar -xfz my_file.tar.gz
tar
command has many more useful flags.bu
, behind which is the python setup.py sdist bdist_wheel
, then to call this command, it is enough to use this alias.~/.bash_profile
file: alias bu="python setup.py sdist bdist_wheel"
~/.bash_profile
file on your system, you can create it yourself using the touch
command. After creating the nickname, restart the terminal, after which you can use this nickname. In this case, the input of two characters replaces the input of more than three dozen characters of the command that is intended to build Python packages.~/.bash_profile
for any frequently used commands.Source: https://habr.com/ru/post/445270/
All Articles