Cheatsheet essential commands - mishraxharshit/harshitxmishra.github.io GitHub Wiki
A quick reference for the most-used Linux commands. Not a replacement for the full phases — use this once you have learned the concepts.
pwd # current directory
cd /path/to/dir # change directory (absolute)
cd relative/path # change directory (relative)
cd .. # go up one level
cd - # go to previous directory
cd ~ # go to home directory
ls -la # list all files with details
ls -lh # human-readable file sizes
ls -lt # sort by modification time
touch file.txt # create empty file
mkdir -p dir/subdir # create directory (with parents)
cp source dest # copy file
cp -r source/ dest/ # copy directory recursively
mv source dest # move or rename
rm file # delete file
rm -r directory/ # delete directory
ln -s target linkname # create symbolic link
cat file.txt # print entire file
less file.txt # page through file
head -20 file.txt # first 20 lines
tail -20 file.txt # last 20 lines
tail -f file.txt # follow live updates
wc -l file.txt # count lines
grep "pattern" file # search in file
grep -r "pattern" directory/ # recursive search
grep -i "pattern" file # case insensitive
grep -v "pattern" file # invert (non-matching lines)
find /path -name "*.txt" # find files by name
find /path -type f -mtime -7 # files modified in last 7 days
find /path -size +10M # files larger than 10MB
which command # find command's binary location
cut -d: -f1 /etc/passwd # extract field 1 (colon delimiter)
sort file.txt # sort alphabetically
sort -n numbers.txt # sort numerically
sort | uniq # remove duplicates
sort | uniq -c # count occurrences
sed 's/old/new/g' file # replace all occurrences
awk '{print $1}' file # print first field
awk -F: '{print $1}' file # colon-delimited first field
tr 'a-z' 'A-Z' # convert to uppercase
chmod 755 file # rwxr-xr-x
chmod 644 file # rw-r--r--
chmod 600 file # rw------- (private)
chmod +x script.sh # add execute permission
chmod -R 755 directory/ # recursive
chown user:group file # change owner and group
sudo chown -R alice:alice /home/alice/
whoami # current user
id # uid, gid, and groups
id alice # info for another user
sudo command # run as root
sudo -u user command # run as specific user
adduser bob # create user interactively
usermod -aG docker alice # add alice to docker group
groups # list current user's groups
passwd # change your password
sudo passwd bob # change bob's password
ps aux # all running processes
ps aux | grep nginx # search for process
top # live process viewer
htop # improved live viewer
kill PID # SIGTERM (polite)
kill -9 PID # SIGKILL (force)
pkill nginx # kill by name
command & # run in background
jobs # list background jobs
fg # bring job to foreground
nohup command & # run, survive logout
systemctl status nginx # check service status
systemctl start nginx # start service
systemctl stop nginx # stop service
systemctl restart nginx # restart service
systemctl reload nginx # reload config
systemctl enable nginx # start on boot
systemctl disable nginx # do not start on boot
systemctl enable --now nginx # enable and start now
journalctl -u nginx # service logs
journalctl -u nginx -f # follow service logs
journalctl -b # all logs since boot
ip addr show # IP addresses
ip route show # routing table
ping -c 4 google.com # test connectivity
traceroute google.com # trace path to host
ss -tlnp # listening TCP ports
dig google.com # DNS lookup
curl -I https://example.com # HTTP headers only
ssh user@host # connect to server
scp file user@host:/path/ # copy file to server
rsync -avz src/ user@host:/dst/ # sync directory
df -h # disk space by filesystem
du -sh /var/log/ # directory size
du -sh * | sort -rh # subdirectory sizes, largest first
lsblk # list block devices
mount # show mounted filesystems
sudo fdisk -l # list disk partitions
# Ubuntu / Debian (apt)
sudo apt update # update package index
sudo apt upgrade # upgrade all packages
sudo apt install nginx # install package
sudo apt remove nginx # remove package
sudo apt autoremove # remove unused dependencies
apt search nginx # search for package
apt show nginx # package information
RHEL / Fedora / CentOS (dnf)
sudo dnf update
sudo dnf install nginx
sudo dnf remove nginx
dnf search nginx
command > file.txt # stdout to file (overwrite)
command >> file.txt # stdout to file (append)
command 2> errors.txt # stderr to file
command > all.txt 2>&1 # stdout and stderr to file
command < input.txt # read stdin from file
cmd1 | cmd2 | cmd3 # pipe chain
command > /dev/null 2>&1 # discard all output
| Shortcut | Action |
|---|---|
| Ctrl+C | Kill running command |
| Ctrl+Z | Suspend running command |
| Ctrl+D | Exit shell / end of input |
| Ctrl+L | Clear screen |
| Ctrl+R | Search command history |
| Ctrl+A | Move cursor to start of line |
| Ctrl+E | Move cursor to end of line |
| Ctrl+W | Delete previous word |
| Tab | Autocomplete |
| !! | Repeat last command |
| !word | Repeat last command starting with word |
man command # full manual page
command --help # quick help
info command # detailed GNU documentation
apropos keyword # find commands by keyword
type command # what kind of command it is