Essential Linux Commands

Quick reference guide to the 30 most important Linux commands for daily use. Perfect for beginners and handy for pros.

📁 Navigation

pwd

Print working directory

beginner
pwd
cd

Change directory

beginner
cd [directory]
cd /var/log
  • •cd ~ goes to home
  • •cd - goes to previous dir
  • •cd .. goes up one level
ls

List directory contents

beginner
ls [options] [path]
ls -la
  • •-l for long format
  • •-a for hidden files
  • •-h for human-readable sizes

📄 File Operations

cp

Copy files or directories

beginner
cp [options] source dest
cp -r folder1 folder2
  • •-r for recursive (directories)
  • •-i for interactive (confirm overwrite)
mv

Move or rename files

beginner
mv source dest
mv old.txt new.txt
rm

Remove files or directories

⚠️ Caution beginner
rm [options] file
rm -rf directory/
  • •-r for recursive
  • •-f for force
  • •⚠️ No recycle bin!
mkdir

Create directory

beginner
mkdir [options] dirname
mkdir -p path/to/dir
  • •-p creates parent directories too
touch

Create empty file or update timestamp

beginner
touch newfile.txt

👁️ View & Search

cat

Display file contents

beginner
cat file.txt
less

View file with pagination

beginner
less /var/log/syslog
  • •q to quit
  • •/ to search
  • •n for next match
head

Show first lines of file

beginner
head -n [lines] file
head -n 20 file.txt
tail

Show last lines of file

beginner
tail [options] file
tail -f /var/log/syslog
  • •-f follows file in real-time (great for logs)
grep

Search text patterns

beginner
grep [options] pattern file
grep -r 'error' /var/log/
  • •-i case insensitive
  • •-r recursive
  • •-n show line numbers
find

Find files and directories

intermediate
find path -name pattern
find /home -name '*.txt'
  • •-type f for files
  • •-type d for directories
  • •-mtime for modified time

🔐 Permissions

chmod

Change file permissions

intermediate
chmod [mode] file
chmod 755 script.sh
  • •755 = rwxr-xr-x
  • •644 = rw-r--r--
  • •+x to add execute
chown

Change file owner

intermediate
chown user:group file
chown www-data:www-data /var/www
sudo

Run as superuser

beginner
sudo command
sudo apt update
  • •sudo -i for root shell
  • •sudo -u user for specific user

📊 System Info

df

Disk space usage

beginner
df -h
  • •-h for human-readable sizes
du

Directory size

beginner
du [options] path
du -sh /var/
  • •-s for summary
  • •-h for human-readable
top

Real-time process monitor

beginner
top
  • •q to quit
  • •k to kill process
  • •M to sort by memory
ps

List running processes

beginner
ps aux
  • •aux shows all processes
  • •-ef is alternative format
free

Memory usage

beginner
free -h

🌐 Network

ping

Test network connectivity

beginner
ping [options] host
ping -c 4 google.com
  • •-c count to limit pings
curl

Transfer data from URLs

intermediate
curl [options] URL
curl -I https://example.com
  • •-I for headers only
  • •-o to save to file
  • •-X for HTTP method
wget

Download files

beginner
wget [options] URL
wget https://example.com/file.zip
ssh

Secure shell connection

beginner
ssh user@host
ssh [email protected]
  • •-p for custom port
  • •-i for identity file
scp

Secure copy over SSH

intermediate
scp source user@host:dest
scp file.txt user@server:/home/

Quick Reference Table

CommandPurposeExample
pwdWhere am I?pwd
ls -laList all filesls -la /etc/
cdChange directorycd /var/log
catView filecat file.txt
grepSearch textgrep 'error' log.txt
findFind filesfind / -name '*.conf'
chmodChange permissionschmod 755 script.sh
ps auxList processesps aux | grep nginx
df -hDisk usagedf -h
free -hMemory usagefree -h

💡 Tip: Combine commands with pipes (|) for powerful workflows!

# Find large log files
find /var/log -type f -size +100M | head -10

# Search for errors in logs
grep -r 'error' /var/log/ | tail -20

# Check who's using the most disk space
du -sh /* 2>/dev/null | sort -rh | head -10
Type to start searching...