Find the answer to your Linux question:
Results 1 to 4 of 4
Hi everyone, I am trying to write a small script that can output the RAM size. I am doing this with the following command line: system ("free -m | grep ...
  1. #1
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277

    RAM size

    Hi everyone,

    I am trying to write a small script that can output the RAM size.
    I am doing this with the following command line:

    system ("free -m | grep Mem");

    The output I get is:
    Mem: 999 916 83 0 106 265

    Is there a way so that I can print out only the RAM size, which is the first number in the above row?

    Thank you

  2. #2
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    Code:
    cat /proc/meminfo | grep MemTotal

  3. #3
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    Try using awk
    Code:
    free -m |grep Mem |awk '{print $2}'
    There are lots of ways to do this however. How about...
    Code:
    grep MemTotal /proc/meminfo
    Though this again would require awk or similar to parse it.

    EDIT :- Beat me to it Coopstah

  4. #4
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277
    Thank you very much guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...