SyntaxStudy
Sign Up
Linux / Bash Navigating with cd, pwd, and Shortcuts
Linux / Bash Beginner 1 min read

Navigating with cd, pwd, and Shortcuts

Effective navigation is the foundation of shell productivity. The `cd` (change directory) command moves your working directory, and `pwd` (print working directory) confirms where you are. Together with tab completion and shell history, these commands let you move around complex file systems quickly. Several shortcuts reduce typing: `cd -` returns you to the previous directory, making it easy to switch back and forth between two locations. `pushd` and `popd` implement a directory stack — you can push your current location, change directories, and then pop back. This is particularly useful in shell scripts that need to navigate temporarily and return. The `find` command is a powerful tool for locating files by name, type, size, modification time, ownership, and permissions. Unlike the simpler `locate`, `find` searches in real time rather than an indexed database, so results are always current. Combining `find` with `-exec` allows you to act on every matched file in a single command.
Example
# Print current directory
pwd

# Navigate to an absolute path
cd /var/log

# Navigate up two levels
cd ../..

# Return to previous directory
cd -

# Push current dir onto stack and cd to /tmp
pushd /tmp

# List the directory stack
dirs -v

# Return to last pushed directory
popd

# ---- find examples ----

# Find files by name (case-insensitive)
find /home -iname "*.txt"

# Find files modified in the last 7 days
find /var/log -mtime -7

# Find files larger than 100 MB
find / -size +100M -type f 2>/dev/null

# Find empty files
find . -type f -empty

# Find and delete .tmp files (with confirmation prompt removed)
find /tmp -name "*.tmp" -type f -delete

# Find files owned by a specific user
find /home -user alice

# Execute a command on each found file
find . -name "*.log" -exec gzip {} \;