Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 09-26-2008, 04:23 AM   #1
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 593

Rep: Reputation: 30
To list the file on MB size only

Is there anyway to list the files on size of Megabytes only?
Am using ls -lh always or sometimes du -sh/ch,but they can list them in kb.

Say if a files is 724Kbytes, is there any way to print it in MB?

Old 09-26-2008, 04:59 AM   #2
Senior Member
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Here's a hack; it's not nice, and it doesn't handle files with spaces in it, but you get the idea:
ls -l | awk '{printf "%s %i %s %s %.3fMB %s %i %s %s\n", $1,$2,$3,$4,$5/1024000,$6,$7,$8,$9}'

Last edited by pwc101; 09-26-2008 at 05:00 AM.
Old 09-26-2008, 05:37 AM   #3
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 593

Original Poster
Rep: Reputation: 30
Thanks PWc101 .... It's Great
Old 10-04-2008, 07:05 AM   #4
Registered: Feb 2008
Location: London
Distribution: FC8, FC9, Centos 4, Centos 5, Knoppix
Posts: 52

Rep: Reputation: 17
It always rounds up so it isn't very accurate for small files but you could try

ls -l --block-size=1M
1 members found this post helpful.
Old 10-04-2008, 09:21 AM   #5
Senior Member
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Originally Posted by ZAMO View Post
Is there anyway to list the files on size of Megabytes only?
du -sh *|egrep '^[0-9]+(,[0-9]+)*M.*$'
or if (for some reason) your locale uses "." instead of "," to separate numbers, then:
du -sh *|egrep '^[0-9]+(\.[0-9]+)*M.*$'

Last edited by ErV; 10-04-2008 at 09:44 AM.


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
List LS query by file size hammertime1983 Linux - Newbie 3 05-27-2013 02:38 AM
any ideas to reduce log file size or make log file size managed? George2 Programming 2 08-13-2006 06:55 AM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 04:18 PM
How to list total file size of a directory phil1076 Linux - General 3 12-18-2003 03:47 PM
list size of directory and all directories it contains? ubien Linux - General 2 01-11-2003 10:59 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:59 AM.

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