LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636
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: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
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
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636
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: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
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


All times are GMT -5. The time now is 03:28 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration