Commands for displaying system information.
Displays basic system information.
Option | Description |
---|---|
-a | Display all information |
-s | Display kernel name |
-n | Display network node hostname |
-r | Display kernel release number |
-v | Display kernel version |
-m | Display machine hardware name |
-p | Display processor type |
-o | Display operating system |
Examples:
uname -a
- Display all system informationuname -r
- Display kernel release numberuname -o
- Display operating systemuname -a | awk '{print $3}'
- Extract only the kernel versionecho "Kernel: $(uname -r)"
- Display kernel version in a shell scriptuname -m | grep -q "x86_64" && echo "64-bit system" || echo "32-bit system"
- Determine system architectureuname -a | grep -i "ubuntu"
- Check if system is Ubuntuuname -a > system_info.txt
- Save system information to a fileif [ "$(uname)" = "Linux" ]; then echo "This is Linux"; fi
- Conditional based on OS type
Displays or sets the system's hostname.
Option | Description |
---|---|
-f | Display fully qualified domain name (FQDN) |
-i | Display host's IP address |
-d | Display DNS domain name |
Examples:
hostname
- Display hostnamehostname -f
- Display fully qualified domain namesudo hostname new-hostname
- Temporarily change hostname (reverts after reboot)hostname -I
- Display all IP addresses of the systemhostname | tr '[:lower:]' '[:upper:]'
- Display hostname in uppercaseecho "Current host: $(hostname)"
- Display hostname in a shell scripthostname -i | grep -q "127.0.0.1" && echo "Localhost configuration detected"
- Check for localhost configurationping -c 1 $(hostname)
- Ping your own hostssh user@$(hostname -f)
- SSH to your own host using FQDN
Displays disk space usage of file systems.
Option | Description |
---|---|
-h | Display in human-readable format (KB, MB, GB, etc.) |
-T | Display file system type |
-i | Display inode information |
-a | Display all file systems (including those with 0 size) |
Examples:
df -h
- Display disk usage in human-readable formatdf -h /home
- Display disk usage for a specific mount pointdf -hT
- Display disk usage with file system typesdf -h | grep -v "tmpfs" | sort -k 5 -r
- Exclude temporary file systems and sort by usage percentagedf -h | awk '$5 > "80%" {print $0}'
- Display file systems with usage over 80%df -i | grep -v "tmpfs"
- Display inode usage excluding temporary file systemsdf -h | grep "^/dev" | awk '{total += $2; used += $3} END {print "Total: " total "GB, Used: " used "GB"}'
- Calculate total capacity and usage across all disksdf -h --output=source,size,used,avail,pcent | grep -v "tmpfs"
- Display only specific columnswatch -n 5 "df -h | grep /dev/sda"
- Monitor disk usage every 5 secondsdf -h | mail -s "Disk Usage Report $(date +%F)" admin@example.com
- Email disk usage report
Displays disk usage of directories and files.
Option | Description |
---|---|
-h | Display in human-readable format (KB, MB, GB, etc.) |
-s | Display only total size for specified directory |
-a | Display size of all files and directories |
-c | Display grand total |
--max-depth=N | Display directories only to specified depth |
Examples:
du -h
- Display size of current directory and subdirectoriesdu -sh /home/user
- Display only total size of specified directorydu -h --max-depth=1 /
- Display size of directories directly under rootdu -h --max-depth=1 | sort -hr
- Sort subdirectories by size (largest first)du -h --max-depth=1 | grep "[0-9]G\b"
- Display only directories with size in GBfind . -type f -name "*.log" | xargs du -ch
- Display size of all log files with totaldu -sh /var/* 2>/dev/null | sort -hr | head -n 5
- Display 5 largest directories in /var (ignoring errors)du -h --time /home/user | sort -r
- Display sizes with last modification time, sorted by sizedu -h --exclude="*.bak" --max-depth=2 /home
- Display directory sizes excluding backup filesdu -b | sort -n | awk '{printf "%.3f MB: %s\n", $1/(1024*1024), $2}' | tail
- Display largest directories in MBfor i in /*; do if [ -d "$i" ]; then du -sh "$i"; fi; done | sort -hr
- Display top-level directories sorted by size
Displays system memory usage.
Option | Description |
---|---|
-h | Display in human-readable format (KB, MB, GB, etc.) |
-m | Display in megabytes |
-g | Display in gigabytes |
-t | Display total line |
-s N | Update display every N seconds (continuous monitoring) |
Examples:
free -h
- Display memory usage in human-readable formatfree -m
- Display memory usage in megabytesfree -s 5
- Update memory usage display every 5 secondsfree -m | awk 'NR==2{printf "Memory Usage: %s/%s MB (%.2f%%)\n", $3,$2,$3*100/$2 }'
- Display memory usage percentagefree -m | grep Mem | awk '{print "Used: " $3 "MB, Free: " $4 "MB, Available: " $7 "MB"}'
- Extract used, free, and available memorywatch -n 1 'free -m | grep "Mem\|Swap"'
- Monitor memory and swap usage every secondfree -b | grep "Mem:" | awk '{printf "%.2f GB\n", $2/(1024*1024*1024)}'
- Display total memory in GBfree -m > memory_$(date +%Y%m%d_%H%M%S).log
- Save memory usage to timestamped log filefor i in {1..10}; do free -m | grep Mem; sleep 5; done
- Record memory usage 10 times at 5-second intervalsfree -m | awk '/Mem:/ {print "Memory used: " 100*$3/$2 "%"} /Swap:/ {print "Swap used: " 100*$3/$2 "%"}'
- Display memory and swap usage percentages
Displays CPU architecture information.
Option | Description |
---|---|
-e | Display in extended readable format |
-a | Display both online and offline CPUs |
-J | Output in JSON format |
Examples:
lscpu
- Display CPU informationlscpu -e
- Display CPU information in extended formatlscpu | grep -E "^CPU\(s\)|Core|Socket|Model name"
- Extract key CPU informationlscpu -p | grep -v "^#" | wc -l
- Count available CPU coreslscpu | grep "MHz" | awk '{print $NF " MHz"}'
- Extract CPU frequencylscpu -J | jq
- Display CPU information in formatted JSONlscpu | grep -i cache | sort
- Extract and sort cache informationlscpu -p=CPU,CORE,SOCKET | grep -v "^#"
- Display CPU, core, and socket relationshipslscpu | awk -F: '/Model name/ {print $2}' | sed 's/^ *//'
- Extract CPU model name and remove leading spaceslscpu | grep -i "virt" | grep -i "tech"
- Display virtualization technology information
Displays block devices (hard disks, SSDs, USB drives, etc.) on the system.
Option | Description |
---|---|
-a | Display all devices |
-f | Display filesystem information |
-m | Include mountpoint information |
-o NAME,SIZE,... | Specify columns to display |
Examples:
lsblk
- Display block deviceslsblk -f
- Display with filesystem informationlsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT
- Display only specific columnslsblk -d | grep -v "loop"
- Display only disks (exclude loop devices)lsblk -o NAME,SIZE,TYPE,MOUNTPOINT | grep "disk\|part" | sort -k 2 -hr
- Display disks and partitions sorted by sizelsblk -J | jq
- Display block device information in formatted JSONlsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,UUID | grep -v "^loop"
- Display detailed information including UUID (exclude loop devices)lsblk -o NAME,SIZE,RO,RM,MOUNTPOINT | grep "1$" | grep "^sd"
- Find removable SD deviceslsblk -b | awk '$4=="0" && $6=="disk" {sum+=$3} END {print sum/1024/1024/1024 " GB"}'
- Calculate total disk capacity in GBlsblk -o NAME,SIZE,MOUNTPOINT | grep -v "^loop" | awk 'NR>1 {print}' | column -t
- Display in formatted table
Displays USB devices connected to the system.
Option | Description |
---|---|
-v | Display verbose information |
-t | Display USB device tree |
-d [vendor]:[product] | Display only devices with specified vendor and product ID |
Examples:
lsusb
- List USB deviceslsusb -v
- Display verbose informationlsusb -t
- Display in tree structurelsusb | grep -i "storage"
- Find storage deviceslsusb -v | grep -A 5 -i "keyboard"
- Display detailed information about keyboard deviceslsusb | awk '{print $6, $7, $8, $9, $10, $11}'
- Extract device nameslsusb -v | grep -i "bcdusb" | sort
- Extract and sort USB version informationlsusb | cut -d' ' -f6 | sort | uniq -c
- Count devices by vendorlsusb -v 2>/dev/null | grep -i "power" | grep -i "ma"
- Display power consumption informationfor dev in $(lsusb | awk '{print $2":"$4}' | sed 's/://' | sed 's/://'); do lsusb -D /dev/bus/usb/$dev | grep -i product; done
- Display product names for all USB devices
Displays system uptime, number of users, and load averages.
Option | Description |
---|---|
-p | Display uptime in pretty format |
-s | Display system up since date/time |
Examples:
uptime
- Display uptime and load averagesuptime -p
- Display uptime in pretty formatuptime -s
- Display system start timeuptime | awk '{print $3, $4}' | sed 's/,//'
- Extract only uptimeuptime | awk '{print $10, $11, $12}'
- Extract only load averageswatch -n 5 uptime
- Monitor uptime and load averages every 5 secondsuptime | awk '{print $10}' | sed 's/,//' | awk '{if ($1 > 1.0) print "High load: " $1; else print "Normal load: " $1}'
- Evaluate 1-minute load averageecho "System has been up since $(uptime -s)"
- Display formatted uptimefor i in {1..12}; do uptime | awk '{print $10}' | tr -d ','; sleep 5; done
- Record load average 12 times at 5-second intervalsuptime > uptime_$(date +%Y%m%d_%H%M%S).log
- Save uptime information to timestamped log fileuptime | awk '{print $3, $4, $5}' | sed 's/,//g' | awk -v d="$(date +%F)" '{print d, $0}'
- Combine current date with uptime