Results 1 to 9 of 9

Thread: Get RAM Memory in Terminal

  1. #1

    Default Get RAM Memory in Terminal

    How can i get the RAM Memory on system in terminal when i have 3 GB with an output like this:

    3072
    or
    3145728
    or
    3221225472

    Anyone knows this?
    Just without MB in back of it, only the numbers. in MB, KB or B?

    Thanks in Advance.

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,378

    Default Re: Get RAM Memory in Terminal

    Code:
    grep 'MemTotal' /proc/meminfo
    You have to cut off a few things there if you like.
    Henk van Velden

  3. #3

    Default Re: Get RAM Memory in Terminal

    thanks, i was looking for this, now i can use sed to cut out so i only have the numbers

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,378

    Default Re: Get RAM Memory in Terminal

    You are welcome.
    Henk van Velden

  5. #5

    Default Re: Get RAM Memory in Terminal

    how to edit the output of this directly with sed or awk?

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,378

    Default Re: Get RAM Memory in Terminal

    Code:
    grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'
    Henk van Velden

  7. #7

    Default Re: Get RAM Memory in Terminal

    Can i set this as a integer variable? I now have this.
    Code:
    declare -i num=grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://        ' -e 's/ kB//'

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,378

    Default Re: Get RAM Memory in Terminal

    To get rid of the spaces in front:
    Code:
    grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal: *//' -e 's/ kB//'
    To get this in an integer num:
    Code:
    declare -i num=$(grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal: *//' -e 's/ kB//')
    Henk van Velden

  9. #9

    Default Re: Get RAM Memory in Terminal

    Code:
    declare -i num=$(free | awk '/Mem/{print $2}')
    or (using a single sed command):
    Code:
    declare -i num=$(sed -n 's/MemTotal: *\(.*\) kB/\1/p' /proc/meminfo)

Posting Permissions

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