[Linux] Common Commands (2)

content

1.man command (important)

2.cp instruction (important)

3.mv command (important)

4. cat instruction

5.more command

6.less directive (important)


1.man command (important)

Linux commands have many parameters, we can't remember all of them, we can get help by checking the online manual. The command to access the Linux man page is man

Syntax: man [options] command

Common options:

  • -k Search online help by keyword
  • num is only found in chapter num
  • -a displays all chapters, such as man printf, it starts searching from the first chapter by default, and stops when you know it. With the a option, when you press q to exit, he will continue to search later until all chapters are searched. .

To explain, the man manual is divided into 8 chapters
1) Executable programs or shell commands.
2) System calls (functions provided by the kernel).
3) Library functions (functions in a program library).
4) Special files (usually found in /dev).
5) File formats and conventions, such as /etc/passwd.
6) Games.
7) Miscellaneous.
8) System administration commands (usually restricted to root users).


2.cp instruction (important)

In Windows, we can copy a file or directory from one place to another through Ctrl+C and Ctrl+V. If we want to complete this operation in Linux, we need to use the cp command.

Syntax: cp [options] source file or directory target file or directory
function: copy files or directories existing directory, it will copy all previously specified files or directories to this directory. If multiple files or directories are specified at the same time, and the final destination is not an existing directory, an error message will appear.

 

 

Common options:

1) -f or --force force a file or directory to be copied, regardless of whether the destination file or directory already exists


2) -i or --interactive ask the user before overwriting the file


3) -r or -R recursively process, process the files and subdirectories in the specified directory together. If the form of the source file or directory does not belong to the directory or symbolic link, it will be treated as a normal file

 Tip:  When you need to copy all the contents of the current directory, you can use wildcards to copy.

 


3.mv command (important)

The mv command is the abbreviation of move, which can be used to move files or rename files (move (rename) files). It is a commonly used command in Linux systems and is often used to back up files or directories.


Syntax: mv [options] source file or directory target file or directory

 Function:
1. ) Depending on the type of the second parameter in the mv command (target file or target directory), the mv command renames the file or moves it to a new directory.

2.) When the second parameter type is a file, the mv command completes the file renaming. At this time, there can only be one source file (or the source directory name), and it renames the given source file or directory to The given target filename.


3. ) When the second parameter is the name of an existing directory, there can be multiple source file or directory parameters , and the mv command moves the source files specified by each parameter to the target directory.

 Common options:

1.) -f: force means to force, if the target file already exists, it will not be asked but will be overwritten directly


2.) -i : If the destination file (destination) already exists, it will ask whether to overwrite!

 

 


4. cat instruction

In Linux, it is impossible to open a file with the mouse to read it like Windows. To read the file, you can use the cat command.

Syntax: cat [options] [file]
Function: View the contents of the target file

 Common options:

        1.)-b number non-empty output lines
        2.)-n number all lines of output
        3.)-s do not output multiple empty lines

Note:  The cat command will print the entire contents of the target file to the screen. If the content of the target file is too large, it will cause the screen to be refreshed (until all the content of the file is printed on the screen). Therefore, the cat command is generally only suitable for viewing files with less content.


5.more command

If you want to view a large amount of information files, you can use the more command.

Syntax: more [option][file]
Function: more command, similar to cat

 

 Note:  The more command can only be scrolled down by pressing the Enter key, and cannot be scrolled up, and the more command will load the entire file before viewing it.


6.less directive (important)

        The less tool is also a tool for paging display of files or other output. It should be said that it is an orthodox tool for viewing file contents in Linux, with extremely powerful functions.
        The usage of less is more flexible than more. In more mode, we can't scroll forward, we can only scroll back, but if less is used, we can use the functions of [pageup][pagedown] and other buttons to scroll back and forth, which is easier to view The contents of a file!
        In addition, you can have more search functions in less, not only can you search down, you can also search up.

Syntax:  less option File
function:  Both the function of viewing the content of the target file and the function of searching.

 

 

Note:  The less command can scroll up and down by pressing the up and down keys, and the less command will not load the entire file before viewing.

Common options:
1) -i ignore case when searching.
2) -N displays the line number of each line.
3) /string Function to search down "string".
4) The function of ?string to search "string" upwards.
5) n Repeats the previous search (related to/or ?).
6) N Repeats the previous search in reverse (related to/or ?).

Guess you like

Origin blog.csdn.net/m0_51866180/article/details/123050452