LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   To list the file on MB size only (https://www.linuxquestions.org/questions/linux-general-1/to-list-the-file-on-mb-size-only-672479/)

ZAMO 09-26-2008 04:23 AM

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?

Thanks

pwc101 09-26-2008 04:59 AM

Here's a hack; it's not nice, and it doesn't handle files with spaces in it, but you get the idea:
Code:

ls -l | awk '{printf "%s %i %s %s %.3fMB %s %i %s %s\n", $1,$2,$3,$4,$5/1024000,$6,$7,$8,$9}'

ZAMO 09-26-2008 05:37 AM

Thanks PWc101 .... It's Great

timnp 10-04-2008 07:05 AM

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

Code:

ls -l --block-size=1M

ErV 10-04-2008 09:21 AM

Quote:

Originally Posted by ZAMO (Post 3292263)
Is there anyway to list the files on size of Megabytes only?

Code:

du -sh *|egrep '^[0-9]+(,[0-9]+)*M.*$'
or if (for some reason) your locale uses "." instead of "," to separate numbers, then:
Code:

du -sh *|egrep '^[0-9]+(\.[0-9]+)*M.*$'


All times are GMT -5. The time now is 12:23 AM.