SH

System Info

Bash & Linux · 10 entries

System & Kernel Information

syntax
uname [options]
example
uname -a
uname -r
uname -s
output
Linux web01 5.15.0-94-generic #104-Ubuntu SMP x86_64 GNU/Linux

Note -a shows all info. -r shows kernel release. -s shows kernel name. -m shows architecture (x86_64, aarch64). Useful in scripts that need to detect the OS: if [[ $(uname -s) == 'Darwin' ]]; then ... (macOS) fi.

Disk Space Usage

syntax
df [options] [filesystem]
example
df -h
df -h /
df -hT
output
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sda1      ext4   50G   32G   16G  67% /
/dev/sdb1      xfs   200G  145G   55G  73% /data

Note -h for human-readable sizes. -T shows filesystem type. -i shows inode usage (you can run out of inodes even with free space if you have millions of tiny files). Check df regularly on servers to prevent disk-full outages.

Directory Size

syntax
du [options] [directory]
example
du -sh /var/log/
du -h --max-depth=1 /opt/ | sort -rh
du -sh ~/projects/*
output
2.3G    /var/log/
1.1G    /opt/app
450M    /opt/data
32M     /opt/config

Note -s shows total for each argument (summary). -h is human-readable. --max-depth limits how deep to report. Combining with sort -rh quickly identifies what is consuming the most space.

Memory Usage

syntax
free [options]
example
free -h
output
              total   used   free   shared  buff/cache  available
Mem:          16Gi   5.2Gi  2.1Gi  312Mi    8.7Gi       10Gi
Swap:         4.0Gi  128Mi  3.9Gi

Note -h for human-readable. The 'available' column is the best indicator of how much memory is actually free for applications (it includes reclaimable buffer/cache). Linux aggressively caches, so low 'free' is normal and does not mean you are out of memory. Not available on macOS; use vm_stat instead.

System Uptime & Load

syntax
uptime
example
uptime
output
 14:22:01 up 47 days, 3:15,  2 users,  load average: 0.52, 0.78, 0.65

Note Load averages are for the last 1, 5, and 15 minutes. On a single-core system, a load of 1.0 means it is fully utilized. On a 4-core system, a load of 4.0 is fully utilized. Consistently high load relative to core count indicates the server needs investigation.

Current User Info

syntax
whoami
id [user]
example
whoami
id
id deploy
output
deploy
uid=1000(deploy) gid=1000(deploy) groups=1000(deploy),27(sudo),999(docker)

Note whoami prints just the username. id shows uid, gid, and all group memberships. Useful in scripts to verify you are running as the expected user: if [[ $(whoami) != 'root' ]]; then echo 'Run as root'; exit 1; fi.

Environment Variables

syntax
env
export VAR=value
printenv VAR
example
env | grep PATH
export DATABASE_URL='postgres://user:pass@db:5432/mydb'
printenv HOME
output
/home/deploy

Note env lists all environment variables. export makes a variable available to child processes. Variables set without export are local to the current shell. printenv retrieves a single variable. Avoid putting secrets in environment variables on shared systems; prefer a secrets manager.

Date & Time

syntax
date [+format]
example
date
date '+%Y-%m-%d %H:%M:%S'
date -d '+7 days' '+%Y-%m-%d'
date -u
output
Sat Apr  4 14:22:01 UTC 2026
2026-04-04 14:22:01
2026-04-11

Note Common format tokens: %Y (year), %m (month), %d (day), %H (hour), %M (minute), %S (second), %s (Unix epoch). -d adjusts the date (GNU only; on macOS use -v). -u outputs UTC. Useful for timestamped filenames: backup_$(date +%Y%m%d_%H%M%S).tar.gz.

CPU Information

syntax
lscpu
example
lscpu
output
Architecture:        x86_64
CPU(s):              8
Model name:          Intel(R) Core(TM) i7-10700 @ 2.90GHz
Thread(s) per core:  2
Core(s) per socket:  4

Note Shows CPU architecture, core count, threads, cache sizes, and more. On macOS, use sysctl -n machdep.cpu.brand_string and sysctl -n hw.ncpu instead.

List Block Devices

syntax
lsblk [options]
example
lsblk -f
output
NAME   FSTYPE  LABEL   SIZE MOUNTPOINT
sda                    100G
├─sda1 ext4   root     50G /
├─sda2 swap            4G  [SWAP]
└─sda3 xfs    data    46G  /data

Note -f shows filesystem type, label, UUID, and mount points. Useful for identifying disks before mounting or partitioning. Linux only; on macOS, use diskutil list.