Difference between revisions of "One-liners"
m (added Category:System Administration using HotCat) |
(reference link) |
||
Line 2: | Line 2: | ||
== Free Memory == | == Free Memory == | ||
− | Use <code>echo</code> to output the result of a sub-shell, and a few extra characters (' - + p'), which is then piped to the (reverse-polish) desk calculator. Con<code>cat</code>enate the /proc/meminfo file, printing it on STDOUT. Using extended-regex <code>grep</code>, we search for lines of output that begin with "MemFree", "Cached" or "Writeback" followed by the colon character. Piping to <code>awk</code>, we can print out the string in position 2 of each line. Those values are ultimately processed in the calculator by popping the last two numbers off the stack (Writeback and Cached), and adding that result to the first number (MemFree). | + | Use <code>echo</code> to output the result of a sub-shell, and a few extra characters (' - + p'), which is then piped to the (reverse-polish) desk calculator. Con<code>cat</code>enate the /proc/meminfo file, printing it on STDOUT. Using extended-regex <code>grep</code>, we search for lines of output that begin with "MemFree", "Cached" or "Writeback" followed by the colon character. Piping to <code>awk</code>, we can print out the string in position 2 of each line. Those values are ultimately processed in the calculator by popping the last two numbers off the stack (Writeback and Cached), and adding that result to the first number (MemFree).<ref>[http://www.computerweekly.com/feature/Write-through-write-around-write-back-Cache-explained Cache explained]</ref> |
<source lang="bash"> | <source lang="bash"> | ||
echo $(cat /proc/meminfo | egrep '^(MemFree|Cached|Writeback):' | awk '{print $2}') - + p | dc | echo $(cat /proc/meminfo | egrep '^(MemFree|Cached|Writeback):' | awk '{print $2}') - + p | dc | ||
Line 18: | Line 18: | ||
VmSize: 158212 kB | VmSize: 158212 kB | ||
</pre> | </pre> | ||
+ | |||
+ | {{References}} | ||
[[Category:Bash]] | [[Category:Bash]] | ||
[[Category:System Administration]] | [[Category:System Administration]] |
Revision as of 10:59, 30 September 2015
Sometimes one-liners are so cool, you just want to remember them. And good one-liners can also teach you the intricacies and features of the Bash shell.
Free Memory[edit | edit source]
Use echo
to output the result of a sub-shell, and a few extra characters (' - + p'), which is then piped to the (reverse-polish) desk calculator. Concat
enate the /proc/meminfo file, printing it on STDOUT. Using extended-regex grep
, we search for lines of output that begin with "MemFree", "Cached" or "Writeback" followed by the colon character. Piping to awk
, we can print out the string in position 2 of each line. Those values are ultimately processed in the calculator by popping the last two numbers off the stack (Writeback and Cached), and adding that result to the first number (MemFree).[1]
echo $(cat /proc/meminfo | egrep '^(MemFree|Cached|Writeback):' | awk '{print $2}') - + p | dc
Result:
3033240
Size of X[edit | edit source]
Since everything is a file, we can look in the folder for processes (/proc), and specifically the folder created for the process id of "X" (X-org). grep
ping for the line starting with 'VmSize', we can see the Virtual Memory size of our graphical desktop.
grep ^VmSize /proc/$(pidof X)/status
Result:
VmSize: 158212 kB