Linux Cheatsheet

Navigating the Filesystem

Use this Linux reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

Essential Navigation

pwd             # print working directory
cd /etc         # absolute path
cd Documents    # relative path
cd ..           # parent directory
cd -            # previous directory
cd ~            # home directory
cd              # home directory (shorthand)

Listing Files

ls              # list directory
ls -l           # long format (perms, owner, size, date)
ls -lh          # human-readable sizes (KB, MB)
ls -a           # include hidden files (dot-files)
ls -lA          # long + hidden, exclude . and ..
ls -lt          # sort by modification time (newest first)
ls -lS          # sort by size (largest first)
ls -R           # recursive
ls --color=auto # colorize output

Directory Tree

tree                    # visual tree (install if missing)
tree -L 2               # limit depth to 2 levels
tree -a                 # include hidden files
tree -d                 # directories only
tree --gitignore        # respect .gitignore
find . -maxdepth 2 -type d   # alternative with find

Path Concepts

SymbolMeaning
/filesystem root
~current user's home (/home/user)
.current directory
..parent directory
-(in cd) previous directory

Key Filesystem Paths

PathContents
/bin, /usr/binuser executables
/sbin, /usr/sbinsystem/admin executables
/etcsystem-wide config files
/varvariable data (logs, spool, cache)
/tmptemporary files (cleared on reboot)
/home/<user>user home directories
/rootroot user home
/procvirtual FS — kernel/process info
/sysvirtual FS — device/kernel tunables
/devdevice files
/mnt, /mediamount points
/optoptional third-party software
/lib, /usr/libshared libraries
/bootbootloader, kernel images

Globbing (Filename Expansion)

PatternMatches
*any number of any characters
?exactly one character
[abc]one character from set
[a-z]one character in range
[^abc]any character NOT in set
{jpg,png}either literal (brace expansion)
**recursive match (Bash 4+ with globstar)
ls *.log            # all .log files
ls file?.txt        # file1.txt, fileA.txt, etc.
ls report_{2023,2024}.pdf
shopt -s globstar   # enable ** in Bash
ls **/*.js          # all .js files recursively

Pushd / Popd Stack

pushd /var/log      # push cwd, cd to /var/log
pushd /etc          # push again
dirs -v             # show directory stack
popd                # return to previous directory
popd +1             # pop entry at index 1