Master Linux Shell Navigation: cd, pwd, and Handy Keyboard Shortcuts
This guide explains how to display the current directory, change directories using relative and absolute paths, leverage special symbols like ~ and -, chain commands with pipes and logical operators, and use essential Ctrl shortcuts and other common shell commands for efficient terminal work.
Displaying the Current Directory
Use pwd to print the absolute path of the working directory, for example /home/xiaochao/Download.
Changing Directories with cd
Relative path: cd Download # enters the Download folder under the current directory.
Absolute path: cd /var/log # jumps directly to /var/log.
Current directory symbol: cd . # stays in the current folder.
Parent directory: cd .. # moves up one level.
Two levels up (zsh only): cd ... # attempts to go up two levels; not supported by bash.
Special Symbols
Tilde ( ~) expands to the user's home directory ( $HOME), e.g., /home/xiaochao. Running cd without arguments is equivalent to cd ~.
Hyphen ( -) returns to the previous directory, mirroring the “back” button in graphical file managers. Example sequence:
cd /home/xiaochao/Download
cd /home/xiaochao
cd - # back to /home/xiaochao/Download
cd - # back to /home/xiaochaoExecuting Multiple Commands
Pipe ( |) passes the output of the left command to the right one, e.g., ls | wc -l counts files in the current directory.
Logical AND ( &&) runs the second command only if the first succeeds, e.g., aa && ls.
Background ampersand ( &) runs the first command in the background while still waiting for it to finish before starting the second, e.g., aa & ls.
Logical OR ( ||) runs the second command in parallel with the first, e.g., aa || ls.
Useful Ctrl Shortcuts
Ctrl+A– move cursor to the beginning of the line. Ctrl+E – move cursor to the end of the line. Ctrl+L – clear the terminal screen (same as clear). Ctrl+U – delete everything before the cursor on the current line. Ctrl+Y – paste the text removed by Ctrl+U. Ctrl+R – search command history interactively. Ctrl+C – terminate the running foreground process. Ctrl+D – send an EOF (end‑of‑file) signal, often closing the terminal. Ctrl+Z – suspend the current process and move it to the background.
Other Common Shell Commands
$?– exit status of the last command. !$ – last argument of the previous command. !! – repeat the previous command. man ascii – view the ASCII table. >file.txt – create or truncate file.txt (shorter than touch). du -s * | sort -n | tail – list the ten largest items in the current directory. ssh user@server bash < script.sh – execute a local script on a remote host without copying it.
convert input.png -gravity NorthWest -background transparent -extent 720x200 output.png– resize an image with ImageMagick. fgrep -r "Hello World" ./* – recursively search for the string "Hello World" in the current directory. locate – find files by name (requires mlocate and periodic updatedb updates).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
