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.
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
| Symbol | Meaning |
|---|---|
/ | filesystem root |
~ | current user's home (/home/user) |
. | current directory |
.. | parent directory |
- | (in cd) previous directory |
Key Filesystem Paths
| Path | Contents |
|---|---|
/bin, /usr/bin | user executables |
/sbin, /usr/sbin | system/admin executables |
/etc | system-wide config files |
/var | variable data (logs, spool, cache) |
/tmp | temporary files (cleared on reboot) |
/home/<user> | user home directories |
/root | root user home |
/proc | virtual FS — kernel/process info |
/sys | virtual FS — device/kernel tunables |
/dev | device files |
/mnt, /media | mount points |
/opt | optional third-party software |
/lib, /usr/lib | shared libraries |
/boot | bootloader, kernel images |
Globbing (Filename Expansion)
| Pattern | Matches |
|---|---|
* | 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