1831647 Members
2041 Online
110029 Solutions
New Discussion

Re: ls commands

 
Jeff Hagstrom
Regular Advisor

ls commands

How can use the ls command to list on size, something greater then a number and by date, something older then 2000
9 REPLIES 9
Steven E. Protter
Exalted Contributor

Re: ls commands

perhaps a find in combination with +mtime with -exec ls -la

You may need to work sort into it as well.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Pete Randall
Outstanding Contributor

Re: ls commands

Jeff,

I think something like this should do what you want (if I'm interpreting correctly):

"find /starting_dir -size +20000c -mtime +910 -exec ls {} \; |sort -n"

Replace 20000c with your size limit in bytes. The 910 is an approximation of the number of days since 01/01/2000.


Pete


Pete
Pete Randall
Outstanding Contributor

Re: ls commands

Jeff,

After further review, make that:

"find /starting_dir -size +20000c -mtime +910 -exec ll {} \; |sort -n"


Pete


Pete
Pete Randall
Outstanding Contributor

Re: ls commands

And - make the mtime 1200 or so.


Pete


Pete
Tom Ward_1
Honored Contributor

Re: ls commands

Here's what I use, to sort by size
"ls -l |sort -n -k 5"

You're going to need find commands to go after files over a certain size or older than a set date.

James R. Ferguson
Acclaimed Contributor

Re: ls commands

Hi Jeff:

Use 'find' with a reference file to get an exact date and time boundry. Thus:

# touch -amt 200001010000 /tmp/ref # 01/01/2000 at 0000 hours

# find /tmp -xdev \( -size +10000c -a -newer /tmp/ref \) -exec ls -l | sort -k5nr

...will produce a list of all files in the /tmp directory whose size is greater than 10,000 bytes and newer than 01/01/2000 at 0000 hours. The output will be sorted in descending size order.

Regards!

...JRF...
Jon Mattatall
Esteemed Contributor

Re: ls commands

Borrowing heavily from JRF.....

You want a list of files:
sorted by size
the size greater than some value
and all older than 2000.

Still go with the

# touch -amt 200001010000 /tmp/ref # 01/01/2000 at 0000 hours

but try

# find / -size +10000 \( ! -newer /tmp/ref \) -exec ls -al {} \;|sort -k5nr

if I understand correctly, the files will all be larger than 512bytes x 10000, or about 5Mb.

np, pls. (and I'm adding this to my list of strange little one liners).
A little knowledge is dangerous - none is absolutely terrifying!!!
Tim D Fulford
Honored Contributor

Re: ls commands

Just another flavor ... find is the best method, but that has already been mentioned...

ls -ltr

This lists files in reverse time order, so you could awk this & pront any files greater than a particular size.... (I'm at home so dont know the filed size is in)

ls -ltr | awk '$4>20000{print $0}'

Tim
-
Ronelle van Niekerk
Regular Advisor

Re: ls commands

Or, to get really AWKward :

ls -l | awk '{if ($5 > 1000000) { if (substr($8,3,1) == ":" || $8 > 2000) {print $0}}}'
rm -r /it/managers