To display information about memory, we use the following command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | $ free -help free: invalid option -- 'h' usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V] -b,-k,-m,-g show output in bytes, KB, MB, or GB -l show detailed low and high memory statistics -o use old format (no -/+buffers/cache line) -t display total for RAM + swap -s update every [delay] seconds -c update [count] times -V display version information and exit $ free -mt total used free shared buffers cached Mem: 1002 758 243 0 46 355 -/+ buffers/cache: 357 644 Swap: 2015 0 2015 Total: 3018 758 2259 |
But if we want the data displayed in the terminal to be maintained, we will use:
1 2 3 4 5 6 7 8 9 | $ watch --help Usage: watch [-dhntv] [--differences[=cumulative]] [--help] [--interval=] [--no-title] [--version] <command></command> -d, --differences[=cumulative] highlight changes between updates (cumulative means highlighting is cumulative) -h, --help print a summary of the options -n, --interval= seconds to wait between updates -v, --version print the version number -t, --no-title turns off showing the header |
The combination of the two args will solve our problem.
Here is the final command:
1 2 | $ watch -d free -mt |
Here is the displayed result:
It will display used and free memory every two seconds.