Useful Shell Command Reference
There are many ways to get information about hardware:
cat /proc/cpuinfo lscpu
cat /proc/meminfo vmstat -s free -m or free -g
ip link show netstat -i
|I/O device (hard drive)||
lsblk -d fdisk -l
df or mount show the disks mounted and can be used to show disk space.
On a file or directory level, the du command is useful for seeing how much disk space is being used.
I/O Activity and Utilization
iostat and sar come with Linux package sysstat-9.0.4-27. iostat is used for tracking I/O performance. The recommended options are:
- -d for disk utilization
- -m for calculations in MB/sec
- -x for extended report
- -t sec to repeat statistics every sec seconds
sar has several forms of output:
- -b for I/O and transfer rate statistics
- -d for block device activity
- -n for network statistics
- -v for various file system statistics
File Descriptor Usage
lsof is used to identify mapping between processes and open files. By passing multiple arguments, lsof can be used to help isolate the output:
- lsof <filename> to list processes that have <filename> open.
- lsof -p <pid> to list all files opened by the process corresponding to <pid>.
- lsof -r <secs> to keep producing output with a period of <secs>.
Network Ports, States, and Connections
- nc (netcat) or ss (socket statistics) are good for showing network activity.
- netstat is the Swiss-army knife tool for network interfaces.
- tcpdump or Wireshark with Kafka filter should be good for packet sniffing.
- top shows a sorted list of processes.
- ps shows a snapshot list of processes. Arguments can be used to filter the output.
- ps -o min_flt,maj_flt pid shows page fault information.
- ulimit -a is used to display kernel limits and shows which flags affect which kernel settings.
- ulimit -n FD to set a limit on open file descriptors.