Skip to content

Latest commit

 

History

History
127 lines (86 loc) · 6.22 KB

Bash - commands.md

File metadata and controls

127 lines (86 loc) · 6.22 KB

unix commands

free -
  Display amount of free and used memory in the system

  free displays the total amount of free and used physical and swap memory in the system,
  as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo.
  The displayed columns are:

   total  Total installed memory (MemTotal and SwapTotal in
          /proc/meminfo)

   used   Used memory (calculated as total - free - buffers - cache)

   free   Unused memory (MemFree and SwapFree in /proc/meminfo)

   shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo)

   buffers
          Memory used by kernel buffers (Buffers in /proc/meminfo)

   cache  Memory used by the page cache and slabs (Cached and
          SReclaimable in /proc/meminfo)

   buff/cache
          Sum of buffers and cache

   available
          Estimation of how much memory is available for starting
          new applications, without swapping. Unlike the data
          provided by the cache or free fields, this field takes
          into account page cache and also that not all reclaimable
          memory slabs will be reclaimed due to items being in use
          (MemAvailable in /proc/meminfo, available on kernels 3.14,
          emulated on kernels 2.6.27+, otherwise the same as free)

System Monitoring Commands -

System resources:

lsof:
  We can use the Linux lsof command to capture the number of open connections on a given port port for ex: 443
  the cmd to be used as follows:
  lsof -i tcp:443

  usecase - when we upload a big file to Amazon S3, it uploads in chunks (using multi-part upload option),
  so, lsof cmd will tell us how many connections are used to upload in chunks at a given port #

  The lsof command will print out a list of every file that is in use.
  Since Linux considers everythihng a file, this list can be very long.
  However, this command can be useful in diagnosing problems.

  An example of this is if we wish to unmount a filesystem, but we are being told that it is in use.
  We could use this command and grep for the name of the filesystem to see who is using it.

  Or suppose we want to see all files in use by a particular process. To do this we would use lsof -p <processid>, where is the process-id

top:
  The top will display a continually updating report of system resource usage.
  image

  We can modify the output of top while is is running. If we hit an i, top will no longer display idle processes.
  Hit i again to see them again. Hitting M will sort by memory usage, S will sort by how long they processes have been running, and P will sort by CPU usage again.

  For more in-depth information about processes you can look in the /proc filesystem.
  In the /proc filesystem we will find a series of sub-directories with numeric names.
  These directories are associated with the processes ids of currently running processes.
  In each directory we will find a series of files containing information about the process.

  image

  NOTE: WE MUST TAKE EXTREME CAUTION TO NOT MODIFY THESE FILES, DOING SO MAY CAUSE SYSTEM PROBLEMS!

iostat:
  image

ps:
  The ps will provide you a list of processes currently running.
  A common use would be to list all processes currently running. To do this you would use the ps -ef command.

vmstat:
  The vmstat command will provide a report showing statistics for system processes, memory, swap, I/O, and the CPU.
  These statistics are generated using data from the last time the command was run to the present.
  In the case of the command never being run, the data will be from the last reboot until the present.

  image

  image

Filesystem Usage

df:
  The df is the simplest tool available to view disk usage.
  Simply type in df and we'll be shown disk usage for all your mounted filesystems in 1K blocks

  image

du:
  Now that we know how much space has been used on a filesystem how can we find out where that data is?
  To view usage by a directory or file we can use du. Unless we specify a filename du will act recursively.

  image

Monitoring Users

who:
  The easiest way to see who is on the system is to do a who or w.
  The --> who is a simple tool that lists out who is logged --> on the system and what port or terminal they are logged on at.

  image

ps:
  In the previous section, we can see that user aweeks is logged onto both pts/1 and pts/2,
  but what if we want to see what they are doing?
  We could to a ps -u aweeks and get the following output
  image

w:
  Even easier than using the who and ps -u commands is to use the w.
  w will print out not only who is on the system, but also the commands they are running.

  image

Reference:

  1. https://tldp.org/LDP/sag/html/system-monitoring.html