Linux command reference (Ubuntu/Debian flavoured).
Finding files
find . -name "*.log" by name, recursively
find . -type f -mtime -2 files changed in the last 2 days
find . -type f -size +100M files bigger than 100 MB
find . -name "*.tmp" -delete delete matches (check without -delete first)
Searching inside files
grep -rn "TODO" src/ recursive, with line numbers
grep -ri "error" *.log case-insensitive
grep -v "^#" config.ini lines NOT starting with #
grep -c "GET /" access.log count matching lines
Archives
tar czf backup.tar.gz dir/ create gzip archive
tar xzf backup.tar.gz -C /target extract into /target
tar tzf backup.tar.gz list contents
zip -r site.zip site/ / unzip site.zip
Disk space
df -h free space per filesystem
du -sh * size of each item here
du -h --max-depth=1 / | sort -h biggest top-level directories
Processes
ps aux | grep python find processes
top / htop live view
kill PID / kill -9 PID stop politely / forcibly
pgrep -a nginx PIDs with command lines
Services (systemd)
systemctl status nginx
sudo systemctl restart nginx
journalctl -u nginx -n 50 --no-pager last 50 log lines of a service
journalctl -f follow the system log
Permissions
chmod 644 file rw-r--r-- chmod 755 dir rwxr-xr-x
chmod +x script.sh make executable
sudo chown user:group file change owner
Text processing
head -n 20 file / tail -n 20 file / tail -f file
sort file | uniq -c | sort -rn count duplicate lines
cut -d, -f1,3 data.csv columns 1 and 3 of a CSV
awk '{print $1}' access.log first field of each line
sed 's/old/new/g' file replace text (add -i to edit in place)
wc -l file count lines
Networking
ip addr interfaces and addresses
ss -tlnp listening TCP ports and their programs
ping -c 4 host / dig example.comOr: /edit?page=LinuxCommands&text=your+text&name=YourName
Index | Recent changes | permalink | rev 99e4cbccae4c