Files And Directories |
|
Command |
Option |
Annotation |
Example |
Basic File Operations |
Ls |
[Option] [file] |
Show all files and directories |
Ls-al |
-A () |
Show all files and directories, including hidden files and directories (show all files and directories, including hidden files and directories, but not realistic "." and "." Directories) |
View Details of all files in the current directory = ll |
-L |
Displays complete attribute information for files and directories. |
-D |
|
|
Cd |
+ Path |
Change current path |
Cd/etc to the etc directory |
Pwd |
|
Show current path |
Pwd displays the current path |
Mkdir |
+ Directory name |
Create directory |
Mkdir abc create abc directory |
-P |
Create a parent directory when the parent directory does not exist |
Rmdir |
+ Directory name |
Delete A directory. Only empty directories can be deleted. |
Rmdir abc Delete abc directory |
Cp |
[Option] Source Target |
Copy a file |
Cp-r test/usr/copy all contents in the test directory under the current directory, including subdirectories, to the usr directory |
-R |
Replicate directories cyclically |
-F |
|
Mv |
Source Target |
|
Mv test/usr/move the test directory under the current directory to the usr directory |
Rm |
[Option] File Name |
Delete |
Rm-rf test forcibly deletes the test directory and all files and subdirectories in the current directory. |
-R |
Cyclic deletion is often used to delete directories, indicating that all files in directories and directories are deleted. |
-F |
Force Delete not prompted |
View File Content |
Cat |
[Option] File Name |
View File Content |
Cat-nb/etc/inittab displays the content of the inittab file under the etc directory, displaying the row number but not empty lines |
-N |
Display row numbers together |
-B |
Line numbers are displayed together, but empty rows are not displayed. |
More |
+ File name |
Same as cat. If the file contains more than 40 lines, it will be displayed on a split screen. Press enter to move down a single line or press ctrl + f to flip the page and press q to exit browsing. |
Same as cat |
Head (tail) |
[Option] File Name |
Display 10 rows before (after) the file |
Head-5/test |
-N |
Number of rows displayed |
Display the first five lines of the test file in the current directory |
Cut |
Option [file] |
Select a part of each row in the file. |
Cut-d ":"-f 2 c.txt |
-D |
Use (...) for segmentation |
To: split each c.txtline and display the second column of each line in the c.txt document |
-F |
Column number |
|
Link file |
Ln |
[Option] Source Target |
Sets the link file. If the parameter is null, a hard link is created by default. |
Ln (-d) ct. sh dlink |
-S |
Create a symbolic link |
Create a dlink hard link in the current directory to point to ct. sh |
-D |
Create a hard link |
Search for text and directories |
Find |
[Path] [Option] File Name |
You can specify a directory and all subdirectories for search, because the hard disk search speed is slow. |
Find.-name "*. txt"-atime 1 |
-Name file |
Search for a file named name file with wildcards * |
Find the TXT file in the current directory. |
Locate |
+ File name |
Searching from an existing database is extremely fast, but the database content needs to be updated in real time. You can use the updatedb command to manually update the database. |
Use the same as find |
Which |
+ File name |
Find the location of the executable file and find it through the path under the Environment Variable path |
Which ls |
Whereis |
[Option] File Name |
Search Based on the Set directory. Instead of the directory under path, you can customize the directory. |
Whereis ls |
-B |
Search for binary files only |
|
-M |
Only find the instruction file |
|
Grep |
Option pattern (included string) file name |
Indicates to find a row containing the specified content in a text file. |
Grep-n 456 B .txt |
-N |
Show row number |
Displays B .txt with 456 rows and displays row numbers |
-I |
String is case insensitive |
Grep-v 456 B .txt |
-V |
Reverse query: searches for lines that do not contain the specified content in a text file. |
Display B .txt rows that do not contain 456 |
File and directory permissions |
Chown |
[Option] user: group directory or file name |
Change the owner and group of files or directories |
Chown-R lucy: root lamp |
-R |
All files under the directory are changed. |
Change the owner of the lamp directory and all its files and sub-directory files in the current directory to lucy, and change the group to root. |
Chmod |
[Option] [parameter] directory or file name |
Change the read and write permissions of files or directories |
1. chmod 760 ct. sh: Change the permission of the ct. sh file in the current directory to rwxrw ---- |
-R |
All files under the directory are changed. |
2. chmod ug = rwx, o = r ct. sh change the permission of the ct. sh file in the current directory to rwxrwxr -- |
3. chmod g-r, o + w ct. sh remove the read permission of the group to which the ct. sh file in the current directory belongs, and grant the write permission to others. |