Home > System Tutorial > LINUX > 15 practice examples of the Linux 'cd' command

15 practice examples of the Linux 'cd' command

WBOY
Release: 2024-02-13 19:42:03
forward
505 people have browsed it

In the Linux operating system, the "cd" (change directory) command is one of the most commonly used and important commands for novices and system administrators. For administrators who manage servers without a graphical interface, it is essential to use the "cd" command to enter directories, check logs, execute programs/applications/scripts, and complete other tasks. For novices, the "cd" command is also one of the basic commands they must learn.

15 practice examples of the Linux cd command

So, please study hard. We will bring you 15 basic 'cd' commands here. They are full of skills and shortcuts. Learning to use these learned skills will greatly reduce your expenses on the terminal. Effort and time

Course content

Command name: cd

stands for: switch directory

Platform used: all Linux distributions

Execution method: command line

Permissions: access your own directory or other specified directories

Level: Basic/Beginner

1. Switch from the current directory to /usr/local

avi@tecmint:~$ cd /usr/local
avi@tecmint:/usr/local$
Copy after login

2. Use the absolute path to switch from the current directory to /usr/local/lib

avi@tecmint:/usr/local$ cd /usr/local/lib
avi@tecmint:/usr/local/lib$
Copy after login

3. Use a relative path to switch from the current path to /usr/local/lib

avi@tecmint:/usr/local$ cd lib
avi@tecmint:/usr/local/lib$
Copy after login

4. (a) Switch the current directory to the previous directory

avi@tecmint:/usr/local/lib$ cd -
/usr/local
avi@tecmint:/usr/local$
Copy after login

4. (b) Switch the current directory to the upper-level directory

avi@tecmint:/usr/local/lib$ cd ..
avi@tecmint:/usr/local$
Copy after login

5. Display the last working directory we left

avi@tecmint:/usr/local$ cd --
/home/avi
Copy after login

6. Return two levels from the current directory to the upper level

avi@tecmint:/usr/local$ cd ../../
avi@tecmint:/$
Copy after login

7. Return to the user’s home directory from any directory

avi@tecmint:/usr/local$ cd ~
avi@tecmint:~$
Copy after login

or

avi@tecmint:/usr/local$ cd
avi@tecmint:~$
Copy after login

8. Switch the working directory to the current working directory

avi@tecmint:~/Downloads$ cd .
avi@tecmint:~/Downloads$
Copy after login

or

avi@tecmint:~/Downloads$ cd ./
avi@tecmint:~/Downloads$
Copy after login

9. Request a line of command to switch

Your current directory is "/usr/local/lib/python3.4/dist-packages", now you want to switch to "/home/avi/Desktop/", the requirements are: one line of command, switch up until '/ ', then use the absolute path

avi@tecmint:/usr/local/lib/python3.4/dist-packages$ cd ../../../../../home/avi/Desktop/
avi@tecmint:~/Desktop$
Copy after login

10. Request to use TAB

Switch from the current working directory to /var/www/html, requirement: do not type the complete command, use TAB

avi@tecmint:/var/www$ cd /v/w/h
avi@tecmint:/var/www/html$
Copy after login

11. Forgot the directory name

Switch from the current directory to /etc/v__ _, oh, you forgot the name of the directory, but you don’t want to use TAB

avi@tecmint:~$ cd /etc/v*
avi@tecmint:/etc/vbox$
Copy after login

Please note: If there is only one directory starting with 'v', this will be moved to 'vbox'. If there are many directories starting with 'v' and no further criteria are provided on the command line, this will move to the first directory starting with 'v' (as per The order in which they appear alphabetically in a standard dictionary)

12.切换想要的用户

你想切换到用户‘av‘(不确定是avi还是avt)目录,不用TAB

avi@tecmint:/etc$ cd /home/av?
avi@tecmint:~$
Copy after login

13.Linux下的pushed和poped

Pushed和poped是Linux bash命令,也是其他几个能够保存当前工作目录位置至内存,并且从内存读取目录作为当前目录的脚本,这些脚本也可以切换目录

avi@tecmint:~$ pushd /var/www/html
/var/www/html ~
avi@tecmint:/var/www/html$ 
Copy after login

上面的命令保存当前目录到内存,然后切换到要求的目录。一旦poped被执行,它会从内存取出保存的目录位置,作为当前目录

avi@tecmint:/var/www/html$ popd
~
avi@tecmint:~$
Copy after login

14.切换到名字带有空格的目录

avi@tecmint:~$ cd test/ tecmint/
avi@tecmint:~/test tecmint$
Copy after login

avi@tecmint:~$ cd 'test tecmint'
avi@tecmint:~/test tecmint$
Copy after login

avi@tecmint:~$ cd "test tecmint"/
avi@tecmint:~/test tecmint$
Copy after login

15.切换并显示出来

从当前目录切换到下载目录,然后列出它所包含的内容(使用一行命令)

avi@tecmint:/usr$ cd ~/Downloads && ls
...
.
service_locator_in.xls
sources.list
teamviewer_linux_x64.deb
tor-browser-linux64-3.6.3_en-US.tar.xz
.
...
Copy after login

我们尝试使用最少的词句和一如既往的友好,来让你了解Linux的工作和执行。

这就是所有内容。我很快会带着另一个有趣的主题回来的。

The above is the detailed content of 15 practice examples of the Linux 'cd' command. For more information, please follow other related articles on the PHP Chinese website!

source:lxlinux.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template