1756012 Members
2613 Online
108839 Solutions
New Discussion юеВ

Unix Command "ls"

 
SOLVED
Go to solution
Landen
Occasional Contributor

Unix Command "ls"

Hi,

I was wondering if the ls command can list all files in a current directory with file size that is greater than some number and less than some number? If so, how will this be done? If not, are there any other commands that will do this function? or maybe a small script?

Perhaps, some clever individual could answer this question?

arrivederci...
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: Unix Command "ls"

Hi Landen:

If you want to use 'ls' and limit the results returned by filesize, consider this method:

# ls -l /tmp|awk '$5 > 1000 && $5 < 3000 {print $0}'

...this will return all files in the /tmp directory whose size is greater than 1000 and less than 3000.

Regards!

...JRF...
Victor BERRIDGE
Honored Contributor

Re: Unix Command "ls"

Hi,
I can only think of using the cmd find with size option with -a (logical AND operator)...
So man find...

All the best
Victor
MANOJ SRIVASTAVA
Honored Contributor

Re: Unix Command "ls"

Hi Landen


do

ls -l | awk ' { if ($5 > "aaa" && $5 < "BBB" ) print $NF,$5 }' > /tmp/test.

will give you what you need from the present working directory , incase you want to search everythin under that directory

replace ls -l with ls -lR .

Manopj Srivastava
Paula J Frazer-Campbell
Honored Contributor

Re: Unix Command "ls"

Hi

This command will find in /tmp files greater than 1000000 bytes - modify size and dir to suit.

find /tmp -size +1000000c -exec ls -l {} \;


Paula
If you can spell SysAdmin then you is one - anon
Bernie Vande Griend
Respected Contributor
Solution

Re: Unix Command "ls"

If you just want a listing of files in the current directory that are between 10000 bytes and 20000 bytes, simply:
find . -size +10000c -size -20000c -print
Ye who thinks he has a lot to say, probably shouldn't.