Getting Started: 15 practice examples on Linux's 'cd' command
In Linux, The 'cd' (Change directory) command is the most important and commonly used command for beginners and system administrators. For administrators who manage servers without graphic interfaces, 'cd' is the only way to go to the directory, check logs, execute programs, applications, scripts, and other tasks. For new users, it is the initial command they must learn by themselves.
Example of 15 cd commands in Linux
Therefore, please study hard. Here we will bring you 15 basic 'cd' commands, which are skillful and shortcuts and learn to use these learned skills, it will greatly reduce your effort and time spent on the terminal.
Course details
- Command name: cd
- Representative: Switch the Directory
- Platform: All Linux releases
- Execution method: Command Line
- Permission: access your own directory or other specified directories
- Level: Basic/beginner
Switch from the current directory to/usr/local
- Avi @ tecmint :~ $ Cd/usr/local
- Avi @ tecmint:/usr/local $
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 $
Use the relative path to switch from the current path to/usr/local/lib
- Avi @ tecmint:/usr/local $ cd lib
- Avi @ tecmint:/usr/local/lib $
(A) switch the current directory to the parent directory
- Avi @ tecmint:/usr/local/lib $ cd-
- /Usr/local
- Avi @ tecmint:/usr/local $
(B) switch the current directory to the parent directory
- Avi @ tecmint:/usr/local/lib $ cd ..
- Avi @ tecmint:/usr/local $
Display the last left working directory (use the '-' option)
- Avi @ tecmint:/usr/local $ cd --
- /Home/avi
Returns two layers from the current directory to the upper-level
- Avi @ tecmint:/usr/local $ cd ../../
- Avi @ tecmint:/$
Return from any directory to the user's home directory
- Avi @ tecmint:/usr/local $ cd ~
- Avi @ tecmint :~ $
Or
- Avi @ tecmint:/usr/local $ cd
- Avi @ tecmint :~ $
Switch the working directory to the current working directory (LCTT: What is the significance of this ?!)
- Avi @ tecmint :~ /Downloads $ cd.
- Avi @ tecmint :~ /Downloads $
Or
- Avi @ tecmint :~ /Downloads $ cd ./
- Avi @ tecmint :~ /Downloads $
Your current directory is "/usr/local/lib/python3.4/dist-packages". Switch to "/home/avi/Desktop/". A command line is required, switch up until '/', and then use the absolute path
- Avi @ tecmint:/usr/local/lib/python3.4/dist-packages $ cd.../home/avi/Desktop/
- Avi @ tecmint :~ /Desktop $
Switch from the current working directory to/var/www/html. Requirement: do not complete the command. Use the TAB
- Avi @ tecmint:/var/www $ cd/v <TAB>/w <TAB>/h <TAB>
- Avi @ tecmint:/var/www/html $
Switch from the current directory to/etc/v _. Ah, you forgot the directory name, but you don't want to use the TAB
- Avi @ tecmint :~ $ Cd/etc/v *
- Avi @ tecmint:/etc/vbox $
Note: If only one directory starts with 'V', it will be moved to 'vbox '. If many directories start with 'V' and the command line does not provide more standards, this will be moved to the first directory starting with 'V' (in the order in which letters exist in the Standard Dictionary)
You want to switch to the user's 'av' directory (not sure if it is avi or avt) without using a TAB
- Avi @ tecmint:/etc $ cd/home/av?
- Avi @ tecmint :~ $
Pushed and poped in Linux
Pushed and poped are Linux bash commands. They are also the scripts that can save the current working directory location to the memory and read the directory from the memory as the current directory. These scripts can also switch directories.
- Avi @ tecmint :~ $ Pushd/var/www/html
- /Var/www/html ~
- Avi @ tecmint:/var/www/html $
The preceding command saves the current directory to the memory and switches to the required directory. Once poped is executed, it extracts the saved directory location from the memory as the current directory
- Avi @ tecmint:/var/www/html $ popd
- ~
- Avi @ tecmint :~ $
Switch to the directory with spaces
- Avi @ tecmint :~ $ Cd test \ tecmint/
- Avi @ tecmint :~ /Test tecmint $
Or
- Avi @ tecmint :~ $ Cd 'test cmint'
- Avi @ tecmint :~ /Test tecmint $
Or
- Avi @ tecmint :~ $ Cd "test tecmint "/
- Avi @ tecmint :~ /Test tecmint $
Switch from the current directory to the download directory, and then list the content it contains (using a line of command)
- 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
- .
- ...
We try to use the least words and are as friendly as ever to help you understand how Linux works and runs.
This is all content. I will come back soon with another interesting topic.
10 useful Linux Command Interview Questions and answers
Linux Command cd
Cat for Linux commands
Linux Command alias/unalias
Linux Command Parsing: su root and su-root
Interactive input of Linux commands read
This article permanently updates the link address: