Guides

Linux Commands

Quick Reference

This page covers the most commonly used Linux commands, grouped by purpose. It's designed as a practical baseline for anyone working with Linux systems.


📁 File & Directory Management

ls – List directory contents

bash
ls
ls -l        # detailed list
ls -a        # include hidden files
ls -lh       # human-readable sizes

cd – Change directory

bash
cd /path/to/dir
cd ..        # go up one level
cd ~         # go to home directory

pwd – Print working directory

bash
pwd

mkdir – Create directories

bash
mkdir new_folder
mkdir -p a/b/c   # create nested directories

rm – Remove files/directories

bash
rm file.txt
rm -r folder/     # recursive delete
rm -rf folder/    # force delete (dangerous)

cp – Copy files/directories

bash
cp file1 file2
cp -r dir1 dir2

mv – Move/rename files

bash
mv old.txt new.txt
mv file.txt /path/

📄 File Viewing & Editing

cat – Display file content

bash
cat file.txt

less – View file (scrollable)

bash
less file.txt

head / tail – Preview file sections

bash
head file.txt       # first 10 lines
tail file.txt       # last 10 lines
tail -f log.txt     # follow live logs

nano / vim – Text editors

bash
nano file.txt
vim file.txt

🔍 Search & Filtering

grep – Search text

bash
grep "text" file.txt
grep -r "text" /dir     # recursive
grep -i "text" file     # case-insensitive

find – Locate files

bash
find /path -name file.txt
find . -type f -name "*.log"

locate – Fast file search (database-based)

bash
locate filename

⚙️ System Information

uname – System info

bash
uname -a

top / htop – Process viewer

bash
top
htop

df – Disk usage

bash
df -h

du – Directory size

bash
du -sh *

free – Memory usage

bash
free -h

👤 Permissions & Ownership

chmod – Change permissions

bash
chmod 755 file
chmod +x script.sh

chown – Change ownership

bash
chown user:group file

🔄 Process Management

ps – List processes

bash
ps aux

kill – Terminate process

bash
kill PID
kill -9 PID   # force kill

pkill – Kill by name

bash
pkill nginx

🌐 Networking

ip – Network configuration

bash
ip a
ip r

ping – Test connectivity

bash
ping google.com

curl – HTTP requests

bash
curl https://example.com

wget – Download files

bash
wget https://example.com/file.zip

📦 Package Management (Debian/Ubuntu)

apt – Package manager

bash
apt update
apt upgrade
apt install package
apt remove package

📜 Archives & Compression

tar – Archive files

bash
tar -cvf archive.tar folder/
tar -xvf archive.tar

gzip / gunzip

bash
gzip file
gunzip file.gz

🔐 Sudo & User Control

sudo – Run as superuser

bash
sudo command

whoami – Current user

bash
whoami

🧠 Useful Shortcuts & Tips

  • Ctrl + C → Stop current command
  • Ctrl + Z → Suspend process
  • Ctrl + R → Search command history
  • !! → Repeat last command
  • history → Show command history

🧩 Pro Tips

  • Combine commands with pipes:
bash
cat file.txt | grep "error"
  • Redirect output:
bash
command > output.txt     # overwrite
command >> output.txt    # append
  • Use tab completion to speed up typing.

⚠️ Common Pitfalls

  • rm -rf / → catastrophic (never run blindly)
  • Always double-check paths when using sudo
  • Be cautious with wildcards (*)