How to use linux cd command?

青灯夜游
青灯夜游Original
2020-11-02 17:19:4913734browse

linux cd command is used to switch the current working directory, the syntax format is "cd [dirName]", where the dirName representation can be an absolute path or a relative path; if the directory name is omitted, it changes to the user's home directory , that is, the directory where you were when you first logged in.

How to use linux cd command?

Related recommendations: "Linux Video Tutorial"

Linux cd command is used to switch the current working directory to dirName( directory parameters).

The dirName representation can be an absolute path or a relative path. If the directory name is omitted, it will change to the user's home directory (that is, the directory where the user just logged in).

In addition, "~" also means the home directory, "." means the current directory, and ".." means the directory above the current directory.

1. Linux cd command syntax

cd [dirName]

dirName: The target directory to be switched.

2. Linux cd command example

Jump into the test directory:

[root@/root/linuxdaxue.com]#cd testDir/
[root@/root/linuxdaxue.com/testDir]#ls
file1  file2  file3

Jump to the upper directory

[root@/root/linuxdaxue.com/testDir]#cd ..
[root@/root/linuxdaxue.com]#ls
testDir

Jump to the upper directory

[root@/root/linuxdaxue.com/testDir]#cd ../../
[root@/root]#ls

Jump to the user home directory

[root@/root/linuxdaxue.com/testDir]#ls
file1  file2  file3
[root@/root/linuxdaxue.com/testDir]#cd ~/
[root@/root]#pwd
/root

Use absolute path

[root@/root]#cd /root/linuxdaxue.com/testDir
[root@/root/linuxdaxue.com/testDir]#ls
file1  file2  file3

Use environment variables

[root@/root]#cd $TEST_PATH
[root@/root/linuxdaxue.com/testDir]#ls
file1  file2  file3

Jump to the last time Using the directory

[root@/root]#pwd
/root
[root@/root]#cd -
/root/linuxdaxue.com/testDir
[root@/root/linuxdaxue.com/testDir]#

cd command is relatively simple. It is mainly used to switch working directories. I hope everyone can master it.

For more programming-related knowledge, please visit: Introduction to Programming! !

The above is the detailed content of How to use linux cd command?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn