Skip to content

Linux Commands Reference

Quick reference for common Linux commands. Covers the commands you'll use daily on EC2 instances, in labs, and in the terminal.


Command Full Name What It Does
pwd Print Working Directory Show current path
ls List List files in current directory
ls -la List (long + hidden) Show all files with permissions
cd Change Directory Navigate to directory
mkdir Make Directory Create new directory
rmdir Remove Directory Delete empty directory
rm -rf Remove (recursive, force) Delete directory and contents — irreversible
cp Copy Copy files/directories
mv Move Move or rename files
touch Touch Create empty file or update timestamp
cat Concatenate Display file contents
less Less View file one page at a time
head Head First 10 lines of file
tail -f Tail (follow) Last lines of file, live-updating (great for logs)

Command What It Does
grep "pattern" file Search for text in file
grep -r "pattern" dir/ Recursive search
find . -name "*.log" Find files by name
locate filename Fast file search (uses index)

Permissions

Command What It Does
chmod 755 file Set permissions (owner: rwx, group: rx, other: rx)
chmod +x script.sh Make file executable
chown user:group file Change file owner
sudo Run as superuser
whoami Show current user

Permission numbers: r=4, w=2, x=1755 = rwxr-xr-x


Processes

Command What It Does
top Live process monitor
ps aux All running processes
kill PID Stop process by ID
kill -9 PID Force kill
nohup command & Run command that survives logout

Networking

Command What It Does
ping 8.8.8.8 Test connectivity (use Google DNS to rule out DNS issues)
curl https://example.com Make HTTP request
wget https://url Download file
ssh -i key.pem user@host SSH with PEM key
scp -i key.pem file user@host:/path Secure copy to remote
netstat -tuln Show listening ports
ss -tuln Modern alternative to netstat
ifconfig / ip addr Show network interfaces
nslookup domain DNS lookup
dig domain Detailed DNS lookup

Disk & Storage

Command What It Does
df -h Disk space usage (human readable)
du -sh * Size of each item in current directory
lsblk List block devices (disks, volumes)
mount List mounted filesystems

Archives & Compression

Command What It Does
tar -czf archive.tar.gz dir/ Create gzip archive
tar -xzf archive.tar.gz Extract gzip archive
gzip file Compress file
unzip file.zip Extract zip

System Info

Command What It Does
uname -a System info (kernel, architecture)
uptime How long system has been running
history Previous commands
man command Manual page for any command
which command Path to a command's binary

File Descriptors (Redirection)

command > file.txt     # stdout to file (overwrite)
command >> file.txt    # stdout to file (append)
command 2> err.txt     # stderr to file
command 2>&1           # stderr to stdout
command &>/dev/null    # discard all output

Numbers: 0 = stdin, 1 = stdout, 2 = stderr


Shell Profile Files

File When It Loads
~/.bash_profile Login shell (SSH, console)
~/.bashrc Interactive non-login shell (new terminal tab)
~/.zshrc Zsh equivalent of .bashrc

Apply changes without restarting: source ~/.bashrc