CentOS from the heart of the study of six notes: directory operations command cd, pwd, mkdir, rmdir


First, the absolute path and relative path

Absolute path: from the root directory (/) began to write the name of the file or directory name, for example /home/fromheart/.bashrc;

Relative path: the path relative to the current wording of the file name. E.g. ./home/formheart ../../home/fromheart/ or the like, anyway not start / writing belong relative path.


Second, the special directory

The representative of this layer directory

.. on behalf of parent directory

- on behalf of a former working directory

~ Master file on behalf of "current user status" where the folder

~ Account on behalf of the user account's home folder (account is an account name)



Under Linux, the existence of the parent directory (..) in the root directory?

If you use "ls -al /" to the query, you can see the root directory does exist. .. with two directories, directory attributes and permissions both exactly the same, which represents the root directory on a layer of (..) and the root directory of your (.) is the same directory.


Note: For file location is not "regular" executables (/ bin, / usr / bin as the regular), when the user wants to perform these procedures, you need to strictly specify the executable file, such as the need to run the current user's home directory install.sh, execute the command input, you need to enter ./install.sh


Second, the directory operations command

pwd: displays the current directory

cd: Transform directory

mkdir: create a new directory

rmdir: delete an empty directory


1.pwd (Print Working Directory, the directory display current location)

Format pwd [-P]

Options and parameters:

-P: show the exact path, instead of using the link (link) path.

pwd

cd / bin

pwd

pwd -P

snap043.jpg


2, cd (change directory, directory conversion)

cd .

cd ..

cd ~

cd -

cd ~ from hearts


snap044.jpg


3, mkdir (make directory to create a new directory)

Format: mkdir [-mp] directory name

Options and parameters:

-m: permission settings file Oh! Directory permissions set directly created without using the default permissions (umask).

-p: help users directly to the desired directory (the top directory contains) recursively create it.


mkdir 1 2

mkdir 3/4

(Command does not need behalf -p parameter)

mkdir -p 3/4

ls -alr 3

-to ls

Note: When the directory name contains spaces, you need to use quotes "" to the directory name references

mkdir "Program Files". If the direct input mkdir Program Files, the system will directly create two directories Program and Files.

snap046.jpg


umask command: display or set the default permissions

umask

The results show the default permissions for the 0002, users can use the 777 "minus" 002 after three, the result is 775, even if permission is rwxrwxr_x. This is the default permissions to create the directory (file). The user can set permissions to create a directory by mkdir -m

mkdir -m 711 5

-to ls

snap047.jpg


4, rmdir (delete "empty" directory)

Format: rmdir [-p] directory name

Options and parameters:

-p: together with the "upper", "empty" directory is also deleted together


rmdir 1 2 (simultaneously delete empty directories 12)

rmdir 3 (3 there because the directory directory 4, is not empty, so delete failed)

rmdir -p 3/4 (4 delete the directory, but it's also deleted the last directory 3 together)


When the directory is not empty, the user can use the rm -r command to delete the directory along with the directory of files and subdirectories

rm -r 3

snap048.jpg


Guess you like

Origin blog.51cto.com/ycrsjxy/2467638