System Management

System Management

These commands help you manage and monitor system resources, services, and system-level operations.

systemctl

Controls the systemd system and service manager, which is the foundation of most modern Linux distributions.

systemctl [options] command [unit]

Common commands:

Examples:

# Check status of a service
systemctl status nginx

# Start a service
sudo systemctl start nginx

# Enable a service to start at boot
sudo systemctl enable nginx

# Restart a service
sudo systemctl restart nginx

# List all active services
systemctl list-units --type=service --state=active

journalctl

Queries the systemd journal, which contains logs from the system and services.

journalctl [options]

Options:

Examples:

# View system logs
journalctl

# Follow logs in real-time
journalctl -f

# View logs for a specific service
journalctl -u nginx

# View recent logs
journalctl -n 100

# View logs from today
journalctl --since "today"

# View logs with errors and critical issues only
journalctl -p err..crit

df

Reports file system disk space usage.

df [options] [file]

Options:

Examples:

# Show disk space in human-readable format
df -h

# Show file system types along with usage
df -hT

# Show inode usage
df -i

free

Displays amount of free and used memory in the system.

free [options]

Options:

Examples:

# Show memory usage in human-readable format
free -h

# Show memory usage updated every 2 seconds
free -h -s 2

top

Displays real-time view of system processes.

top [options]

Options:

Interactive commands:

Examples:

# Start top with 3-second refresh
top -d 3

# Show only processes from a specific user
top -u username

htop

An interactive process viewer, more user-friendly than top.

htop [options]

Options:

Interactive commands:

Examples:

# Start htop filtering for root user
htop -u root

reboot

Restarts the system.

reboot [options]

Options:

Examples:

# Reboot the system
sudo reboot

# Force reboot
sudo reboot --force

poweroff

Shuts down the system.

poweroff [options]

Options:

Examples:

# Shutdown the system
sudo poweroff

# Force shutdown
sudo poweroff --force

shutdown

Shuts down or restarts the system.

shutdown [options] [time] [message]

Options:

Examples:

# Shutdown immediately
sudo shutdown now

# Reboot in 5 minutes with a message
sudo shutdown -r +5 "System maintenance"

# Schedule a shutdown at a specific time
sudo shutdown -h 23:30

# Cancel a scheduled shutdown
sudo shutdown -c

dmesg

Displays kernel ring buffer messages.

dmesg [options]

Options:

Examples:

# Show kernel messages with readable timestamps
dmesg -HT

# Show only error messages
dmesg --level=err

# Follow new kernel messages
dmesg -w

uname

Prints basic system information.

uname [options]

Options:

Examples:

# Show all system information
uname -a

# Show only kernel version
uname -r

# Show machine architecture
uname -m

lsblk

Lists information about block devices.

lsblk [options]

Options:

Examples:

# List all block devices with basic info
lsblk

# Show filesystem information
lsblk -f

# Show full paths with size and type
lsblk -po NAME,SIZE,TYPE

blkid

Locates/prints block device attributes.

blkid [options] [device]

Options:

Examples:

# Show all block devices with attributes
sudo blkid

# Find device with specific UUID
sudo blkid -U "a1b2c3d4-e5f6-7890-abcd-1234567890ab"

lsof

Lists open files.

lsof [options]

Options:

Examples:

# Show all open files
sudo lsof

# Show all open network connections
sudo lsof -i

# Show files opened by a specific user
sudo lsof -u username

# Show all files opened by a process
sudo lsof -p 1234

# Show which process is using a specific port
sudo lsof -i :80

mount/umount

Mounts/unmounts filesystems.

mount [options] [device] [directory]
umount [options] [device|directory]

Options (mount):

Options (umount):

Examples:

# Mount a device to a directory
sudo mount /dev/sdb1 /mnt/usb

# Mount with specific filesystem type and options
sudo mount -t ext4 -o rw,noatime /dev/sda2 /home

# Unmount a filesystem
sudo umount /mnt/usb

# Force unmount when device is busy
sudo umount -f /mnt/usb

fdisk

Manipulates disk partition table.

fdisk [options] [device]

Options:

Interactive commands:

Examples:

# List all partitions
sudo fdisk -l

# Manipulate partitions on a specific disk
sudo fdisk /dev/sdb

mkfs

Creates a filesystem on a device or partition.

mkfs [options] -t [fstype] [device]

Common filesystem types:

Examples:

# Create an ext4 filesystem
sudo mkfs -t ext4 /dev/sdb1

# Create an XFS filesystem
sudo mkfs.xfs /dev/sdc1

# Create a FAT32 filesystem (for USB drives)
sudo mkfs.vfat -F 32 /dev/sdd1

dd

Copies and converts files, often used for disk images.

dd [options] operand

Common operands:

Examples:

# Create a disk image
sudo dd if=/dev/sda of=disk.img bs=4M status=progress

# Write an ISO to a USB drive
sudo dd if=ubuntu.iso of=/dev/sdb bs=4M status=progress

# Wipe a disk with zeros
sudo dd if=/dev/zero of=/dev/sdc bs=1M count=1000

timedatectl

Controls the system time and date.

timedatectl [command]

Commands:

Examples:

# Show current time settings