Linux basic commands--related operations of the directory
Common commands for working with directories:
- CD: Transform Catalog
- PWD: Displays the current directory
- mkdir: Create a new directory
- RmDir: Delete an empty directory
CD (Transform directory)
The CD is the abbreviation for Change directory, which is the command used to transform the working directory. Note that there is a space between the directory name and the CD command.
[[Email protected] ~]#CD [Relative path or absolute path]#The most important is the absolute path of the directory and relative path, there are some special directory of symbols ROM! [[Email protected] ~]#CD ~vbird#The representative went to Vbird, the user's home directory, i.e./home/vbird[[email protected] vbird]#CD ~#go back to your home directory, which is the/root directory .[[Email protected] ~]#CD#does not add any path, but also represents the return to their home directory of the meaning Oh! [[Email protected] ~]#CD..#meaning to go to the current top-level directory, that is, the/root of the top-level directory;[[email protected]/]#CD-#to return to the first directory, that is,/root Luo[[Email protected] ~]#Cd/var/spool/mail#This is the way the absolute path is written! Specify the full path name to go directly! [[email protected] mail]#CD.. /mqueue#This is the relative path of the wording, we go from/var/spool/mail to/var/spool/mqueue to write!
PWD (Displays the directory that is currently located)
PWD is the abbreviation for print working directory, which is the command that displays the current directory, such as the directory at the end of the last table is/var/mail, but the prompt byte only shows mail, if you want to know the current directory, you can enter the PWD. In addition, because many of the packages use the same directory name, such as/USR/LOCAL/ETC and/etc, but usually Linux lists only the last directory, this time you can use PWD to know your directory ROM! Lest the catalogue be mistaken, the result ...
[[Email protected] ~]#pwd [-p]options and Parameters:-P: Shows the exact path, not the link path. Example: simply display the current working directory: [Root@www ~]#pwd/root <==Show Directory ~ Example: shows the actual working directory, not the directory name of the link file itself [root@www ~]#Cd/var/mail <== Note that/var/mail is a link file[[email protected] mail]#pwd/var/mail <==list the current working directory [root@www Mail]#pwd-p/var/spool/mail <== What's going on? Is there a plus-P difference a lot ~[root@www Mail]#Ls-ld/var/maillrwxrwxrwx 1 root root Sep 4 17:54/var/mail-spool/Mail#You know what you're supposed to see here? Because/var/mail is a link file, linked to/var/spool/mail#so, with the PWD-P option, it will show the correct full path instead of displaying the data in the link file.
In fact, the interesting is that the-p option! He can let us get the correct directory name instead of displaying it as a path to the link file.
mkdir (Create new directory)
If you want to create a new directory, then use mkdir (Make directory)!
[[Email protected] ~]#mkdir [-mp] Directory nameoptions and Parameters:-m: Permission to configure files Oh! Direct configuration, do not need to see the default permissions (umask) face ~-P: help you to directly create the desired directory (including the top level directory)! Example: please go to/under TMP Try to create a few new directories to see: [Root@www ~]#cd/tmp[[email protected] tmp]#mkdir Test <== Create a new directory for test[[email protected] tmp]#mkdir test1/test2/test3/test4Mkdir:cannot Create directory ' test1/test2/test3/test4 ': No such file or directory <==There is no way to create this directory directly! [Root@www TMP]#mkdir-p Test1/test2/test3/test4#Add this-p option to help you create multi-level catalogs yourself! Example: Create a permission of rwx--x--directory of x [root@www TMP]#mkdir-m 711 Test2[[email protected] tmp]#ls-lDrwxr-xr-x 3 root root 4096 Jul 18 12:50TESTDRWXR-xr-x 3 root root 4096 Jul 18 12:53test1drwx--x--x 2 root root 4096 Jul 18 12:54test2#take a closer look at the permissions section above, and if you do not add-m to force the configuration property, the system uses the default property. #So what's your default property? This will be through the umask of the below to understand Oh! ^_^
In the default case, you need a layer of the directory to create a level! For example: If you want to create a directory for/home/bird/testing/test1, then you must first have/home and then/home/bird, and then/home/bird/testing must exist before you can create/home/bird/ Testing/test1 This directory! If there is no/home/bird/testing, there is no way to create test1 directory Luo!
But now there's a simpler and more effective way! That's the option of adding-P! You can directly release: "Mkdir-p/home/bird/testing/test1" then the system will automatically help you to home/home,/home/bird,/home/bird/testing sequentially create a directory! Also, if the directory already exists, the system will not display an error message! It's very happy! ^_^. But brother Bird does not recommend the usual-p option, because worry if you typo, then the directory name will become a mess!
In addition, there is a place where you have to first have a concept, which is the "Default permissions" place. We can use-m to force a new directory-related permission, such as in the table above, we give M 711来 permission to give the new directory drwx--x--x. However, if the-M option is not given, then what is the default new directory permission? This is related to umask and will be introduced in the following.
RmDir (delete "Empty" directory)
If you want to delete the old directory, use RmDir!
[[Email protected] ~]#rmdir [-p] Directory nameoptions and Parameters:-P: Along with the previous level of "empty" directories also delete the example: The directory that will be created in the mkdir paradigm (/tmp below) Remove! [Root@www TMP]#Ls-l <== See how many directories exist? Drwxr-xr-x 3 root root 4096 Jul 18 12:50TESTDRWXR-xr-x 3 root root 4096 Jul 18 12:53test1drwx--x--x 2 root root 4096 Jul 18 12:54Test2[root@www TMP]#rmdir test <== can be removed directly, no problem[[email protected] tmp]#rmdir test1 <== because there is still content, so cannot delete! rmdir: ' test1 ': Directory not empty[root@www TMP]#rmdir-p Test1/test2/test3/test4[[email protected] tmp]#ls-l <== You see, the bottom of the output of test and test1 disappeared! Drwx--x--x 2 root root 4096 Jul 18 12:54test2#look at that! With the-P option, you can delete the Test1/test2/test3/test4 once at once ~#However, it is important to note that this rmdir can only "delete empty directories" Oh!
For example, to kill the test you just created, use "RmDir test"! Please pay attention to Yo! Directories require a layer of deletion! And there must be no other directories or files in the deleted directory! This is also the so-called Empty directory of directories (empty directory) meaning Ah! What if we're going to kill everything in the catalog?! This time you must use the "Rm-r test" ROM! However, it is not dangerous to use rmdir! You can also try to use the-P option to delete the top level directory.
CentOS Learning Notes-BASIC commands-related operations for directories