- Linux
- Linux command
- here
cd command - change current directory
You can change the current directory using the cd command.
cd DirectoryName
Specify the directory name with a relative path
To change the current directory to the directory "labo" with the cd command, execute the following command.
cd labo
This means that the "labo" directory in the current hierarchy of the current directory is the current directory, starting from the current current directory.
This is called specifying the directory name with a relative path.
Specify the directory name with an absolute path
You can also specify the directory name with an absolute path with the cd command.
To change to the directory "/usr/local/lib", execute the following command.
cd /usr/local/lib
Absolute paths are characterized by starting with "/". The cd command looks at the leading "/" to identify whether it is a relative path or an absolute path.
What is the current directory?
The current directory is the directory you are currently working on. Think of a directory in Linux as having the same meaning as a folder in Windows.
When you log in to Linux, the location called your home directory is your current directory.
/home/kimoto
You can use the pwd command to display the current directory.
pwd
If you find yourself in the wrong directory, you can check it with the pwd command.
Special directory name
Remember the following directory names as special directory names.
Current current directory .
"." Is a special directory name that points to the current current directory.
cd .
This just changes the current directory to the current current directory, so nothing happens.
But remember the meaning. The cd command has no particular meaning, but there are some situations where it makes sense.
Parent directory ..
".." is a special directory name that points to the parent directory.
It is frequently used when you want to change the current directory and return to the parent directory one level higher.
cd ..
Home directory ~
"~" Is a special directory name that points to your home directory.
cd ~
If the user is "kimoto", the home directory will be expanded as follows.
cd /home/kimoto
The special directories ".", "..", and "~" are not actually interpreted by the cd command, but by the shell, but they are frequently used by the cd command, so I will introduce them. Did.
cd command sample
This is a sample that changes the current directory to the home directory, creates a labo directory there, and changes the current directory to the labo directory.
# Change the current directory to your home directory cd ~ # Create labo directory mkdir labo # Change current directory to labo cd labo # Check the current current directory with the pwd command pwd
In the Perl seminar environment, it was displayed as follows.
/home/kimoto/labo