# #mkdir Command The mkdir command is used to create a directory of the specified name, requiring the user who created the directory to have write permissions in the current directory, and the specified directory name cannot be a directory that is already in the current directory. The mkdir command is the abbreviation for Make directory.
# # #命令格式:
mkdir [Options] Directory
# # #常用参数:
Parameters |
Description |
-M--mode= mode |
Set Permissions < modes > |
-P--parents |
Can be a path name. If some directories in the path do not already exist, and with this option, the system will automatically set up those directories that do not yet exist, that is, multiple directories can be established at one time |
-V--verbose |
Displays information each time a new catalog is created |
# # #常用范例: Example one: to create multiple directories recursively, you can use the following command:
mkdir -p zhou/test
Example Two: create a directory with permissions of 777, you can use the following command:
mkdir -m 777 zhou
Example Three: Create a directory display information, you can use the following command:
mkdir -vp zhou/test
# # #思考题 Try the following commands to see what magical things happen to the tree needs to be installed separately
sudo apt-get updatesudo apt-get install tree
mkdir -vp shiyanlou/{lib/,bin/,doc/{info,product}}tree shiyanlou/
# #rm Command RM is a commonly used command that removes one or more files or directories from a directory, and it can delete all files and subdirectories under a directory. For linked files, only the links are deleted and the original files remain unchanged.
RM is a dangerous command, especially when used, especially for novices, or the entire system will be destroyed in this command (e.g., RM *-rf under/(root directory)). So, before we execute RM, it's a good idea to check in which directory, exactly what to delete, and keep a high level of sanity in the operation.
The RM command is the abbreviation for remove.
# # #命令格式:
RM [Options] File or directory
# # #常用参数:
Parameters |
Description |
-F--force |
Ignore non-existent files, never give hints |
-I.--interactive |
For interactive deletion |
-R--recursive |
Instructs RM to recursively delete all directories and subdirectories listed in the parameter |
-V--verbose |
Detailed display of the steps performed |
# # #常用范例: Example: Delete a file, the system will first ask whether to delete, you can use the following command:
rm shiyanlou.log
Example two: forcibly delete the file, the system no longer prompt, you can use the following command:
rm -f shiyanlou.log
Example three: delete all of the suffix named. Log, delete the previous query, you can use the following command:
rm *.log 或 rm -i *.log
# #思考题 1. Consider what the following command does.
myrm(){ D=/tmp/$(date +%Y%m%d%H%M%S); mkdir -p $D; mv "[email protected]" $D && echo "moved to $D ok"; }
# #mv Command The MV command function is used to move files or change file names, is a common command under the Linux system, often used to back up files or directories. The MV command determines whether to rename the file or move it to a new directory, depending on the second parameter type, which is the target file or the destination directory. When the second parameter type is a file, the MV command completes the file rename, at which point the source file can only have one (or the source directory name), which renames the given source file or directory to the specified destination file name. When the second parameter is a directory name that already exists, the source file or directory parameter can have more than one, and the MV command moves the source files specified by each parameter to the destination directory. The MV command is the abbreviation for move.
# # #命令格式:
MV [option] source file or directory destination file or directory
# # #常用参数:
Parameters |
Description |
-B--back |
Overwrite pre-backup if file overwrite is required |
-F--force |
If the destination file already exists, it will not be queried and overwritten directly |
-I.--interactive |
If the target file already exists, you will be asked if you want to overwrite |
-U--update |
Update if the destination file already exists and the source file is newer |
-T--target |
This option is useful when moving multiple source files to a directory, where the destination directory is before the source file |
# # #常用范例: Example one: rename the file Shiyanlou.log to Zhou.log, you can use the following command:
mv shiyanlou.log zhou.log
Example Two: move the file Zhou.log to the test directory (the test directory must already exist, or perform a rename), you can use the following command:
mv zhou.log test
Example Three: the file a.txt moved to the Test1 directory, if the file exists, before overwriting will ask whether to overwrite, you can use the following command:
mv -i a.txt test1
# #cp Command The CP command is used to copy files or directories and is one of the most commonly used commands in a Linux system. In general, the shell sets an alias, and when the file is copied at the command line, if the destination file already exists, it asks whether to overwrite it, regardless of whether you use the-i parameter. However, if you execute the CP in a shell script, you do not ask for overrides if you do not have the-i parameter. This means that the command line and shell scripts perform somewhat differently. The CP command is the abbreviation for copy. command format:
CP [Options] source file directory CP [option]-T directory source files Common parameters:
Parameters |
Description |
-T--target-directory |
Specify Destination Directory |
-I.--interactive |
Ask before overwriting (invalidates the previous-n option) |
-N--no-clobber |
Do not overwrite existing files (invalidate the previous-i option) |
-S--symbolic-link |
Create a symbolic link to a source file, not a copy of a file |
-F--force |
Forcibly copying a file or directory, regardless of whether the destination file or directory already exists |
-U--update |
After using this parameter, the file will only be copied if the source file is modified at a later time than the destination file, or if the corresponding destination file does not exist. |
Common examples: Example one: to create a symbolic link to a file Shiyanlou.log Zhou.log, you can use the following command:
cp -s shiyanlou.log zhou.log
Example Two: copy all the files under the Test1 directory to the Test2 directory, ask before overwriting, you can use the following command:
cp -i test1/* test2
example Three: copy the most recently updated file under the Test1 directory to the Test2 directory, ask before overwriting, you can use the following command:
cp -iu test1/* test2
# #cat The function of the command Cat command is to output a file or standard input combination to the standard output. This command is commonly used to display the contents of a file, or to connect several files to display, or to read from a standard input and display it, often in conjunction with redirection symbols. The cat command is an abbreviation for concatenate.
# # #命令格式:
Cat [Options] [file]
# # #常用参数:
Parameters |
Description |
-A--show-all |
Equivalent to-vet |
-B--number-nonblank |
Number of non-null output lines |
-E |
Equivalent to-ve |
-E--show-ends |
Show $ at end of each line |
-N--number |
Numbering all the lines of the output, numbering the number of rows for all outputs starting from 1 |
-S--squeeze-blank |
Blank line with more than two lines in a row |
-T |
Equivalent to-VT |
-T--show-tabs |
Display the ^i character as a |
-U |
(ignored) |
-V--show-nonprinting |
Use ^ and M-references, except LFD and TAB |
# # #常用范例: Example One: Add the Shiyanlou.log file content and enter Zhou.log This file, you can use the following command:
cat -n shiyanlou.log > zhou.log
Example Two: add shiyanlou.log file contents and line number after input zhou.log this file, multiple lines of empty lines for a row of output, you can use the following command:
cat -ns shiyanlou.log > zhou.log
Example Three: the Zhou.log file content is displayed in reverse, you can use the following command:
tac zhou.log
Description: The TAC is writing cat back, so it functions in contrast to cat, where cat is continuously displayed on the screen from the first line to the last row, while the TAC is displayed on the screen in reverse from the last line to the first line.
# # #思考题 1. Perform what the following command will output.
# #nl Command NL command to calculate the line number of a file in a Linux system. NL can automatically add a line number to the output file content. The default result is a bit different from Cat-n, NL can make the line number more display design, including the number of digits and whether auto-completion 0 and so on.
The NL command is the abbreviation for number of lines.
# # #命令格式:
NL [Options] [file]
# # #常用参数: Parameters | Description:---------------|:----------------B | There are two main ways to specify the line number:-B A | Indicates that the line number is also listed (similar to cat-n), whether or not it is a blank line | If there is a blank line, do not list the line number (default)-n | There are three main ways to represent a travel number:-N LN | Line number on the left of the screen display-n RN | The line number is displayed on the very right of its own field, and no 0-n RZ | line number is displayed on the right side of its field, plus 0-w | The number of digits occupied by the line number field
# # #常用范例: Example: The Shiyanlou.log file content with the line number after the display, empty line No line number, you can use the following command:
nl -b t shiyanlou.log
Example two: The Shiyanlou.log file content with the line number is displayed, the line number in the screen at the left and the right of the top 0 and right plus 0 display, you can use the following command:
nl -n ln shiyanlou.lognl -n rn shiyanlou.lognl -n rz shiyanlou.log
Example Three: the Shiyanlou.log file content plus line number display, line number on the screen at the right plus 0 display, line number column occupies 3, you can use the following command:
nl -n rz -w 3 shiyanlou.log
# # #思考题
Linux operational Commands (ii)