Commonly used directory operation commands
Function classification |
command |
Create and delete directories |
mkdir,rmdir |
Display, change the current directory |
pwd,cd |
Show directory contents |
ls |
Note:
pwd (present working directory) ,cd (change directory)
pwd command
Function : Display the absolute path of the current directory
Format: pwd
cd command
Function : change the current directory to the specified directory
Format: pwd [directory]
Note: When the directory parameter is not specified, enter the user's home directory
ls (list) command
Function : Display the information of the specified file or all files in the specified directory
Format: ls [option] [file or directory]...
[Options]:
-a Display all files and directories, including hidden files "." ".." directory
-R Recursively display lower subdirectories.
-F display file type descriptor (* is an executable ordinary file, / is a directory file)
-d displays the information of the directory instead of its content
-u displays the last access time of the file, used in conjunction with -l
-c displays the last change time of the file, used in conjunction with -l
-t Sort and display by file modification time
-l Display file details in long format
Note: 1) When no directory or file is specified, the file list information in the current working directory will be displayed
2) Without options, output the file names of all non-implicit files in the directory in alphabetical order
3) When the long format is displayed, the format is as follows:
File type and permissions Number of connections Owner name Owner group name File size Last modified time File name
Create and delete directories
mkdir(make directory)
Function: Create directory
Format: mkdir [options] directory...
[Options]
-m permission to create a directory according to the specified permissions
-p creates a directory recursively, that is, when the parent directory of the directory does not exist, the parent directory is also created
[Explanation] When the directory permission is not specified, the default permission is 777-create mask
rmdir command
Function: delete directory
Format: rmdir [options] directory...
[Options]
-p deletes a directory recursively, that is, when the parent directory is empty after the directory is deleted, the parent directory is also deleted
Note: If the directory is not empty, it cannot be deleted, and it is not allowed to delete non-empty directories under Linux
Commonly used file operation commands
Function classification |
command |
File display |
cat,more,less |
File copy, delete and move |
cp 、 rm 、 mv |
Statistics and sorting of file content |
wc、sort |
Change file access permissions |
chmod |
Change the time stamp of a file |
touch |
Set file mask |
umask |
File search, search |
find、grep |
File display
cat command
-A displays all characters, including line breaks, tabs and other non-printing characters
-n number all lines of output and display the line number
-b is similar to -n, but does not number blank lines
-s compress consecutive blank lines into one blank line
Note: When multiple files are specified, each file will be displayed in turn. When no file is specified, standard input will be read (the default is the keyboard)
And display, Ctrl+d ends the input, this command is suitable for short files
more command
Function: split screen display file content
Format: more [option] [file]...
[Options]
-p does not scroll, clear the screen
-s compress consecutive blank lines into one blank line
+n start to display from the nth line
+/str Start displaying from the place containing the string of str
Note: When browsing to the last page, it will exit automatically. When the file parameter is not specified, the standard input will be read by default
During the browsing process, --more--(x%) will be displayed in the lower left corner of the screen, hence the name of the command
Buttons available when browsing:
Enter scroll down one line
↑ ↓ Up and down
/string Find the string string
n Find the next string
q Exit
Space page down
b Page up
less command
less is a substitute for more, the name is derived from the English phrase more or less
The format and usage of the command are the same as more, but the user can completely
Control the browsing process to the last page and will not automatically exit
The man command uses the less command to control the browsing of man pages
Copy, move and delete files
cp(copy) command
Function: Copy files
Format: cp [options] source file target file
cp [options] source file... target directory
[Options]
-i interactive mode, when the target file exists, prompt whether to overwrite input y or Y overwrite, input other characters do not overwrite
-r copy directories recursively
-b Create a backup for the overwritten file. The name of the backup file is the original file name plus "~"
-f Force copy. That is, if the target file exists and cannot be opened, delete it first, and then copy it
-p keep the original attributes of the file
-v display operation result
rm command
Function: delete files
Format: rm[option] file...
[Options]
-f Ignore non-existent files without prompting
-i prompt the user to confirm before deleting
-r delete directories recursively
-v display operation result
Note: If the parameter is a directory, the -r option is required, because Linux cannot directly delete non-empty directories, and an error will be reported
The files deleted by rm are permanently deleted and cannot be restored to avoid deletion errors. You can use echo to verify
Expand parameters
mv command
Function: move files, rename files
Format: mv [option] source file target file
mv [options] source file... target file
[Options]
-i prompts the user to confirm before overwriting
-f does not prompt the user to confirm, directly overwrite
-b Create a backup for the overwritten file, the name of the backup file is the original file name followed by "~"
-v display operation result
Note: The mv command to move the directory does not need to use the -r recursive command
Statistics and sorting of file content
wc command
-c counts only the number of bytes
-l only count the number of rows
-m only count the number of characters
-w only count words
Note: When the option is not specified, the number of lines, words and characters will be displayed.
When the file is not specified, read the standard input file
sort command
Function: Sort the lines of the text file from small to large in ASCII character order
And output the sorted results.
Format: sort [option][file]...
Options:
-b ignore the initial blank
-d only consider letters, numbers and spaces
-f ignore case
-kn specifies the content starting from the nth field as the sort key
-r reverse sort
Note: Without parameters, the sort command reads the input from the standard input device until
Press Ctrl + d keys, and then output the sorted content
Change file attributes
chmod(change mode)
Function: modify file access permissions
Format: chmod[option][digital permission mode] file...
chmod[options][character permission mode expression]... file...
[Options]
-R recursively change the permission attributes of the specified directory and its files and subdirectories
Note:
1) The format of the character permission mode expression is <Permission Range><Operation><Permission Character>
Scope of authority: ugoa
Operation: + - =
Permission characters: r w x
2) Use',' to separate multiple expressions, and there can be no spaces. Such as: u=rw,gr
3) Only the owner and root of the file have the authority to modify the file
go = no permission character means that the corresponding permission range has no permission
touch command
Function: modify the time label of the file to the current time
Format: touch[option] file...
[Options]
-a only modify the access time of the file
-m only changes the modification time of the file
-c do not create a file if the file does not exist
Set file mask
umask instruction
Function: set, display the permission mask of the newly created file
Format: umask[options][mask]
[Options]
-S displays the permissions corresponding to the mask in character form