search
HomeSystem TutorialLINUX15 practice examples of the Linux 'cd' command

15 practice examples of the Linux 'cd' command

Feb 13, 2024 pm 07:42 PM
linuxlinux tutoriallinux systemLinux operating systemlinux commandshell scriptembeddedlinuxGetting started with linuxlinux learning

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$

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!

Statement
This article is reproduced at:良许Linux教程网. If there is any infringement, please contact admin@php.cn delete
How does performance differ between Linux and Windows for various tasks?How does performance differ between Linux and Windows for various tasks?May 14, 2025 am 12:03 AM

Linux performs well in servers and development environments, while Windows performs better in desktop and gaming. 1) Linux's file system performs well when dealing with large numbers of small files. 2) Linux performs excellently in high concurrency and high throughput network scenarios. 3) Linux memory management has more advantages in server environments. 4) Linux is efficient when executing command line and script tasks, while Windows performs better on graphical interfaces and multimedia applications.

How to Create GUI Applications In Linux Using PyGObjectHow to Create GUI Applications In Linux Using PyGObjectMay 13, 2025 am 11:09 AM

Creating graphical user interface (GUI) applications is a fantastic way to bring your ideas to life and make your programs more user-friendly. PyGObject is a Python library that allows developers to create GUI applications on Linux desktops using the

How to Install LAMP Stack with PhpMyAdmin in Arch LinuxHow to Install LAMP Stack with PhpMyAdmin in Arch LinuxMay 13, 2025 am 11:01 AM

Arch Linux provides a flexible cutting-edge system environment and is a powerfully suited solution for developing web applications on small non-critical systems because is a completely open source and provides the latest up-to-date releases on kernel

How to Install LEMP (Nginx, PHP, MariaDB) on Arch LinuxHow to Install LEMP (Nginx, PHP, MariaDB) on Arch LinuxMay 13, 2025 am 10:43 AM

Due to its Rolling Release model which embraces cutting-edge software Arch Linux was not designed and developed to run as a server to provide reliable network services because it requires extra time for maintenance, constant upgrades, and sensible fi

12 Must-Have Linux Console [Terminal] File Managers12 Must-Have Linux Console [Terminal] File ManagersMay 13, 2025 am 10:14 AM

Linux console file managers can be very helpful in day-to-day tasks, when managing files on a local machine, or when connected to a remote one. The visual console representation of the directory helps us quickly perform file/folder operations and sav

qBittorrent: A Powerful Open-Source BitTorrent ClientqBittorrent: A Powerful Open-Source BitTorrent ClientMay 13, 2025 am 10:12 AM

qBittorrent is a popular open-source BitTorrent client that allows users to download and share files over the internet. The latest version, qBittorrent 5.0, was released recently and comes packed with new features and improvements. This article will

Setup Nginx Virtual Hosts, phpMyAdmin, and SSL on Arch LinuxSetup Nginx Virtual Hosts, phpMyAdmin, and SSL on Arch LinuxMay 13, 2025 am 10:03 AM

The previous Arch Linux LEMP article just covered basic stuff, from installing network services (Nginx, PHP, MySQL, and PhpMyAdmin) and configuring minimal security required for MySQL server and PhpMyadmin. This topic is strictly related to the forme

Zenity: Building GTK  Dialogs in Shell ScriptsZenity: Building GTK Dialogs in Shell ScriptsMay 13, 2025 am 09:38 AM

Zenity is a tool that allows you to create graphical dialog boxes in Linux using the command line. It uses GTK , a toolkit for creating graphical user interfaces (GUIs), making it easy to add visual elements to your scripts. Zenity can be extremely u

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),