Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash & admin sys commands

https://explainshell.com/

Find the largest file in a directory and its subdirectories using the find command & more

find . -printf '%s %p\n'| sort -nr | head -10

@see https://www.cyberciti.biz/faq/how-do-i-find-the-largest-filesdirectories-on-a-linuxunixbsd-filesystem/

Show host IP address for a specific domain

$ host google.be | awk '/has address/ { print $4 }'

Size of directories:

All the directories in the current directory

$ du -sh */

A specific directory

du -sh file_path

@see https://unix.stackexchange.com/questions/185764/how-do-i-get-the-size-of-a-directory-on-the-command-line

Size of all the files in the current directory

$ du -sh -- *

Report file system disk space usage

Use it to see if some partition is full.

$ df -Th

Other commands

1. top [Process Activity Command]
Displays the most CPU-intensive tasks running on the server and updates the list every five seconds.

2. vmstat [System Activity, Hardware and System Information]
Reports information about processes, memory, paging, block IO, traps, and cpu activity.

  • vmstat 3 (repeat every 3 seconds)
  • vmstat -m (display memory utilization slabinfo)
  • vmstat -a (get information about active/inactive memory pages)

3. w [Who Is Logged on And What They Are Doing]
Displays information about the users currently on the machine, and their processes.

4. uptime [Tell How Long The System Has Been Running]
See how long the server has been running, the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.

5. ps [Display The Processes]
Displays a snapshot of the current processes. To select all processes use the -A or -e option. ps is just like top but provides more information.

  • ps -auxf | sort -nr -k 4 | head -10 (Find Out Top 10 Memory Consuming Process)
  • ps -auxf | sort -nr -k 3 | head -10 (Find Out Top 10 CPU Consuming Process)
  • ps -eo euser,ruser,suser,fuser,f,comm,label (Print Security Information)
  • ps axZ OR ps -eM (Print Security Information)
  • ps -Al (Show Long Format Output)
  • ps ax OR ps axu (Print All Process On The Server)

6. free [Memory Usage]
Displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.

7. iostat [Average CPU Load, Disk Activity]
Reports CPU statistics and input/output statistics for devices, partitions and network filesystems (NFS).

8. sar [Collect and Report System Activity]
Used to collect, report, and save system activity information.

  • sar -n DEV | more (display network counter)
  • sar -n DEV -f /var/log/sa/sa24 | more (display network counters from the 24th)
  • sar 4 5 (display real time usage)

9. mpstat [Multiprocessor Usage]
Displays activities for each available processor, processor 0 being the first one. mpstat -P ALL to display average CPU utilization per processor.

10. pmap - Process Memory Usage
Reports memory map of a process. Use this command to find out causes of memory bottlenecks: pmap -d PID

Source: http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment