linux command reference

This reference provides an overview of essential Linux commands for file management, process control, networking, system information, and more. It serves as a quick guide for both beginners and experienced users.

tip: this page is dense—use your browser search for keywords like “networking”, “systemctl”, “journalctl”, “/etc/fstab”, “usb devices”, “new disk”, “burning cd/dvd” to jump fast.

jump to

files permissions processes networking usb interfaces system info packages archive users disk fstab systemctl journalctl shutdown env text pipes back to top

file and directory commands

Command Description
ls List files and directories.
cd <directory> Change the current directory.
pwd Print the current working directory.
mkdir <directory> Create a new directory.
rmdir <directory> Remove an empty directory.
rm <file> Delete a file.
rm -r <directory> Recursively delete a directory and its contents.
cp <source> <destination> Copy files or directories.
mv <source> <destination> Move or rename files or directories.
touch <file> Create an empty file or update the timestamp.
cat <file> Display the contents of a file.
less <file> View the contents of a file one page at a time.
head <file> Display the first lines of a file.
tail <file> Display the last lines of a file.
find <path> -name <pattern> Search for files and directories by name.
grep <pattern> <file> Search for patterns within files.

file permissions and ownership

Command Description
chmod <permissions> <file> Change the permissions of a file or directory.
chown <owner> <file> Change the owner of a file or directory.
chgrp <group> <file> Change the group ownership.
umask <mask> Set default file creation permissions.

process management

Command Description
ps Display information about running processes.
top Display real-time system statistics.
htop An enhanced version of top (may require installation).
kill <PID> Terminate a process by its PID.
killall <process_name> Terminate all processes with the given name.
bg Resume a suspended job in the background.
fg Bring a background job to the foreground.
jobs List current jobs.
nice -n <priority> <command> Start a process with a given priority.
renice <priority> -p <PID> Change the priority of an existing process.

networking commands

CommandDescription
ip addr · ip linkShow interfaces, state, and MAC addresses.
ip addr add 192.0.2.10/24 dev eth0Add an address temporarily.
ip link set eth0 up|downBring interface up/down.
ip route · ip route add default via 192.0.2.1Show / set routes.
ss -tulnpList listening sockets with PIDs (modern netstat).
ping -c 4 hostConnectivity test.
traceroute host · mtr -rw hostPath / loss diagnostics.
dig +short A example.comQuick DNS lookup.
nslookup example.comInteractive DNS queries.
ethtool eth0Link speed/duplex; driver info.
tcpdump -ni eth0 port 443Packet capture on interface/port.
nmcli dev statusNetworkManager overview (desktop servers).
firewall-cmd --list-allFirewalld zones/services (RHEL/Fedora).
nft list rulesetShow nftables rules.
curl -I https://example.comCheck HTTP(S) headers.
scp src user@host:/dst/Copy files over SSH.

usb devices

CommandDescription
lsusbList USB buses/devices (IDs, vendor, product).
lsusb -tTree view with speeds and drivers.
dmesg | tailRecent kernel messages when a device is plugged.
usb-devicesVerbose info including driver/module bindings.
udevadm info -q all -n /dev/ttyUSB0Attributes for a given node.

configure interfaces

# Temporary (until reboot)
ip addr add 192.0.2.10/24 dev eth0
ip link set eth0 up
ip route add default via 192.0.2.1

# Debian/Ubuntu classic (/etc/network/interfaces)
auto eth0
iface eth0 inet static
  address 192.0.2.10/24
  gateway 192.0.2.1
  dns-nameservers 1.1.1.1 9.9.9.9

# Netplan (Ubuntu 22.04+, /etc/netplan/01-net.yaml)
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: false
      addresses: [192.0.2.10/24]
      gateway4: 192.0.2.1
      nameservers:
        addresses: [1.1.1.1, 9.9.9.9]
# apply: netplan apply

# RHEL/CentOS ifcfg (/etc/sysconfig/network-scripts/ifcfg-eth0)
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.0.2.10
PREFIX=24
GATEWAY=192.0.2.1
DNS1=1.1.1.1
DNS2=9.9.9.9
# restart: nmcli con reload && nmcli con up eth0

# systemd-networkd (/etc/systemd/network/10-eth0.network)
[Match]
Name=eth0
[Network]
Address=192.0.2.10/24
Gateway=192.0.2.1
DNS=1.1.1.1 9.9.9.9
# reload: systemctl restart systemd-networkd

system information

Command Description
uname -a Display system information.
df -h Show disk space usage.
du -sh <directory> Estimate file space usage.
free -h Display memory usage.
uptime Show how long the system has been running.
who Show who is logged on.
last Show last logged in users.
history Show command history.
man <command> Display the manual page for a command.
info <command> Display info documentation.

package management

Debian/Ubuntu-based Systems (using apt):

Command Description
sudo apt update Update package index.
sudo apt upgrade Upgrade installed packages.
sudo apt install <package> Install a package.
sudo apt remove <package> Remove a package.
sudo apt search <package> Search for a package.

Red Hat/CentOS-based Systems (using yum or dnf):

Command Description
sudo yum update Update packages.
sudo yum install <package> Install a package.
sudo yum remove <package> Remove a package.
sudo yum search <package> Search for a package.

compression and archiving

Command Description
tar -cvf archive.tar <files> Create a tar archive.
tar -xvf archive.tar Extract a tar archive.
tar -zcvf archive.tar.gz <files> Create a compressed tar archive with gzip.
tar -zxvf archive.tar.gz Extract a gzip compressed tar archive.
zip archive.zip <files> Create a zip archive.
unzip archive.zip Extract a zip archive.
gzip <file> Compress a file with gzip.
gunzip <file.gz> Decompress a gzip file.

user and group management

Command Description
sudo adduser <username> Add a new user.
sudo passwd <username> Change a user's password.
sudo deluser <username> Delete a user.
sudo addgroup <groupname> Add a new group.
sudo delgroup <groupname> Delete a group.
sudo usermod -aG <group> <username> Add a user to a group.
id <username> Display user identity.

disk management

Command Description
fdisk -l List disk partitions.
mount <device> <mount_point> Mount a filesystem.
umount <mount_point> Unmount a filesystem.
df -h Report filesystem disk space usage.
du -sh <directory> Estimate file space usage.
fsck <device> Check and repair a filesystem.

provision a new disk (quick flow)

# 1) Identify the disk
lsblk -fp           # shows devices, fs type, UUIDs

# 2) Partition (example: GPT, one partition)
sudo parted /dev/sdb -- mklabel gpt
sudo parted /dev/sdb -- mkpart primary ext4 0% 100%

# 3) Make filesystem
sudo mkfs.ext4 /dev/sdb1

# 4) Mount temporarily
sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data

# 5) Add to /etc/fstab (use UUID for stability)
UUID=$(blkid -s UUID -o value /dev/sdb1)
echo \"UUID=${UUID}  /mnt/data  ext4  defaults  0 2\" | sudo tee -a /etc/fstab
sudo mount -a   # verify fstab works

# 6) Permissions example
sudo chown -R $USER:$USER /mnt/data

/etc/fstab examples

# UUID recommended for stable devices
UUID=1111-2222  /           ext4  defaults              0 1

# NFS
192.0.2.20:/export/media  /mnt/media  nfs4  rw,_netdev,hard,intr  0 0

# SMB/CIFS (needs cifs-utils)
//fileserver/share  /mnt/share  cifs  credentials=/root/.smbcred,iocharset=utf8,vers=3.0,_netdev  0 0
# /root/.smbcred:
# username=alice
# password=secret
# domain=WORKGROUP

# tmpfs (RAM disk)
tmpfs  /mnt/ramdisk  tmpfs  size=1G,noexec,nodev,nosuid  0 0

# Bind mount
/var/log  /mnt/logcopy  none  bind  0 0

burning cd/dvd images

# Create ISO from folder
genisoimage -o image.iso -R -J /path/to/folder

# Verify ISO checksum
sha256sum image.iso

# Burn ISO to CD/DVD (wodim/growisofs)
wodim -v dev=/dev/sr0 speed=8 image.iso
# or for DVD/BD:
growisofs -dvd-compat -Z /dev/sr0=image.iso

# Erase rewritable media
wodim dev=/dev/sr0 blank=fast

# Verify disc
dd if=/dev/sr0 bs=1M | sha256sum

systemctl cheats

CommandDescription
sudo systemctl status nginxService status + last logs.
sudo systemctl start|stop|restart nginxControl service.
sudo systemctl enable --now nginxEnable at boot and start immediately.
sudo systemctl disable nginxDisable at boot.
sudo systemctl reload nginxReload config without restart.
sudo systemctl daemon-reloadPick up changed unit files.
systemctl list-units --type=service --state=failedFind failed services (no sudo needed).
systemctl list-timers --allSee systemd timers and next run time.

journalctl

CommandDescription
sudo journalctl -u nginxLogs for a unit (oldest→newest).
sudo journalctl -u nginx -eJump to end of logs.
sudo journalctl -u nginx -fFollow (tail) logs.
sudo journalctl -u nginx --since \"1 hour ago\"Filter by time.
journalctl -b -1Logs from previous boot.

system control and shutdown

CommandDescription
sudo shutdown -h nowShutdown immediately.
sudo shutdown -r nowReboot immediately.
sudo rebootReboot shorthand.

environment variables and shell

Command Description
echo $VARIABLE Display the value of an environment variable.
export VARIABLE=value Set or modify an environment variable.
alias <name>='<command>' Create a shell alias.
unalias <name> Remove a shell alias.
env Display all environment variables.

text processing

Command Description
grep <pattern> <file> Search for a pattern in files.
sed 's/old/new/g' <file> Replace text in a file using stream editor.
awk '/pattern/ {action}' <file> Pattern scanning and processing language.
sort <file> Sort lines of text files.
uniq <file> Report or filter out repeated lines.
diff <file1> <file2> Compare files line by line.
wc <file> Print newline, word, and byte counts.
tee <file> Read from standard input and write to standard output and files.

redirection and pipes

Use redirection and pipes to control input and output:

examples

# Redirect output to a file
ls -l > filelist.txt

# Append output to a file
echo "New line" >> file.txt

# Redirect error messages to a file
command 2> error.log

# Pipe output to another command
ps aux | grep apache

# Suppress output
command > /dev/null 2>&1

Return to Home