I'm trying to list files, first by size and I'm using something like this
ls -l|awk '{print $5,$6,$7,$8,$9|"sort -nr"}'|more
Now I'd like to just do the same listing but only for files with the year 2009 in the $8 field or even anything less than 2011.
See if this does it for you:
ls -l|awk '{print $5,$6,$7,$8,$9|"sort -nr"}' | egrep ' 2010 ' | more
That worked thanks and if I wanted to remove all those files, then I could try this? I know the rm command is potentially dangerous so I would like to know before I run it
ls -l|awk '{print $5,$6,$7,$8,$9|"sort -nr"}' | egrep ' 2010 ' | rm -f
Oh and in a related question how about the files that are only 0 bytes which is represented in $5 and then just remove those?
edit:
I tried this and it seem to work for zero bytes from my results
ls -l|awk '{print $5,$6,$7,$8,$9|"sort -nr""}' | egrep '^0' | more
My only question left for above results is can I just add | rm -f to remove the files. I dont want to wipe the whole directory by accident.
use find
command.
Check first: (I just guess the date, you need adjust it with your request)
find . -type f -mtime +700 -mtime -1000 -ls
Then do the clean:
find . -type f -mtime +700 -mtime -1000 -exec rm -f {} \
I tried this for files equal to 0
find . -type f -size 0 -exec rm -f {} \
and all I get is this:
>
find . -type f -printf "%AY %p\n" | grep "^2010"