Linux Basic Commands - CodeSwordsman

A quick reference for everyday file, permission, process, network and archive commands on mainstream Linux distributions.

Universal (CentOS / Ubuntu / Debian)Updated 2026-10-2941 commands

Files & Directories

Print the absolute path of the current directory

pwd

List all files including hidden ones, with human-readable sizes

ls -alh

Change into a directory; cd - returns to the previous one

cd /var/log

Copy a directory recursively

cp -r /opt/app /backup/app

Move or rename a file

mv /data/app.log /data/app.log.bak
Risky

Force-delete a directory recursively; double-check the path first

rm -rf /data/cache

Create nested directories, creating parents as needed

mkdir -p /data/app/logs

Create a symbolic link, commonly used for version switching

ln -s /opt/app/v2 /opt/app/current

Find log files modified more than 7 days ago

find /var/log -name "*.log" -mtime +7

Show directory sizes sorted by size

du -sh /data/* | sort -h

View & Search

Show OS release information

cat /etc/os-release

Page through a large file; press / to search and q to quit

less /etc/nginx/nginx.conf

Follow the last 200 lines of a log in real time

tail -f -n 200 /var/log/nginx/error.log

Show the first 50 lines of a file

head -n 50 /etc/passwd

Search a directory recursively with line numbers

grep -rn "server_name" /etc/nginx

Locate a command and show its version

which nginx && nginx -v

Permissions & Users

Set mode 755: owner read/write/execute, others read/execute

chmod 755 /opt/app/start.sh

Apply permissions recursively to a directory

chmod -R 775 /var/www/html

Change owner and group recursively

chown -R www-data:www-data /var/www

Create a user with a home directory and bash shell

useradd -m -s /bin/bash deploy

Change the password of a user

passwd deploy

Show current UID, GID and group memberships

id

Processes & System

Show running processes matching a keyword

ps aux | grep nginx

Print a one-shot snapshot of top CPU/memory processes

top -b -n 1 | head -n 20
Risky

Gracefully terminate a process; -9 forces a kill and may lose data

kill -15 12345

Check service status and recent log lines

systemctl status nginx

Enable at boot and start the service now

systemctl enable --now nginx

Follow the last hour of logs for a service

journalctl -u nginx -f --since "1 hour ago"

Show memory and swap usage

free -h

Show disk usage and filesystem types

df -hT

Show uptime and load average

uptime

Network & Transfer

Show network interfaces and IP addresses

ip addr

List listening TCP/UDP ports with processes

ss -tunlp

Send 4 ICMP packets to test connectivity

ping -c 4 8.8.8.8

Fetch response headers only to check availability

curl -I https://example.com

Copy a directory over SSH recursively

scp -r /data/dist deploy@10.0.0.12:/opt/app

Log in to a remote host on a specific port

ssh -p 22 deploy@10.0.0.12

Compression & Archive

Create a gzip-compressed tarball

tar -czf app.tar.gz /opt/app

Extract into a target directory

tar -xzf app.tar.gz -C /opt

List archive contents without extracting

tar -tzf app.tar.gz | head

Create a zip archive for Windows compatibility

zip -r app.zip /opt/app

This website uses cookies to ensure you get the best experience on our website. Privacy Policy.