sysadmin.lk
SYSADMIN - NETWORKTOOLSby sysadmin.lk

Basic Linux Commands & Help

A quick-reference cheatsheet of common Linux commands, grouped by category — search or filter to find what you need.

File & Directory

lsls [options] [path]

List directory contents.

ls -lah /var/log
cdcd [path]

Change the current directory.

cd /etc/nginx
pwdpwd

Print the current working directory.

cpcp [options] source dest

Copy files or directories.

cp -r ./site /var/www/site
mvmv source dest

Move or rename a file or directory.

mv old.conf new.conf
rmrm [options] path

Remove files or directories.

rm -rf /tmp/build
mkdirmkdir [-p] path

Create a directory (with -p, create parents as needed).

mkdir -p /srv/app/logs
touchtouch path

Create an empty file, or update its modification time.

touch .env
findfind path -name pattern

Search a directory tree for files matching criteria.

find /var/log -name '*.log' -mtime +7
lnln [-s] target link

Create a hard or (with -s) symbolic link.

ln -s /opt/app/current /opt/app/live
treetree [path]

Show a directory's contents as a tree.

Permissions & Ownership

chmodchmod mode path

Change a file or directory's permissions.

chmod 640 /etc/app/secret.env
chownchown user:group path

Change a file or directory's owner and group.

chown -R www-data:www-data /var/www
umaskumask [mode]

Show or set the default permission mask for new files.

chattrchattr +i path

Change extended file attributes, e.g. making a file immutable.

Process Management

psps [options]

Show running processes.

ps aux | grep nginx
toptop

Live view of running processes and resource usage.

htophtop

Interactive, colorized alternative to top (not installed by default).

killkill [-signal] pid

Send a signal (default TERM) to a process.

kill -9 4821
killallkillall name

Send a signal to all processes matching a name.

killall -HUP nginx
nicenice -n level command

Run a command with an adjusted scheduling priority.

nohupnohup command &

Run a command immune to hangups, so it keeps running after logout.

jobsjobs

List background jobs in the current shell.

bg / fgbg %1 / fg %1

Resume a stopped job in the background or foreground.

Networking

pingping host

Send ICMP echo requests to test reachability.

ping -c 4 1.1.1.1
curlcurl [options] url

Transfer data to/from a URL — the go-to tool for testing HTTP.

curl -I https://example.com
wgetwget url

Download a file from a URL.

ssss [options]

Show socket statistics — the modern replacement for netstat.

ss -tulpn
netstatnetstat [options]

Show network connections, routing tables, and interface stats (legacy).

digdig [@server] name [type]

Query DNS records for a domain.

dig @1.1.1.1 example.com MX
nslookupnslookup name

Query DNS records (simpler, older alternative to dig).

traceroutetraceroute host

Show the network path (hops) to a host.

ipip addr | ip route | ...

Show/manipulate routing, network devices, and addresses.

ip addr show
sshssh user@host

Open a secure shell session on a remote host.

scpscp source user@host:dest

Copy files over SSH.

scp app.tar.gz [email protected]:/srv/releases/
rsyncrsync [options] source dest

Efficiently sync files/directories, locally or over SSH.

rsync -avz ./dist/ deploy@host:/var/www/app/
ncnc host port

Netcat — read/write raw TCP or UDP connections; handy for quick port tests.

Package Management

aptapt install|remove|update|upgrade pkg

Package manager for Debian/Ubuntu.

sudo apt update && sudo apt upgrade
yum / dnfdnf install|remove pkg

Package manager for RHEL/CentOS/Fedora.

dpkgdpkg -i package.deb

Install/query low-level .deb packages directly.

rpmrpm -ivh package.rpm

Install/query low-level .rpm packages directly.

snapsnap install pkg

Install sandboxed snap packages.

Disk & Storage

dfdf -h

Show disk space usage per filesystem.

dudu -sh path

Show disk usage of files/directories.

du -sh /var/log/*
mountmount device path

Mount a filesystem.

umountumount path

Unmount a filesystem.

lsblklsblk

List block devices (disks and partitions) as a tree.

fdiskfdisk -l

Partition a disk, or list partitions with -l.

dddd if=in of=out

Low-level copy of raw data between devices/files — powerful and unforgiving.

User Management

whoamiwhoami

Print the current effective username.

idid [user]

Show a user's UID, GID, and group memberships.

useradduseradd -m username

Create a new user account.

usermodusermod -aG group user

Modify an existing user account, e.g. adding a group.

usermod -aG docker deploy
passwdpasswd [user]

Change a user's password.

susu [-] [user]

Switch to another user's shell.

sudosudo command

Run a command as another user (default root) per /etc/sudoers.

who / wwho

Show who is currently logged in.

Text Processing

grepgrep [options] pattern file

Search text for lines matching a pattern.

grep -ri 'error' /var/log/app.log
sedsed 's/find/replace/' file

Stream editor for filtering and transforming text.

awkawk 'pattern {action}' file

Pattern-scanning and text-processing language.

awk '{print $1}' access.log
catcat file

Print a file's contents to stdout.

lessless file

View a file one screen at a time, scrollable.

head / tailtail -f file

Show the start/end of a file; -f follows new lines as they're written.

tail -f /var/log/syslog
cutcut -d, -f1 file

Extract columns/fields from each line of a file.

sortsort [options] file

Sort lines of text.

uniquniq [options] file

Filter out (or count) repeated adjacent lines — usually piped after sort.

wcwc -l file

Count lines, words, or bytes in a file.

diffdiff fileA fileB

Show differences between two files.

xargscommand | xargs other-command

Build and run commands from piped input.

find . -name '*.tmp' | xargs rm
tartar -czf out.tar.gz dir/

Archive files; -c create, -x extract, -z gzip, -f filename.

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

System Info

unameuname -a

Print system/kernel information.

uptimeuptime

Show how long the system has been running plus load averages.

freefree -h

Show memory and swap usage.

vmstatvmstat [interval]

Report virtual memory, CPU, and I/O statistics.

iostatiostat [interval]

Report CPU and per-device I/O statistics (part of sysstat).

sarsar -A

Collect and report historical system activity (part of sysstat).

dmesgdmesg | tail

Show kernel ring buffer messages — useful for hardware/driver issues.

journalctljournalctl -u service -f

Query and follow the systemd journal (logs).

journalctl -u nginx -f
historyhistory

Show this shell session's command history.

envenv

Show the current environment variables.

systemd / Services

systemctl statussystemctl status service

Show a service's current status.

systemctl start/stopsystemctl start|stop service

Start or stop a systemd service.

sudo systemctl restart nginx
systemctl enablesystemctl enable service

Make a service start automatically on boot.

systemctl daemon-reloadsystemctl daemon-reload

Reload unit files after editing one, before restarting the service.

Archives & Compression

gzip / gunzipgzip file / gunzip file.gz

Compress or decompress a single file.

zip / unzipzip -r out.zip dir/ / unzip out.zip

Create or extract a .zip archive.