Cheat Sheet
Linux
Filesystem Navigation
- ls
- List directory contents
- cd
- Change directories
- pwd
- Print current working directory
- mkdir, rmdir
- Create / remove directories
- touch, cp, mv, rm
- Create, copy, move, remove files
File Inspection
- cat, less, more
- View file contents
- head, tail
- View start / end of a file
- grep
- Search text within files
- wc
- Word, line, and character counts
Permissions & Ownership
- chown user:group file
- Change file owner and group
- chgrp group file
- Change group ownership
- chmod +x file
- Add execute permission
- chmod u/g/o/r/w/x
- Modify permissions for user, group, other
- chmod 644 file
- Octal notation, equivalent to symbolic u+rw,g+r,o+r
Networking
- ip addr show
- Show network interfaces and IP info (or ifconfig)
- ping
- Check connectivity to a host
- curl, wget
- Retrieve files / web content from a URL
- ss
- Display network connections, routing tables, open ports (or netstat)
- traceroute
- Trace the route to a network host
- dig, nslookup
- DNS queries and domain resolution checks
Process Management
- ps
- List running processes
- top / htop
- Interactive real-time view of processes
- kill, pkill, killall
- Terminate processes by PID or name
- &, bg, fg, jobs
- Run jobs in the background, bring them to the foreground
- nice, renice
- Adjust process priorities
Environment & Users
- env
- Show all environment variables
- echo $VAR_NAME
- Display a variable's value
- export VAR="value"
- Set a variable for the current shell/session (add to ~/.bashrc to persist)
- useradd, userdel
- Add / remove user accounts
- usermod -aG group user
- Modify a user account, e.g. add to a group
- passwd
- Set or change a user's password
- groupadd, groupdel
- Create / delete groups
- gpasswd -a user group
- Add a user to a group
VIM Basics
- h j k l
- Move left / down / up / right
- i, Esc
- Insert mode; return to command mode
- :wq
- Save and quit
- x
- Delete a character
- dd
- Delete the current line
- yy, p
- Yank (copy) the current line, paste
- u, Ctrl+r
- Undo, redo
- /pattern, ?pattern
- Search forward / backward
- :%s/old/new/g
- Replace all occurrences of "old" with "new"