Skip to content

Instantly share code, notes, and snippets.

@damc-dev
Last active December 23, 2016 14:43
Show Gist options
  • Save damc-dev/9643e80e1bc0b23024f5 to your computer and use it in GitHub Desktop.
Save damc-dev/9643e80e1bc0b23024f5 to your computer and use it in GitHub Desktop.
Unix Commands - System Information

System Info Unix Commands

Memory Usage

free: Display information on available RAM

Usage

$ free
$ free -m  #Show in MB's

System Activity

sar: System Activity Report

Used to report on various system loads, including CPU activity, memory/paging, device load, network. Linux distributions provide sar through the sysstat package.

Syntax

sar [-flags] [ -e time ] [ -f filename ] [-i sec ] [ -s time ]
-f filename Uses filename as the data source for sar. The default is the current daily data file /var/adm/sa/sadd.
-e time Selects data up to time. The default is 18:00.
-i sec Selects data at intervals as close as possible to sec seconds.

Display todays CPU activity so far

echo "SAR on the 1/2 hour and average CPU" >> $LOGFILE
sar | head -4 | tail -1 >> $LOGFILE
sar | tail -3 >> $LOGFILE

ps: Running Processes (Snapshot)

'ps' shows you what processes (programs) you have running (or are running with your user id).

Usage

$ ps aux

top: Running Processes (Live)

'top' provides lots of information on the processes running, including the percentage of the cpu and the memory being consumed by that process, who 'owns' the process and it's pid (Process ID), it also shows the output of 'uptime' and a summary of memory usage, similar to 'free'. The output of 'top' is full screen, and refreshes itself frequently (or at user definable intervals).

Usage

$ top

Disk Usage

du: Display Disk Usage

To show an estimate of file space usage under a particular directory or files on a file system

Usage

$ du [FILE]
$ du -h [FILE] # Human readable usage sizes
$ du --max-depth=1 [FILE]

Example

Find the 10 largest file/directories in human readable format

$ du -ah /logs | sort -h -r | head -n 10
4.3G    /logs
4.2G    /logs/jhe
2.0G    /logs/jhe/usm_maisvc.log
1.4G    /logs/jhe/usm
273M    /logs/jhe/usm/systems-mgmt-monitorable-asset-service-asset-crud-1_0
211M    /logs/jhe/usm/systems-mgmt-asset-service-monitorable-asset-update-cluster-assets-1_0

df: Display Free Disk Space

To show statistics about the amount of free disk space on the specified file system or on the file system of which file is a part use the df command as follows:

Usage

$ df
$ df -h

Example

$ df
Filesystem                        1K-blocks      Used Available Use% Mounted on
/dev/mapper/Vol00_vx181d-root       2031440    640668   1285916  34% /
/dev/mapper/Vol00_vx181d-var        4062912   1258364   2594836  33% /var
/dev/mapper/Vol00_vx181d-tmp        2031440     34704   1891892   2% /tmp
/dev/mapper/Vol00_vx181d-usr        4062912   2570504   1282696  67% /usr
/dev/mapper/Vol00_vx181d-openv      4062912    346008   3507192   9% /usr/openv
/dev/mapper/Vol00_vx181d-logs       8125880   4412720   3293784  58% /logs
/dev/mapper/Vol00_vx181d-home       2030995    775610   1150674  41% /home
/dev/mapper/Vol00_vx181d-opt        95195      6229     84051   7% /opt
/dev/mapper/Vol00_vx181d-config     507748     18768    462766   4% /config
/dev/mapper/Vol00_vx181d-software   13204592   2420304  10102832  20% /software
/dev/mapper/Vol00_vx181d-privdir    15236080   9230192   5219636  64% /privdir
/dev/mapper/Vol00_vx181d-upapps     1015704    486960    476316  51% /upapps
/dev/xvda1                          505604     35758    443742   8% /boot
tmpfs                               2097152         0   2097152   0% /dev/shm


$ df /dev/mapper/Vol00_vx181d-logs
Filesystem                    1K-blocks      Used Available Use% Mounted on
/dev/mapper/Vol00_vx181d-logs   8125880   4412720   3293784  58% /logs

Find 10 largest Files

$ find /logs -type f -printf '%s %p\n' | sort -nr | head -10
2125282469 /logs/jhe/usm_maisvc.log
27308300 /logs/jhe/usm_maisvc.log.live.2016.12.13.11.31.45.gz
27273755 /logs/jhe/usm_maisvc.log.live.2016.12.18.11.19.6.gz
26446365 /logs/jhe/usm_maisvc.log.live.2016.12.21.22.0.30.gz
25890490 /logs/jhe/usm_maisvc.log.live.2016.12.18.0.0.2.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment