linux commands

133 commands, each with a one-line explanation. Click a command to copy it, or its title for details.

Commands 133 shown

  • find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null | sort -k5 -rh | head -20

    Find files larger than 100MB sorted by size

  • du -sh /* 2>/dev/null | sort -rh | head -15

    Top 15 largest directories at root level

  • ss -tlnp

    TCP listening ports with PID and process name (modern netstat)

    network

  • ss -tlnp | grep :<port>

    Which process is listening on a specific port

    network · debug

  • ps aux --sort=-%cpu | head -15

    Top 15 processes by CPU consumption

    monitoring

  • ps aux --sort=-%mem | head -15

    Top 15 processes by memory consumption

    monitoring

  • journalctl -u <service> -f --since '10 minutes ago'

    Stream logs for a systemd unit from the last 10 minutes

    logs

  • systemctl status <service> --no-pager -l

    Service status, recent log lines, and active timers

  • tcpdump -i eth0 -nn host <ip> and port 80 -w /tmp/capture.pcap

    Capture specific traffic to a pcap file

    network · debug

  • df -i | sort -k5 -rn

    Show inode usage per filesystem; can cause 'no space' without disk full

  • lsof -p <pid>

    Show all files, sockets, and connections opened by a process

    debug

  • watch -n 2 'kubectl get pods -n <ns>'

    Re-run a command every 2 seconds with diff highlighting

  • nohup ./script.sh > /tmp/out.log 2>&1 &

    Run a script immune to SIGHUP; redirect output to file

  • ssh -L 8080:internal-service:80 user@bastion -N -f

    Forward local port 8080 to an internal host via bastion

    network

  • tar -xzf archive.tar.gz -C /target/dir/

    Extract a gzipped tar archive to a specific directory

  • openssl rand -base64 32

    Cryptographically secure random 32-byte password

    security

  • openssl s_client -connect example.com:443 </dev/null 2>/dev/null | openssl x509 -noout -dates -subject

    Show cert expiry and subject for a live TLS endpoint

    network · security

  • awk '{sum += $3} END {print sum}' file.txt

    Sum the 3rd column of a space-delimited text file

  • sed -i 's/old-string/new-string/g' file.txt

    In-place global string replacement

  • sort file.txt | uniq -c | sort -rn | head -20

    Count and rank duplicate lines in a file

  • lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT,UUID

    Tree of disks, partitions, loop devices with filesystem info

    disk · filesystem

  • blkid

    Print UUID, LABEL, and FSTYPE for all block devices

    disk · filesystem

  • mount -t ext4 /dev/sdb1 /mnt/data

    Mount ext4 partition to /mnt/data

    filesystem

  • findmnt --real

    List all real (non-virtual) mounted filesystems in a tree

    filesystem

  • mount -o remount,rw /

    Remount the root filesystem as read-write (e.g. after rescue boot)

    filesystem

  • fsck -n /dev/sdb1

    Dry-run fsck check (no changes); unmount first for a live fix

    filesystem · debug

  • mkfs.ext4 -L datalabel /dev/sdb1

    Format partition as ext4 with a label

    filesystem · disk

  • resize2fs /dev/sdb1

    Grow ext4 to fill the partition (after partition resize)

    filesystem · disk

  • tune2fs -l /dev/sda1 | grep -E 'Block (count|size)|Mount count|Last mount'

    Show ext2/3/4 metadata: block size, mount count, last mount time

    filesystem

  • du -h --max-depth=2 /var | sort -rh | head -20

    Disk usage of /var up to 2 directory levels deep

    disk

  • df -hT --type=ext4 --type=xfs --type=btrfs

    Show free space only for real filesystems (skip tmpfs/overlay)

    disk

  • fdisk /dev/sdb

    Interactive MBR/GPT partition table editor

    disk · partitions

  • parted /dev/sdb -- mklabel gpt mkpart primary ext4 1MiB 100%

    Create a single GPT partition using the full disk

    disk · partitions

  • pvs && pvdisplay

    List LVM physical volumes with space usage

    lvm · disk

  • vgs && vgdisplay

    List LVM volume groups with free PE

    lvm · disk

  • lvs -o +devices

    List logical volumes with device paths

    lvm · disk

  • lvextend -L +10G /dev/vg0/lv_data && resize2fs /dev/vg0/lv_data

    Extend LVM logical volume by 10G and grow ext4 filesystem online

    lvm · disk · filesystem

  • fallocate -l 2G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile

    Allocate 2G swap file, set permissions, format and enable

    disk · memory

  • swapon --show && free -h

    List active swap spaces and overall memory/swap stats

    memory

  • ip -br a

    Brief list of all interfaces with IPs

    network

  • ip route show table all

    All routing rules including policy routes

    network

  • ip route add 10.0.0.0/8 via 192.168.1.1 dev eth0

    Add a persistent-until-reboot static route

    network

  • ip neigh show

    Neighbour (ARP/NDP) cache with reachability state

    network

  • ip -s link show eth0

    TX/RX bytes, errors, drops for an interface

    network · monitoring

  • dig +short A example.com @8.8.8.8

    Query A records via a specific DNS server

    network · dns

  • dig +short -x 8.8.8.8

    PTR record for an IP address

    network · dns

  • dig +trace example.com

    Follow full DNS resolution chain from root nameservers

    network · dns

  • ss -tnp state established

    All established TCP connections with process info

    network

  • ss -tan | awk 'NR>1{print $1}' | sort | uniq -c | sort -rn

    How many connections are in ESTABLISHED, TIME_WAIT, etc.

    network · monitoring

  • mtr --report --tcp --port 443 example.com

    Combine traceroute and ping; TCP mode to bypass ICMP blocks

    network · debug

  • ping -M do -s 1472 -c 3 8.8.8.8

    Send DF-bit ping of 1500-byte frames to detect MTU issues

    network · debug

  • iptables -L -n -v --line-numbers

    All filter table rules with packet counters and line numbers

    network · security

  • nft list ruleset

    Full nftables ruleset in human-readable form

    network · security

  • iperf3 -c <server_ip> -t 10 -P 4

    Measure TCP throughput with 4 parallel streams for 10 seconds

    network · monitoring

  • iftop -i eth0 -n

    Real-time bandwidth per connection on an interface

    network · monitoring

  • uname -r && uname -a

    Kernel release string and full system info

    kernel

  • dmesg -T --level=err,warn | tail -50

    Last 50 kernel errors/warnings with human-readable timestamps

    kernel · debug

  • lsmod | sort

    All currently loaded kernel modules

    kernel

  • modprobe <module> && lsmod | grep <module>

    Load a module with dependencies and verify

    kernel

  • modinfo <module>

    Module parameters, version, license, and dependencies

    kernel

  • sysctl -a | grep vm.swappiness

    List all kernel parameters; filter by name

    kernel

  • sysctl -w net.ipv4.ip_forward=1

    Enable IP forwarding at runtime (also add to /etc/sysctl.d/)

    kernel · network

  • cat /proc/cmdline

    Parameters passed to the kernel at boot time

    kernel

  • cat /proc/sys/fs/file-nr

    Allocated FDs, free FDs, and system-wide max (file-max)

    kernel · monitoring

  • iostat -xz 2 5

    Extended disk IO stats every 2s, 5 iterations; look for %iowait, await

    disk · monitoring

  • vmstat 1 5

    System-wide CPU, memory, swap, IO stats per second

    memory · monitoring

  • iotop -ao

    Accumulated disk read/write per process (requires root)

    disk · monitoring

  • sar -u -r -d 1 5

    CPU, memory, and disk stats via sysstat (5 samples, 1s interval)

    monitoring

  • strace -f -e trace=network,file -p <pid>

    Trace network and file syscalls of a running process

    debug · monitoring

  • perf stat -e cycles,instructions,cache-misses -- sleep 5

    Hardware CPU counters during a 5-second window

    monitoring · performance

  • lscpu | grep -E 'Model|Socket|Core|Thread|MHz'

    CPU model, socket/core/thread topology, and clock speed

    hardware

  • dmidecode -t memory | grep -E 'Size|Speed|Locator|Type:'

    Physical DIMM slots: size, speed, type (requires root)

    hardware

  • lspci -v | grep -A5 'VGA\|Ethernet\|NVMe'

    Network cards, GPUs, NVMe controllers with driver info

    hardware

  • chattr +i /etc/resolv.conf && lsattr /etc/resolv.conf

    Prevent any user (incl. root) from modifying the file

    filesystem · security

  • lsattr -R /etc/ 2>/dev/null | grep -v '^\-\-\-\-'

    List non-default extended attrs in /etc/

    filesystem

  • getfacl /srv/shared

    Show POSIX ACL entries including owner, group, and extra users

    filesystem · security

  • setfacl -m u:alice:rwx /srv/shared

    Grant alice full access without changing group ownership

    filesystem · security

  • find / -perm /6000 -type f -ls 2>/dev/null

    Locate setuid/setgid executables (security audit)

    security

  • pgrep -la nginx

    List PIDs and full command lines matching a name

  • kill -TERM -$(pgrep -f 'my-app')

    Send SIGTERM to the entire process group

  • renice -n 10 -p <pid>

    Lower priority (nice +10) of a running process

    performance

  • systemd-run --scope -p MemoryMax=512M -p CPUQuota=50% -- ./heavy.sh

    Run a command in a transient systemd scope with resource limits

    performance · cgroups

  • journalctl --since '2024-01-15 10:00' --until '2024-01-15 10:30' -u nginx

    Logs for nginx between two timestamps

    logs

  • journalctl -u <service> -o json | jq '{ts: .REALTIME_TIMESTAMP, msg: .MESSAGE}'

    Structured log export for ingestion into log aggregators

    logs

  • timedatectl status && chronyc tracking

    Clock sync state, offset, and NTP source details

    network

  • systemctl list-timers --all --no-pager

    All timers with last/next trigger times

  • ssh-copy-id -i ~/.ssh/id_ed25519.pub user@host

    Append public key to remote authorized_keys

    ssh

  • rsync -avz --progress --delete src/ user@host:/dest/

    Mirror directory to remote with deletion of extra files

    filesystem

  • shred -vzn 1 /dev/sdb

    One-pass overwrite with zeros + verify (use hdparm ATA for NVMe)

    disk · security

  • smartctl -a /dev/sda | grep -E 'SMART overall|Reallocated|Pending|Uncorrectable'

    SMART overall health and key failure indicators

    disk · monitoring

  • dd if=/dev/zero of=/tmp/testfile bs=1M count=1024 conv=fdatasync

    Write 1GB with forced sync to measure raw write speed

    disk · performance

  • lsns -t net,pid,mnt

    List Linux namespaces for network, PID, and mount isolation

    kernel · containers

  • systemd-cgls

    Tree view of systemd cgroup hierarchy and resource assignments

    kernel · cgroups

  • find /var/log -name '*.log' -exec wc -l {} + | sort -rn | head -20

    Find the biggest log files by line count

    logs

  • tail -f /var/log/syslog /var/log/auth.log

    Stream multiple log files interleaved in one terminal

    logs

  • zgrep -i 'error' /var/log/syslog.*.gz

    grep inside .gz files without manual decompression

    logs

  • logrotate -f /etc/logrotate.conf

    Force log rotation regardless of schedule

    logs

  • for u in $(cut -f1 -d: /etc/passwd); do crontab -l -u $u 2>/dev/null | grep -v '^#' | sed "s|^|$u: |"; done

    Print active cron lines for every user

  • systemd-analyze calendar '*/5 * * * *'

    Parse and show next 5 trigger times for a cron expression

  • command > /tmp/out.log 2> /tmp/err.log

    Split stdout and stderr into separate files

  • command 2>&1 | tee /tmp/all.log

    Redirect stdout+stderr to file and screen simultaneously

  • grep -rl 'old_string' /etc/ | xargs sed -i 's/old_string/new_string/g'

    Find files containing text, then replace in-place

  • awk '{print $1, $3}' /etc/passwd

    Print 1st and 3rd fields of a space-delimited file

  • awk '{sum += $2} END {print sum}' file.txt

    Sum values in column 2 of a text file

  • sed -i '/^#/d' config.conf

    Remove all comment lines starting with #

  • sed -n '/START/,/END/p' file.txt

    Print block of text between START and END markers

  • sort file.txt | uniq -c | sort -rn

    Count occurrences of each unique line

  • who -H && w

    Active user sessions and what they are running

    security

  • last -n 20 | head -25

    Last 20 login records with IP and duration

    security

  • journalctl -u ssh --since '24h ago' | grep 'Failed password' | awk '{print $(NF-3)}' | sort | uniq -c | sort -rn | head -10

    Top source IPs of failed SSH logins in last 24h

    security

  • sudo -l -U <username>

    List sudo rules for a specific user

    security

  • usermod -aG docker,sudo alice

    Append user to multiple groups without removing existing ones

  • cat /proc/<pid>/smaps | awk '/^Size/{sum+=$2} END{print sum/1024" MB"}'

    Total virtual memory size of a process from smaps

    memory · debug

  • grep -E 'HugePages|AnonHugePages|Transparent' /proc/meminfo

    Check if THP / hugepages are used and configured

    memory · kernel

  • echo never > /sys/kernel/mm/transparent_hugepage/enabled

    Disable THP at runtime (fix for Redis, MongoDB latency spikes)

    memory · kernel

  • numactl --hardware

    NUMA nodes, CPU assignment, and memory distribution

    hardware · performance

  • sysctl -w net.core.somaxconn=65535 net.ipv4.tcp_max_syn_backlog=65535

    Increase socket listen backlog for high-connection services

    network · kernel

  • sysctl -w net.core.default_qdisc=fq net.ipv4.tcp_congestion_control=bbr

    Enable Google BBR congestion control for better throughput

    network · kernel · performance

  • ss -ulnp

    All UDP listening sockets with process info

    network

  • taskset -cp 0,1 <pid>

    Pin a running process to specific CPU cores

    performance

  • watch -n1 'cat /proc/interrupts | head -30'

    Per-CPU interrupt counts, updated every second

    hardware · monitoring

  • cat /proc/<pid>/limits

    Hard and soft resource limits for a running process

    debug

  • ulimit -n 1048576 && echo '* soft nofile 1048576 * hard nofile 1048576' >> /etc/security/limits.conf

    Set high FD limit for current session and persist it

    kernel · performance

  • df -i

    Show inode usage per filesystem (important for many small files)

    filesystem · inode · df

  • find / -type f -size +100M 2>/dev/null | sort

    Find files larger than 100MB on the entire filesystem

    filesystem · find · disk

  • cat /proc/$(pgrep myapp)/fd | wc -l

    Count open file descriptors for a running process

    process · fd · proc

  • getenforce

    Show current SELinux enforcement mode

    security · selinux

  • ls /etc/cron.* /var/spool/cron/crontabs/

    List all system and user cron job locations

    cron · scheduling

  • printenv | sort

    Display all environment variables sorted alphabetically

    env · shell

  • iostat -xz 1

    Show extended disk I/O statistics updated every second

    disk · io · iostat

  • pstree -p

    Display process hierarchy with PIDs

    process · pstree

  • sysctl -w net.core.somaxconn=65535

    Increase the maximum connection backlog for sockets

    network · sysctl · tcp · tuning

  • lscpu

    Display CPU architecture and core count information

    cpu · hardware · lscpu