LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-16-2011, 09:34 PM   #1
athrin
Member
 
Registered: Mar 2011
Posts: 135

Rep: Reputation: 1
converting kb to mb


hi.. i want to convert kb to mb
and i'm wanted to use bash.

if i use
"cat /proc/meminfo | grep MemTotal"
will only display in kb and i want to display it in mb..
and i want it to display like this
MemTotal : 250 mb

Last edited by athrin; 03-16-2011 at 11:14 PM.
 
Old 03-16-2011, 09:43 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
free -g

echo 3 k $(cat /proc/meminfo | grep MemTotal | awk '{print $2}') 1024 / 1024 / p | dc

make sure you have dc (desk calculator) installed.

jlinkels
 
Old 03-17-2011, 08:36 AM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Why not use bash's built-in math functionality?

Code:
$(( $(cat /proc/meminfo | grep MemTotal | awk '{ print $2 }') / 1024 ))
 
Old 03-17-2011, 09:02 AM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
AFAIK Bash has no built-in math functionality except integers.

jlinkels
 
Old 03-17-2011, 09:03 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Yes, bash only does integer math.
 
Old 03-18-2011, 03:45 AM   #6
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
thanks guys ^_^
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help Converting C# Code to C++ timrs Programming 1 04-03-2007 07:40 PM
converting Screener Linux - Newbie 14 07-02-2006 10:02 PM
Converting files? sonic04002 Linux - Newbie 8 10-31-2005 10:54 PM
converting to debian Paxmaster Debian 6 12-24-2004 02:35 PM
converting fs nautilus_1987 Linux - Hardware 4 11-03-2002 05:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration