I know how to get the total memory in the system:$ free -lm             total       used       free     shared    Mem:          3008       2495        513         57I know how to get the main memory consumption (RSS) of worker processes in Nginx:$ ps -C nginx -O rss  PID   RSS S TTY          TIME COMMAND 1564  1336 S ?        00:00:00 nginx: master process /usr/sbin/nginx 1565  1756 S ?        00:00:00 nginx: worker process 1566  1756 S ?        00:00:00 nginx: worker process 1567  1756 S ?        00:00:00 nginx: worker process 1568  1756 S ?        00:00:00 nginx: worker processNow to determine how many worker processes my system could use without resorting to swap:echo $((3008 * 1024))3080192$ echo $((3080192 / 1756))1754My server can handle 1754 nginx workers without resorting to swap. However, it would be great if I can take this multi-step process above and make it a single line which can be executed from command line.My problem is I don't know how to extract that 3008 from the free command from the command line. How can I tackle this?
Bash: extract data from a command-line program
bash
My problem is I don't know how to extract that 3008 from the free  command from the command lineGiven this output:free -lm             total       used       free     shared    buffers     cachedMem:          3757       1765       1991        138        122        766Low:          3757       1765       1991High:            0          0          0-/+ buffers/cache:        876       2880Swap:         7772          0       7772Try this:free -lm | grep '^Mem' | awk '{ print $2 }'3757Which will return the total column in the Mem: row. In my case 3757.