Linux cd command: Change directory

cd command, is an abbreviation for Change Directory, to change the working directory.

 

According to the source Linux command mode can be divided into two, namely Shell built-in commands and external commands. The so-called Shell built-in command, it is Shell's own commands that are not executed documents; and external command by the programmer is developed individually, is a command, it will execute the command file. The vast majority of Linux command is an external command, and the command cd is a typical Shell built-in command, so the cd command is not executed path to the file.

Cd command basic format is as follows:

[Root @ localhost ~] # cd [a relative or absolute path]

In addition, CD commands may be followed by a number of special symbols, a fixed meaning expression, as shown in Table 1:

Table 1 cd command special symbol
Special symbols For work
~ Representing the current logged-in user's home directory
~ Username It represents a change to the specified user's home directory
Last representatives directory
. It represents the current directory
.. On behalf of parent directory

Their usage are:

  1. [root @ localhost vbird] # cd ~
    # represents the return to their home directory for the root user, its home directory is / root
    [root @ localhost ~] # cd
    # did not add any path, also represents the return to the current logged-on user home directory
    [root @ localhost ~] # cd ~ vbird
    Representative # switch to the user's home directory vbird, i.e. / home / vbird

  2. [the root @ localhost ~] # CD ..
    # represents a switching to the current directory, i.e., is / root directory on a meaning;

    Note that, in the Linux system, the root directory does exist. (The current directory) and .. (parent directory of the current directory) two directories, but because the root directory is the top directory, so the root .. and. the attributes and permissions exactly the same, that is, the root directory is the parent directory itself.

  3. [root @ localhost /] # cd -
    # represents just go back to that of the directory

If you look closely, not difficult to find, in fact, [root @ localhost ~] in, it has been pointed out the current directory, the time is usually just the landing would be in its own home directory, but - it represents the home directory and, therefore, by using there  cd ~ can go back to their home directory.

[Example 1] learning cd - usage.

[root @ localhost ~] # cd / usr / local / src
# into the / usr / local / src directory
[root @ localhost src] # cd -
/ root
[root @ localhost ~] #
# "cd -" command to go back into the home directory before the src directory
[root @ localhost ~] # cd -
/ usr / local / src
[root @ localhost src] #
# then execute it again "cd -" command, back to the / usr / local / src directory

[Example 2] learning cd. Cd .. and usage.

[root @ localhost ~] # cd / usr / local / src
# into the test directory
[root @ localhost src] # cd ..
# into the parent directory
[root @ localhost local] # pwd
/ usr / local
#pwd is to look at the current command directory, you can see we enter the parent directory / usr / local
[root @ localhost local] # cd.
# into the current directory
[root @ localhost local] # pwd
/ usr / local
# this command does not have a directory change, just to tell you. "" represents the current directory

pwd command displays the current directory, and the specific use in the next section will give you details.

Published 33 original articles · won praise 0 · Views 403

Guess you like

Origin blog.csdn.net/linuxanz/article/details/103474922