command prompt
[ root@localhost ~]#
Command format
Command [Options] [Parameters]
Query the contents of the directory: ls
Ls [option] [file or directory]
[ root@localhost ~] # ls anaconda-ks.cfg test [ root@localhost ~] # ls -a . .. anaconda-ks.cfg .bash_ history .bash_ logout .bash_ profile .bashrc .cache .config .cshrc .tcshrc test [ root@localhost ~] # ls -l Total consumption 4 -rw-------. 1 root root 2752 Nov 10 02:51 anaconda-ks.cfg drwxr-xr-x. 2 root root 6 Nov 12 19:26 test [ root@localhost ~] # ls -l anaconda-ks.cfg -rw-------. 1 root root 2752 Nov 10 02:51 anaconda-ks.cfg [ root@localhost ~] # ls -ld test/ drwxr-xr-x. 2 root root 6 Nov 12 19:26 test / [ root@localhost ~] # ls -lh Total consumption 4.0K -rw-------. 1 root root 2.7K Nov 10 02:51 anaconda-ks.cfg drwxr-xr-x. 2 root root 6 Nov 12 19:26 test [ root@localhost ~] # ls -i 71259104 anaconda-ks.cfg 36099565 test
-rw------- . 1 root root two .7K Nov 10 02 :51 anaconda-ks .cfg
drwxr-xr-x . 2 root root six Nov 12 19 :26 test
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
Directory processing commands
Create directory: mkdir
Mkdir - p [directory name]
[ root@localhost ~] # ls anaconda-ks.cfg test [ root@localhost ~] # mkdir otherFolder [ root@localhost ~] # ls anaconda-ks.cfg otherFolder test [ root@localhost ~] # mkdir folder_ 2/test_ two
mkdir : Unable to create directory "folder_2/test_2" : No such file or directory [ root@localhost ~] # mkdir -p folder_ 2/test_ two [ root@localhost ~] # ls anaconda-ks.cfg folder_ 2 otherFolder test [ root@localhost ~] # ls folder_ 2/ test_ two
Switch directory: cd
Cd [directory]
-
Cd~: Enter the current user's home directory -
Cd -: Enter the last directory -
Cd..: Enter the upper level directory -
Cd: return home directory
[ root@localhost ~] # ls anaconda-ks.cfg folder_ 2 otherFolder test [ root@localhost ~] # cd /folder_ 2/test_ two [ root@localhost test_ 2] # cd [ root@localhost ~] # cd - /root/folder_ 2/test_ two [ root@localhost test_ 2] # cd ../../ otherFolder [ root@localhost otherFolder] # cd .. [ root@localhost ~] #
[ root@localhost ~] # cd folder_ 2/test_ two
[ root@localhost test_ 2] #
[ root@localhost test_ 2] # cd ../../ otherFolder
[ root@localhost otherFolder] #
Query directory location: pwd
pwd
[ root@localhost ~] # pwd /root [ root@localhost ~] # ls anaconda-ks.cfg folder_ 2 otherFolder test [ root@localhost ~] # cd folder_ 2/ [ root@localhost folder_ 2] # ls test_ two [ root@localhost folder_ 2] # cd test_ 2/ [ root@localhost test_ 2] # pwd /root/folder_ 2/test_ two
Delete empty directory: rmdir
Rmdir [directory name]
[ root@localhost ~] # ls anaconda-ks.cfg folder_ 2 otherFolder test [ root@localhost ~] # rmdir otherFolder [ root@localhost ~] # ls anaconda-ks.cfg folder_ 2 test [ root@localhost ~] # rmdir folder_ two
rmdir : Delete "folder_2" Failed: directory is not empty [ root@localhost ~] #
Delete file or directory: rm
Rm - rf [file or directory]
-
If you do not add any options, you can only delete the file. When deleting, you will be prompted to confirm the deletion -
If you only add the option - r, you can delete files or directories. When deleting, you will be prompted to confirm the deletion -
If the option - rf is added, no prompt will be given to delete files or directories
[ root@localhost ~] # ls abc.txt anaconda-ks.cfg folder_ 2 test [ root@localhost ~] # rm abc.txt Rm: whether to delete ordinary empty files "abc.txt" ? y [ root@localhost ~] # rm test Rm: cannot be deleted "test" : is a directory [ root@localhost ~] # rm -r test Rm: whether to delete the directory "test" ? y [ root@localhost ~] # ls anaconda-ks.cfg folder_ two [ root@localhost ~] # rm -rf folder_ two [ root@localhost ~] # ls anaconda-ks.cfg [ root@localhost ~] #
Copy command: cp
Cp [option] [original file or directory] [target directory]
[ root@localhost ~] # ls anaconda-ks.cfg bbc.txt folder_ a folder_ b [ root@localhost ~] # cp bbc.txt folder_ a [ root@localhost ~] # ls folder_ a/ bbc.txt [ root@localhost ~] # cp folder_ a folder_ b Cp: Skip directory "folder_a" [ root@localhost ~] # cp -r folder_ a folder_ b [ root@localhost ~] # ls folder_ b folder_ a test_ one [ root@localhost ~] # ll Total consumption four -rw-------. one root root two thousand seven hundred and fifty-two Nov ten 02 : fifty-one anaconda-ks.cfg -rw-r--r--. one root root zero Nov thirteen seventeen : twenty-one bbc.txt drwxr-xr-x. two root root twenty Nov thirteen seventeen : thirty-eight folder_ a drwxr-xr-x. four root root thirty-four Nov thirteen seventeen : thirty-nine folder_ b [ root@localhost ~] # ll folder_ a Total consumption zero -rw-r--r--. one root root zero Nov thirteen seventeen : thirty-eight bbc.txt [ root@localhost ~] # cp -a bbc.txt folder_ b [ root@localhost ~] # ll folder_ b Total consumption zero -rw-r--r--. one root root zero Nov thirteen seventeen : twenty-one bbc.txt drwxr-xr-x. two root root twenty Nov thirteen seventeen : thirty-nine folder_ a drwxr-xr-x. two root root six Nov thirteen seventeen : thirty-eight test_ one [ root@localhost ~] #
Cut or Rename Command: mv
Mv [original file or directory] [target directory]
-
If the original file or directory is in the same directory as the target directory, it is renamed -
If they are not in the same directory, they are cut
[ root@localhost ~] # ls anaconda-ks.cfg bbc.txt [ root@localhost ~] # mv bbc.txt abc.txt [ root@localhost ~] # ls abc.txt anaconda-ks.cfg [ root@localhost ~] # mkdir test [ root@localhost ~] # ls abc.txt anaconda-ks.cfg test [ root@localhost ~] # mv abc.txt test/ [ root@localhost ~] # ls anaconda-ks.cfg test [ root@localhost ~] # ls test/ abc.txt [ root@localhost ~] #
Link command: ln
Ln - s [original file] [target file]
-
Having the same i node and storage block block can be regarded as the same file -
It can be identified by node i, which is the same -
Cannot span partitions -
Cannot be used for directory
-
Windows like shortcuts -
The soft link has its own i node and block block, but the data block only stores the file name and I node number of the original file, and has no actual file data lrwxrwxrwx L is a soft link (the permissions of soft links are rwxrwxrwx, which is only the permissions of soft links themselves) -
Modify any file and change the other -
Delete the original file, and the soft link cannot be used (the same as the shortcut of Windows)
[ root@localhost ~] # ls anaconda-ks.cfg [ root@localhost ~] # mkdir folder [ root@localhost ~] # ls anaconda-ks.cfg folder [ root@localhost ~] # touch bbb.txt [ root@localhost ~] # ls anaconda-ks.cfg bbb.txt folder [ root@localhost ~] # ln bbb.txt folder/ccc.txt [ root@localhost ~] # ll folder/ Total consumption zero -rw-r--r--. two root root zero Nov thirteen eighteen : 08 ccc.txt [ root@localhost ~] # ll bbb.txt -rw-r--r--. two root root zero Nov thirteen eighteen : 08 bbb.txt
[ root@localhost ~] # mkdir folder_ b [ root@localhost ~] # ln -s bbb.txt folder_ b/eee.txt [ root@localhost ~] # ll Total consumption four -rw-------. one root root two thousand seven hundred and fifty-two Nov ten 02 : fifty-one anaconda-ks.cfg -rw-r--r--. two root root zero Nov thirteen eighteen : ten bbb.txt drwxr-xr-x. two root root twenty Nov thirteen eighteen : 09 folder drwxr-xr-x. two root root twenty Nov thirteen eighteen : eleven folder_ b [ root@localhost ~] # ll folder_ b Total consumption zero lrwxrwxrwx. one root root seven Nov thirteen eighteen : eleven eee.txt -> bbb.txt [ root@localhost ~] # rm -rf bbb.txt [ root@localhost ~] # ll folder_ b Total consumption zero lrwxrwxrwx. one root root seven Nov thirteen eighteen : eleven eee.txt -> bbb.txt
Common directory function
[ root@localhost ~] # ls / bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys temp tmp usr var
/Root directory /Bin command save directory (common user permissions) /The sbin command saves the directory (root permission) /Boot startup directory, including startup related files, related to startup /Dev Device File Save Directory /ETC configuration file saving directory /Home ordinary user home directory /Save directory of lib system library /Mnt system mount directory /Media mount directory (usually used for CD mount) /Root superuser home directory /Tmp temporary directory /Proc writes directly to memory /Sys directly writes to memory /Usr system software resource directory /Related documents of var system