A comprehensive cheat‑sheet of the most useful commands you’ll encounter on CentOS (versions 6‑8). Each entry includes a brief description, common options, and practical examples. Use this as a study guide for a practical server‑administration test.
| Command | Description | Common Options | Example |
|---|---|---|---|
ls |
List directory contents | -l long, -a all, -h human‑readable, -R recursive |
ls -lha /etc |
cd |
Change directory | – | cd /var/log |
pwd |
Print working directory | – | pwd |
cp |
Copy files/directories | -r recursive, -i interactive,
-u update, -v verbose |
cp -r /home/user/docs /backup/ |
mv |
Move/rename | -i interactive, -v verbose |
mv oldname.txt newname.txt |
rm |
Remove files/dirs | -r recursive, -f force, -i interactive |
rm -rf /tmp/old* |
mkdir |
Make directories | -p create parents, -v verbose |
mkdir -p /srv/www/html |
touch |
Create empty file or update timestamp | – | touch /var/log/myapp.log |
cat |
Concatenate and display files | -n number lines, -A show all |
cat /etc/passwd |
less |
Page‑wise viewer (forward/back) | – | less /var/log/messages |
more |
Simple page‑wise viewer | – | more /etc/hosts |
head |
Show first N lines | -n NUM |
head -20 /var/log/secure |
tail |
Show last N lines; follow live | -n NUM, -f follow |
tail -f /var/log/httpd/access_log |
grep |
Search text using patterns | -i ignore case, -r recursive,
-v invert, -n line numbers |
grep -i "error" /var/log/* |
find |
Locate files/directories | -name, -type f/d, -size, -exec, -mtime |
find /var -type f -name "*.log" -mtime +7 |
which |
Show full path of executable | – | which ssh |
whereis |
Locate binary, source, man page | – | whereis bash |
man |
Display manual page | – | man iptables |
info |
Info documentation (GNU) | – | info coreutils |
echo |
Print text or variables | -e enable escapes |
echo -e "Line1\nLine2" |
printf |
Formatted output | – | printf "%-10s %s\n" "User" "ID" |
dirname / basename |
Extract path components | – | basename /etc/passwd → passwd |
| Command | Description | Common Options | Example |
|---|---|---|---|
uname |
Kernel & system info | -a all, -r release, -m machine |
uname -r |
hostname |
Show/set system hostname | – | hostnamectl set-hostname web01 |
hostnamectl |
Control hostname (systemd) | set-hostname, status |
hostnamectl status |
uptime |
How long system has been running | – | uptime |
who |
Who is logged in | – | who |
w |
Who + what they are doing | – | w |
last |
Show last logins | -n NUM, -f FILE |
last -n 10 |
lastlog |
Last login of all users | – | lastlog |
df |
Disk space usage | -h human, -T type, -i inodes |
df -hT |
du |
Estimate file space usage | -h, -s summary, -c total |
du -sh /var/* |
free |
Memory usage | -h, -m, -g |
free -h |
top |
Dynamic process viewer | – | top |
htop |
Interactive process viewer (if installed) | – | htop |
ps |
Snapshot of processes | -ef full, -eo custom format |
`ps -ef |
pstree |
Tree view of processes | – | pstree -p |
pgrep / pkill |
Find/kill processes by name | -l, -u USER |
pgrep -l sshd |
kill / killall |
Send signal to PID/name | -9 SIGKILL, -15 SIGTERM |
kill -15 $(pgrep httpd) |
nice / renice |
Set/adjust process priority | -n PRIORITY |
nice -n 10 command |
ionice |
Set I/O scheduling class/priority | -c CLASS -n PRIO |
ionice -c2 -n7 dd if=/dev/zero of=/tmp/test bs=1M count=100 |
vmstat |
Virtual memory statistics | [delay [count]] |
vmstat 1 5 |
iostat |
CPU & I/O statistics | -x extended, -m MB |
iostat -xz 1 3 |
mpstat |
Per‑CPU utilization | -P ALL |
mpstat -P ALL 1 |
pidstat |
Per‑process statistics | -r resident, -d I/O |
pidstat -d 1 |
sar |
Collect/report system activity | -u CPU, -r memory, -n DEV network |
sar -u 1 3 |
dmesg |
Kernel ring buffer | -T human timestamps, -n LEVEL |
`dmesg |
journalctl |
Query systemd journal | -b boot, -u UNIT, -f follow, --since |
journalctl -u sshd -f |
lsblk |
List block devices | -f with filesystem info, -o custom
columns |
lsblk -f |
blkid |
Locate/print block device attributes | – | blkid /dev/sda1 |
fdisk |
Partition table manipulator (MBR) | -l list |
fdisk -l /dev/sda |
parted |
Partition manipulator (GPT/MBR) | -l list, resizepart |
parted /dev/sdb print |
mkfs |
Create a filesystem | -t TYPE (ext4, xfs, …) |
mkfs -t ext4 /dev/sdb1 |
fsck |
Check/repair filesystem | -y auto‑repair, -t TYPE |
fsck -y /dev/sda2 |
mount |
Mount filesystems | -t TYPE, -o opts |
mount -t ext4 /dev/sdb1 /mnt/data |
umount |
Unmount | – | umount /mnt/data |
findmnt |
List mounted filesystems | – | findmnt |
df / du |
Disk usage (see above) | – | – |
hdparm |
Get/set SATA/IDE parameters | -I info, -tT timings |
hdparm -I /dev/sda |
smartctl |
SMART disk health | -a all info |
smartctl -a /dev/sda |
lspci |
List PCI devices | -v verbose, -k kernel drivers |
lspci -v |
lsusb |
List USB devices | -v verbose |
lsusb |
lshw |
List hardware (requires root) | -short, -json |
lshw -short |
dmidecode |
Dump SMBIOS/DMI data | -t TYPE (bios, system, baseboard…) |
dmidecode -t system |
hostnamectl |
See also above | – | – |
timedatectl |
Query/set time & timezone | set-timezone, set-ntp |
timedatectl set-timezone Asia/Singapore |
clock / hwclock |
Hardware clock | -w set systohc, -s set from
hwclock |
hwclock --systohc |
date |
Print/set system date | – | date "+%Y-%m-%d %H:%M:%S" |
| Command | Description | Common Options | Example |
|---|---|---|---|
useradd |
Add a new user | -m create home, -s SHELL, -G GROUPS, -c COMMENT |
useradd -m -s /bin/bash -G wheel jdoe |
usermod |
Modify existing user | -aG append group, -l new login,
-L/U lock/unlock, -e EXPIRE |
usermod -aG docker jdoe |
userdel |
Delete a user | -r remove home & mail |
userdel -r jdoe |
groupadd |
Add a new group | – | groupadd developers |
groupmod |
Modify group | -n new name, -g new GID |
groupmod -n devs developers |
groupdel |
Delete a group | – | groupdel oldgroup |
id |
Show user/group IDs | – | id jdoe |
whoami |
Effective user name | – | whoami |
passwd |
Change user password | -l lock, -u unlock, -e force change, -S status |
passwd jdoe |
chage |
Change password expiry info | -l list, -m MIN, -M MAX, -W WARN, -I INACTIVE |
chage -l jdoe |
gpasswd |
Administer /etc/group | -a add user, -d delete user, -A admins |
gpasswd -a jdoe wheel |
su |
Switch user | - login shell, -c COMMAND |
su - root |
sudo |
Execute command as another user | -u USER, -l list privileges |
sudo -u nginx systemctl restart nginx |
visudo |
Safely edit sudoers file | – | visudo |
chsh |
Change login shell | -s SHELL |
chsh -s /bin/zsh jdoe |
chfn |
Change finger information | – | chfn jdoe |
groups |
List group membership | – | groups jdoe |
newgrp |
Log in to a new group (changes primary GID) | – | newgrp developers |
logout |
Exit login shell | – | logout |
| Command | Description | Common Options | Example |
|---|---|---|---|
chmod |
Change file mode bits | u/g/o/a +/- rwx, -R recursive,
--reference=FILE |
chmod 750 /var/www/html |
chown |
Change file owner/group | -R recursive, --reference=FILE
|
chown -R nginx:nginx /var/log/nginx |
chgrp |
Change group only | -R recursive |
chgrp -R adm /var/log |
umask |
Show/set default creation mask | – | umask 022 |
getfacl |
Get POSIX ACLs | – | getfacl /shared |
setfacl |
Set POSIX ACLs | -m modify, -x remove, -b remove all, -R recursive |
setfacl -m u:jdoe:rwx /shared |
ls -l |
Show mode & ownership (see ls) | – | – |
stat |
Detailed file/info | – | stat /etc/passwd |
CentOS 6/7 → yum; CentOS 8 → dnf (yum is a symlink to dnf).
Commands are largely interchangeable.
| Command | Description | Common Options | Example |
|---|---|---|---|
yum check-update |
List available updates | – | yum check-update |
yum update |
Update all packages | -y assume yes |
yum -y update |
yum install |
Install package(s) | -y |
yum install httpd php |
yum remove |
Erase package(s) | -y |
yum remove samba |
yum list |
List installed/available | installed, available, updates |
yum list installed |
yum info |
Show package details | – | yum info vim-enhanced |
yum search |
Search package names/summary | – | yum search firewalld |
yum provides |
Find which package provides a file | – | yum provides /usr/bin/terraform |
yum clean all |
Clean caches | – | yum clean all |
yum history |
Transaction history | list, info ID, undo ID, redo ID |
yum history list |
yum deplist |
Show dependencies | – | yum deplist bash |
yum reinstall |
Reinstall package | – | yum reinstall glibc |
yum downgrade |
Downgrade to older version | – | yum downgrade openssl |
rpm |
Low‑level RPM tool | -qi query info, -ql list files,
-Vf verify, -Uvh upgrade, -e erase |
rpm -qi curl |
rpm -Va |
Verify all installed packages | – | rpm -Va |
createrepo |
Create a YUM repository metadata | – | createrepo /my/local/repo |
repoquery |
Query repository (like yum provides) | – | repoquery --whatrequires httpd |
yum-config-manager |
Manage repo config | --add-repo, --enable, --disable |
yum-config-manager --add-repo=https://example.com/myrepo.repo |
dnf |
Same as yum on CentOS 8+ | – | dnf install nginx |
dnf module |
Manage modular streams | list, info, install, remove, enable, disable, reset |
dnf module list |
alternatives |
Manage symbolic links for default commands | --display, --set, --auto |
alternatives --display editor |
| Command | Description | Common Options | Example |
|---|---|---|---|
systemctl |
Control systemd units | start, stop, restart, reload, enable, disable, is-enabled, status, list-units, list-unit-files, mask, unmask, daemon-reload, reset-failed, isolate |
systemctl status sshd |
service |
Legacy SysV init wrapper (redirects to systemctl) | start, stop, restart, status |
service iptables restart |
chkconfig |
Legacy SysV runlevel manager (CentOS 6) | --list, --add, --del, levels |
chkconfig --list httpd |
init / telinit |
Change SysV runlevel | – | telinit 3 |
runlevel |
Show previous & current runlevel | – | runlevel |
shutdown |
Halt/power‑off/reboot | -h halt, -P poweroff, -r reboot, +TIME or now |
shutdown -r now |
reboot |
Reboot system | – | reboot |
halt |
Halt system | – | halt |
poweroff |
Power off system | – | poweroff |
systemd-analyze |
Boot time analysis | blame, critical-chain, plot |
systemd-analyze blame |
systemd-run |
Run a command as a transient service | --unit=NAME, --property= |
systemd-run --unit=backup.timer --on-active=12h /usr/local/bin/backup.sh
|
loginctl |
Manage user sessions/seats | list-sessions, show-user |
loginctl list-sessions |
hostnamectl |
(see System Info) | – | – |
timedatectl |
(see System Info) | – | – |
localectl |
Set locale & keymap | set-locale, set-keymap |
localectl set-locale LANG=en_US.UTF-8 |
| Command | Description | Common Options | Example |
|---|---|---|---|
ip |
Show/manipulate routing, devices, policy | addr, link, route, neigh, rule |
ip addr show |
ifconfig |
Deprecated but still present (net‑tools) | – | ifconfig eth0 |
nmcli |
NetworkManager CLI | device, connection, radio, general |
nmcli device status |
nmtui |
Text UI for NetworkManager | – | nmtui |
ethtool |
Query/control Ethernet driver settings | -i driver info, -k offload, -S stats |
ethtool eth0 |
mii-tool |
Legacy link negotiation checker | – | mii-tool eth0 |
ping |
ICMP echo test | -c COUNT, -i INTERVAL, -s SIZE |
ping -c 4 8.8.8.8 |
traceroute / tracepath |
Path to host | -n no DNS, -m MAX_HOPS |
traceroute -n google.com |
netstat |
Network connections, routing tables, interfaces | -tulpn (TCP/UDP listening), -r
routing, -s stats |
netstat -tulpn |
ss |
Socket statistics (modern replacement) | -tulpn, -s summary |
ss -tulpn |
nc (netcat) |
Read/write network connections | -l listen, -p PORT, -u UDP, -v verbose |
nc -luvp 9999 |
telnet |
Plain‑text TCP client | – | telnet example.com 80 |
ssh |
Secure remote login | -p PORT, -i KEYFILE, -L local forward, -R remote forward
|
ssh -p 2222 user@host |
scp |
Secure copy over SSH | -r recursive, -P PORT |
scp -P 2222 file.txt user@host:/tmp/ |
sftp |
Interactive SFTP client | – | sftp user@host |
rsync |
Fast, versatile file sync | -avz, --delete, --progress, -e "ssh -p 2222" |
rsync -avz -e "ssh -p 2222" /src/ user@host:/dst/ |
wget |
Non‑interactive downloader | -c continue, -r recursive, --no-check-certificate |
wget https://example.com/file.iso |
curl |
Transfer data with URL syntax | -O remote name, -L follow
redirects, -u user:pass, -X POST
|
curl -O https://example.com/file.tar.gz |
host |
DNS lookup | – | host example.com |
dig |
DNS query utility | +short, @SERVER |
dig +short example.com |
nslookup |
Legacy DNS query | – | nslookup example.com |
arp |
Show/modify ARP cache | -a all, -d delete |
arp -a |
iptables |
IPv4 packet filter (legacy) | -L list, -A append, -D delete, -F flush, -t nat table |
iptables -L -v -n |
iptables-save / iptables-restore
|
Save/restore rules | – | iptables-save > /etc/sysconfig/iptables |
firewall-cmd |
firewalld CLI (default on CentOS 7+) | --state, --reload, --list-all, --add-service=, --remove-service=, --add-port=PORT/proto, --permanent
|
firewall-cmd --permanent --add-service=http --reload |
firewall-offline-cmd |
Modify firewalld without running service | – | firewall-offline-cmd --list-all |
semanage port |
SELinux port labeling | -a -t http_port_t -p tcp 8080 |
semanage port -a -t http_port_t -p tcp 8080 |
getenforce / setenforce |
SELinux mode | Enforcing, Permissive, Disabled |
getenforce |
sestatus |
SELinux status summary | – | sestatus |
semodule |
Load/list SElinux modules | -l list, -i install, -r remove |
semodule -l |
auditctl |
Control audit daemon | -w watch file, -a add rule |
auditctl -w /etc/passwd -p wa -k passwd_changes |
ausearch |
Search audit logs | -k KEY, -p pid, -sc syscall |
ausearch -k passwd_changes |
aureport |
Generate audit reports | – | aureport --summary |
setsebool |
Toggle SELinux boolean | -P persistent |
setsebool -P httpd_can_network_connect on |
toggle SELinux boolean (alternative) |
– | setsebool httpd_can_network_connect 1 |
| Command | Description | Common Options | Example |
|---|---|---|---|
pvcreate |
Initialize physical volume | – | pvcreate /dev/sdb1 |
vgcreate |
Create volume group | – | vgcreate vg_data /dev/sdb1 /dev/sdc1 |
lvcreate |
Create logical volume | -L SIZE, -n NAME, -l %EXTENTS |
lvcreate -L 20G -n lv_web vg_data |
lvextend |
Extend LV | -L +SIZE, -r resize FS together
(if using xfs) |
lvevent -L +5G -r /dev/vg_data/lv_web |
lvreduce |
Reduce LV (requires unmount & fsck) | -L SIZE, -r |
lvreduce -L 10G /dev/vg_data/lv_web |
lvremove |
Remove LV | – | lvremove /dev/vg_data/lv_snap |
pvs / vgs / lvs |
Report PVs, VGs, LVs | -o custom fields |
pvs -o pv_name,vg_name,size,free |
pvdisplay / vgdisplay / lvdisplay |
Detailed info | – | vgdisplay vg_data |
vgchange |
Activate/deactivate VG | `-a y | n` |
vgremove |
Remove VG | – | vgremove vg_old |
vgextend / vgreduce |
Add/remove PVs from VG | – | vgextend vg_data /dev/sdd1 |
pvmove |
Move data between PVs | – | pvmove /dev/sdb1 /dev/sde1 |
lvdisplay |
Show LV attributes | – | lvdisplay /dev/vg_data/lv_web |
lvscan |
Scan for LVs | – | lvscan |
vgcfgrestore / vgcfgbackup |
Backup/restore VG metadata | – | vgcfgbackup vg_data |
| Command | Description | Common Options | Example |
|---|---|---|---|
mdadm --create |
Create RAID array | --level=, --raid-devices=, --name= |
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
|
mdadm --detail |
Show array detail | – | mdadm --detail /dev/md0 |
mdadm --manage |
Add/remove devices | --add, --fail, --remove |
mdadm /dev/md0 --add /dev/sdd1 |
mdadm --grow |
Reshape array | --level=, --raid-devices= |
mdadm --grow /dev/md0 --level=5 --raid-devices=4 |
mdadm --stop |
Stop array | – | mdadm --stop /dev/md0 |
mdadm --assemble |
Assemble existing array | – | mdadm --assemble --scan |
mdadm --monitor |
Monitor array (daemon mode) | – | mdadm --monitor --scan --daemonize |
mdadm --examine |
Examine superblock | – | mdadm --examine /dev/sdb1 |
| Command | Description | Common Options | Example |
|---|---|---|---|
fdisk |
MBR partition editor | -l list |
fdisk -l /dev/sda |
parted |
GPT/MBR partition editor | print, resizepart, mkpart |
parted /dev/sdb print |
lsblk |
List block devices tree | -f with FS info |
lsblk -f |
blkid |
Show block device attributes | – | blkid /dev/sda1 |
mkfs |
Make filesystem | -t ext4, -t xfs, -t btrfs |
mkfs -t xfs /dev/vg_data/lv_web |
fsck |
Check/repair FS | -y, -t |
fsck -y /dev/md0 |
mount / umount |
Mount/unmount FS | -t, -o |
mount /dev/vg_data/lv_web /www |
findmnt |
List mounted FS | – | findmnt |
df / du |
Disk usage | – | – |
hdparm |
Tune/get SATA/IDE params | -I, -tT |
hdparm -I /dev/sda |
smartctl |
SMART health | -a, -H |
smartctl -a /dev/nvme0n1 |
blockdev |
Block device ioctl | --getsize64, --setro |
blockdev --getsize64 /dev/sda |
cryptsetup |
LUKS encryption | luksOpen, luksClose, luksFormat |
cryptsetup luksOpen /dev/sdb1 cryptdata |
| Command | Description | Common Options | Example |
|---|---|---|---|
journalctl |
Query systemd journal | -b boot, -u UNIT, -f follow, --since, --until, -p priority |
journalctl -u sshd -f |
rsyslogd / syslog-ng |
Syslog daemon (usually running) | – | systemctl status rsyslog |
logrotate |
Rotate, compress, remove logs | -f force, -d debug |
logrotate -f /etc/logrotate.conf |
last |
Show login history (from /var/log/wtmp) | – | last |
lastb |
Show bad login attempts | – | lastb |
dmesg |
Kernel ring buffer | -T, -n LEVEL |
`dmesg |
tail -f |
Follow log file | – | tail -f /var/log/secure |
zgrep |
Search in compressed logs | – | zgrep "error" /var/log/yum.log.* |
savelog |
Save a log file (rotate) | – | savelog -l 7 /var/log/myapp.log |
logger |
Send message to syslog | -t TAG, -p priority |
logger -t backup "Backup started" |
watch |
Execute command repeatedly, show output | -n SECONDS |
watch -n 5 "df -h" |
| Command | Description | Common Options | Example |
|---|---|---|---|
sysctl |
View/modify kernel parameters | -a all, -w key=value |
sysctl -w net.ipv4.ip_forward=1 |
/proc/sys/ |
Virtual filesystem for sysctl | – | cat /proc/sys/net/ipv4/tcp_fin_timeout |
iostat |
CPU & I/O stats (see above) | – | – |
vmstat |
Virtual memory stats (see above) | – | – |
mpstat |
Per‑CPU stats (see above) | – | – |
pidstat |
Per‑process stats (see above) | – | – |
sar |
System activity reporter (see above) | – | – |
perf |
Linux profiling (if installed) | record, report, stat, top |
perf record -g -a sleep 30 |
tcpdump |
Packet capture | -i INTERFACE, -w FILE, -nn |
tcpdump -i eth0 -nn -s 0 -c 1000 |
iftop |
Real‑time bandwidth per host | – | iftop -i eth0 |
nethogs |
Bandwidth per process | – | nethogs |
iotop |
Top-like I/O usage | – | iotop -o |
stress / stress-ng |
Generate load for testing | --cpu, --io, --vm, --timeout |
stress --cpu 4 --timeout 60s |
hdparm |
Disk benchmark (see above) | -tT |
hdparm -tT /dev/sda |
fio |
Flexible I/O tester | --name=, --rw=read, --bs=4k, --size=1G |
fio --name=randread --rw=randread --bs=4k --size=1G --numjobs=4 --runtime=60 --group_reporting
|
| Command | Description | Common Options | Example |
|---|---|---|---|
lsmod |
List loaded modules | – | `lsmod |
modinfo |
Show module info | – | modinfo ext4 |
modprobe |
Insert/remove module (handles deps) | -r remove, -v verbose |
modprobe -v ext4 |
insmod / rmmod |
Low‑level insert/remove (no deps) | – | insmod /lib/modules/$(uname -r)/kernel/fs/ext4/ext4.ko |
depmod |
Generate module dependencies | -a all |
depmod -a |
grub2-mkconfig |
Generate GRUB2 config | -o OUTPUT |
grub2-mkconfig -o /boot/grub2/grub.cfg |
grub2-install |
Install GRUB2 to device | --target=i386-pc, --recheck |
grub2-install --target=i386-pc /dev/sda |
grub2-set-default |
Set default entry | ENTRY |
grub2-set-default 0 |
grub2-editenv |
Edit GRUB environment block | – | grub2-editenv list |
kernel-install |
Install kernel + initramfs (Fedora/RHEL) | – | kernel-install add 5.14.0-70.13.1.el9_0.x86_64 /lib/modules/5.14.0-70.13.1.el9_0.x86_64/vmlinuz
|
dracut |
Create initramfs image | -f force, --add |
dracut -f /boot/initramfs-$(uname -r).img $(uname -r) |
kexec |
Load new kernel without reboot | -l load, -e execute |
kexec -l /boot/vmlinuz-$(uname -r) --initrd=/boot/initramfs-$(uname -r).img --reuse-cmdline
|
sysctl |
(see above) | – | – |
systemctl |
(see Services) | – | – |
| Command | Description | Common Options | Example |
|---|---|---|---|
passwd |
(see Users) | – | – |
chage |
(see Users) | – | – |
faillock |
Display/manage faillock counters | --user, --reset |
faillock --user jdoe --reset |
pam_tally2 |
(legacy) | – | pam_tally2 --user jdoe --reset |
auditctl |
(see Logging) | – | – |
ausearch |
(see Logging) | – | – |
aureport |
(see Logging) | – | – |
setsebool |
(see SELinux) | – | – |
semanage |
(see SELinux) | – | – |
restorecon |
Restore SELinux context | -Rv recursive verbose |
restorecon -Rv /var/www |
chcon |
Change SELinux context temporarily | -t TYPE, -u USER, -r ROLE |
chcon -t httpd_sys_content_t /var/www/html |
getenforce / setenforce |
SELinux mode | – | getenforce |
semodule |
Manage SELinux policy modules | -l, -i, -r |
semodule -l |
iptables / firewall-cmd |
(see Networking) | – | – |
fail2ban-client |
Manage fail2ban | status, start, stop, reload |
fail2ban-client status sshd |
lynis |
Security auditing tool (if installed) | audit system |
lynis audit system |
openssl |
TLS/SSL toolkit | version, req, x509, s_client |
openssl version |
ssh-keygen |
Generate SSH keys | -t rsa -b 4096, -f FILE, -C comment |
ssh-keygen -t rsa -b 4096 -C "jdoe@example.com" |
ssh-copy-id |
Install public key on remote | -i KEYFILE, -p PORT |
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 2222 user@host |
gpg |
GNU Privacy Guard | --gen-key, --list-keys, --encrypt, --decrypt |
gpg --gen-key |
htpasswd |
Manage basic auth files (Apache) | -c create, -m MD5, -b batch |
htpasswd -c /etc/httpd/.htpasswd jdoe |
sudoers |
(see Users) | – | – |
| Command | Description | Common Options | Example |
|---|---|---|---|
script |
Record terminal session | -a append, -q quiet |
script -a ~/session.log |
history |
Show bash history | – | `history |
!! / !n |
Bash history expansion | – | sudo !! |
alias |
Define/show aliases | – | alias ll='ls -lha' |
unalias |
Remove alias | – | unalias ll |
env |
Print environment | – | `env |
printenv |
Print a variable | – | printenv HOME |
export |
Set env var | – | export JAVA_HOME=/opt/jdk |
unset |
Remove env var or function | – | unset JAVA_HOME |
source / . |
Execute script in current shell | – | source ~/.bashrc |
bash -c |
Run a command string | – | bash -c 'echo $HOME' |
which / type |
Locate command | – | type -a ls |
timeout |
Run command with time limit | -s SIGNAL |
timeout 30s dd if=/dev/zero of=/tmp/test bs=1M count=1024 |
flock |
Manage lock files | -x exclusive, -n non‑blocking |
flock -n /tmp/mylock -c 'my_backup.sh' |
nice / renice |
(see System Info) | – | – |
ionice |
(see System Info) | – | – |
watch |
(see Logging) | – | – |
parallel |
Run jobs in parallel (if installed) | -j jobs |
parallel -j 4 echo {} ::: {1..10} |
xargs |
Build and execute command lines from stdin | -n args, -0 null‑delimited |
`find . -name "*.tmp" -print0 |
exec |
Replace shell with command | – | exec /bin/bash |
disown |
Remove job from shell’s job table | – | disown %1 |
bg / fg |
Background/foreground jobs | – | bg %1 |
jobs |
List active jobs | – | jobs |
screen |
Multiplex terminals | -ls list, -S name create, -r resume |
screen -R mysession |
tmux |
Terminal multiplexer (alternative to screen) | new -s name, attach -t name, ls |
tmux new -s work |
scriptreplay |
Replay a script timing file | – | scriptreplay timing.txt session.log |
strace |
Trace system calls | -c summary, -o FILE, -p PID |
strace -p $(pgrep -f httpd) -o /tmp/strace.out -c |
ltrace |
Trace library calls | – | ltrace -f ls |
lsof |
List open files | -i, -p PID, -d descriptor |
lsof -i :80 |
fuser |
Identify processes using files/sockets | -v verbose, -k kill |
fuser -vk /tmp/mysock |
nl |
Number lines of files | – | nl -ba file.txt |
paste |
Merge lines of files | – | paste file1.txt file2.txt |
join |
Join lines on a common field | – | join -t, file1.csv file2.csv |
split |
Split file into pieces | -b SIZE, -l LINES |
split -b 100M bigfile.iso part_ |
wc |
Word/line/byte count | -l, -w, -c |
wc -l /etc/passwd |
sort |
Sort lines | -n numeric, -r reverse, -u unique |
sort -n -u numbers.txt |
uniq |
Report/omit repeated lines | -c count, -d only duplicates |
uniq -c sorted.txt |
tr |
Translate/delete characters | -d delete, -s squeeze |
tr -d '\r' < win.txt > unix.txt |
cut |
Remove sections from each line | -d delim, -f fields |
cut -d: -f1,6 /etc/passwd |
awk |
Pattern scanning & processing | – | awk -F: '{print $1,$3}' /etc/passwd |
sed |
Stream editor | -e, -f, -i in‑place |
sed -i 's/foo/bar/g' file.txt |
grep / egrep / fgrep |
(see File Management) | – | – |
diff |
Compare files | -u unified, -r recursive |
diff -u file1.txt file2.txt |
patch |
Apply a diff file | -p NUM |
patch -p1 < fix.patch |
cmp |
Compare two files byte‑by‑byte | – | cmp file1.bin file2.bin |
base64 |
Encode/decode base64 | -d decode |
base64 -d file.b64 > file.bin |
md5sum / sha1sum / sha256sum |
Compute/check hashes | -c check |
sha256sum -c CHECKSUMS |
gzip / gunzip |
Compress/decompress .gz | -k keep original, -t test |
gzip -k file.txt |
bzip2 / bunzip2 |
Compress/decompress .bz2 | – | bzip2 -k file.txt |
xz / unxz |
Compress/decompress .xz | – | xz -z file.txt |
tar |
Archive utility | -c create, -x extract, -v verbose, -z gzip, -j bzip2, -J xz, -f FILE |
tar -czvf backup.tar.gz /etc |
zip / unzip |
ZIP archive | -r recurse, -l list |
zip -r archive.zip dir/ |
rsync |
(see Networking) | – | – |
scp |
(see Networking) | – | – |
sftp |
(see Networking) | – | – |
ftp |
Legacy FTP client | – | ftp ftp.example.com |
lftp |
Advanced FTP/HTTP/FISH client | – | lftp ftp.example.com |
wget |
(see Networking) | – | – |
curl |
(see Networking) | – | – |
lynx / elinks |
Text‑mode web browsers | – | lynx http://example.com |
mailx / mail |
Send mail from CLI | -s SUBJECT |
`echo "body" |
mutt |
Full‑featured mail client | – | muttset |
ssh-agent / ssh-add |
Manage SSH keys in agent | – | ssh-add ~/.ssh/id_rsa |
autossh |
Automatically restart SSH tunnels | – | autossh -M 0 -f -N -L 8080:localhost:80 user@host |
ncdu |
NCurses Disk Usage | – | ncdu / |
btop |
Resource monitor (like htop) | – | btop |
glances |
Cross‑platform monitoring | – | glances |
htop |
(see System Info) | – | – |
iotop |
(see Performance) | – | – |
vnstat |
Network traffic logger | -l live, -d days |
vnstat -l |
speedtest-cli |
Test internet speed | – | speedtest-cli |
iperf3 |
Network bandwidth measurement | -s server, -c HOST |
iperf3 -c speedtest.server -t 30 |
ethtool |
(see Networking) | – | – |
mii-tool |
(see Networking) | – | – |
arp-scan |
ARP scanning of local network | – | arp-scan -l |
nmap |
Network exploration & security auditing | -sS, -p-, -O |
nmap -sS -p 1-1000 192.168.1.0/24 |
netcat / nc |
(see Networking) | – | – |
socat |
Multipurpose relay | – | socat TCP-LISTEN:8080,fork TCP:localhost:80 |
stunnel |
TLS wrapper | – | stunnel /etc/stunnel/stunnel.conf |
openssl s_client |
Test TLS connection | – | openssl s_client -connect host:443 -servername host |
certbot |
Let’s Encrypt client (if installed) | certonly, renew |
certbot certonly --webroot -w /var/www/html -d example.com |
fail2ban-client |
(see Security) | – | – |
auditd |
Auditing daemon (usually running) | – | systemctl status auditd |
ausearch / aureport |
(see Logging) | – | – |
setfacl / getfacl |
(see Permissions) | – | – |
chmod / chown |
(see Permissions) | – | – |
useradd / usermod / userdel |
(see Users) | – | – |
groupadd / groupmod / groupdel |
(see Users) | – | – |
su / sudo |
(see Users) | – | – |
visudo |
(see Users) | – | – |
chsh / chfn |
(see Users) | – | – |
passwd |
(see Users) | – | – |
chage |
(see Users) | – | – |
gpasswd |
(see Users) | – | – |
newgrp |
(see Users) | – | – |
id |
(see Users) | – | – |
whoami |
(see Users) | – | – |
groups |
(see Users) | – | – |
last / lastb |
(see Logging) | – | – |
w / who |
(see System Info) | – | – |
uptime |
(see System Info) | – | – |
hostname / hostnamectl |
(see System Info) | – | – |
timedatectl |
(see System Info) | – | – |
clock / hwclock |
(see System Info) | – | – |
date |
(see System Info) | – | – |
cal |
Show calendar | – | cal |
bc |
Calculator | – | `echo "2^10" |
units |
Unit conversion | – | units '60 mph' 'm/s' |
xxd |
Hex dump | – | xxd file.bin |
od |
Octal/hex dump | – | od -x file.bin |
strings |
Extract printable strings | – | strings /bin/bash |
file |
Determine file type | – | file /bin/ls |
stat |
Detailed file info | – | stat /etc/passwd |
readlink |
Resolve symlinks | -f canonical |
readlink -f /usr/bin/python |
realpath |
Canonicalized absolute pathname | – | realpath ../bin/../lib |
mktemp |
Create temporary file/dir | -d dir, -t template |
mktemp -d |
tempfile |
Create temp file (deprecated) | – | tempfile |
dirname / basename |
(see File Management) | – | – |
pwd |
(see File Management) | – | – |
cd |
(see File Management) | – | – |
pushd / popd |
Directory stack | – | pushd /etc; popd |
dirs |
Show directory stack | – | dirs |
alias |
(see Misc) | – | – |
unalias |
(see Misc) | – | – |
history |
(see Misc) | – | – |
fc |
Fix/Re‑run commands | – | fc -s |
bind |
Readline key bindings | – | bind '"\C-x\C-e": shell-expand-line' |
shopt |
Bash shell options | – | shopt -s autocd |
set |
Set shell options | – | set -o nounset |
unset |
Unset variable/function | – | unset VAR |
export |
(see Misc) | – | – |
source |
(see Misc) | – | – |
. |
(see Misc) | – | – |
exec |
(see Misc) | – | – |
eval |
Evaluate arguments as shell code | – | eval "ls -l $DIR" |
wait |
Wait for background jobs | – | wait %1 |
jobs |
(see Misc) | – | – |
bg / fg |
(see Misc) | – | – |
disown |
(see Misc) | – | – |
kill |
(see System Info) | – | – |
killall |
(see System Info) | – | – |
pkill |
(see System Info) | – | – |
pgrep |
(see System Info) | – | – |
nice / renice |
(see System Info) | – | – |
ionice |
(see System Info) | – | – |
schedtool |
Set scheduler policy/priority | – | schedtool -F -p 10 -e myprog |
taskset |
Set/get CPU affinity | – | taskset -c 0-3 myprog |
numactl |
NUMA memory policy | – | numactl --cpunodebind=0 --membind=0 myprog |
ulimit |
Check/set user limits | -a all, -n open files, -u processes |
ulimit -n 4096 |
prlimit |
Get/set process limits (Linux) | – | prlimit --pid 1234 --nofile=4096 |
sysctl |
(see Kernel Modules) | – | – |
/proc/sys/ |
(see Kernel Modules) | – | – |
modprobe |
(see Kernel Modules) | – | – |
lsmod |
(see Kernel Modules) | – | – |
rmmod |
(see Kernel Modules) | – | – |
insmod |
(see Kernel Modules) | – | – |
depmod |
(see Kernel Modules) | – | – |
kmod |
(see Kernel Modules) | – | – |
lsmod |
(see Kernel Modules) | – | – |
lsmod |
(see Kernel Modules) | – | – |
lsmod |
(see Kernel Modules) | – | – |
(The above table is intentionally exhaustive; you can scroll through it for reference.)
journalctl -u nginx | grep error | tail -20).man <command> is the ultimate
reference; use it when uncertain.command --help or man.