15 practice examples of the Linux 'cd' command
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.

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$
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$
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$
4. (a) Switch the current directory to the previous directory
avi@tecmint:/usr/local/lib$ cd - /usr/local avi@tecmint:/usr/local$
4. (b) Switch the current directory to the upper-level directory
avi@tecmint:/usr/local/lib$ cd .. avi@tecmint:/usr/local$
5. Display the last working directory we left
avi@tecmint:/usr/local$ cd -- /home/avi
6. Return two levels from the current directory to the upper level
avi@tecmint:/usr/local$ cd ../../ avi@tecmint:/$
7. Return to the user’s home directory from any directory
avi@tecmint:/usr/local$ cd ~ avi@tecmint:~$
or
avi@tecmint:/usr/local$ cd avi@tecmint:~$
8. Switch the working directory to the current working directory
avi@tecmint:~/Downloads$ cd . avi@tecmint:~/Downloads$
or
avi@tecmint:~/Downloads$ cd ./ avi@tecmint:~/Downloads$
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$
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$
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$
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:~$
13.Linux下的pushed和poped
Pushed和poped是Linux bash命令,也是其他几个能够保存当前工作目录位置至内存,并且从内存读取目录作为当前目录的脚本,这些脚本也可以切换目录
avi@tecmint:~$ pushd /var/www/html /var/www/html ~ avi@tecmint:/var/www/html$
上面的命令保存当前目录到内存,然后切换到要求的目录。一旦poped被执行,它会从内存取出保存的目录位置,作为当前目录
avi@tecmint:/var/www/html$ popd ~ avi@tecmint:~$
14.切换到名字带有空格的目录
avi@tecmint:~$ cd test/ tecmint/ avi@tecmint:~/test tecmint$
或
avi@tecmint:~$ cd 'test tecmint' avi@tecmint:~/test tecmint$
或
avi@tecmint:~$ cd "test tecmint"/ avi@tecmint:~/test tecmint$
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 . ...
我们尝试使用最少的词句和一如既往的友好,来让你了解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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

Sublime Text provides shortcuts to improve development efficiency, including commonly used (save, copy, cut, etc.), editing (indentation, formatting, etc.), navigation (project panel, file browsing, etc.), and finding and replacing shortcuts. Proficiency in using these shortcut keys can significantly improve Sublime's efficiency.
