Problem Statement
Explain common directory navigation commands and shortcuts in Linux. Include cd, pushd, popd, and special directory references.
Explanation
The cd command changes the current directory. cd /path goes to absolute path, cd path goes to relative path, cd without arguments or cd ~ goes to home directory, cd - returns to previous directory (useful for toggling between two directories), and cd .. moves to parent directory. Understanding these shortcuts speeds up navigation significantly.
Pushd and popd maintain a directory stack for navigating between multiple directories. Pushd /path changes to the path and pushes current directory onto the stack. Popd returns to the directory at top of stack. Use dirs to view the stack. This is useful when working in multiple locations and wanting to quickly return.
Special directory references include . (current directory), .. (parent directory), ~ (home directory), / (root directory), and - (previous directory). These work with most commands, like cp file.txt .. to copy to parent directory, or ./script.sh to execute a script in current directory.
Tab completion is essential for efficient navigation - typing cd /ho and pressing Tab completes to /home. Typing cd /home/u then Tab shows options if multiple matches exist. Combine these techniques with history search (Ctrl+R) for maximum efficiency. Mastering navigation is fundamental for productive Linux usage.
