Finding Files by Content and by Date in Solaris

Posted on

I’m accustomed to piping things using xargs (‘| xargs grep’), but this little snip works on filenames with spaces on Solaris without Gnu tools installed. Like xargs, the ‘+’ sign at the end collects the filenames into groups, and runs the command once per group (as opposed to each and every file instance which can be horribly inefficient):

find . -name "*.xml" -exec grep -i 'fillInBlankTestItem' /dev/null {} +

If you simply want to list all recent files based on their dates (the second half of each year starting in 2010, for example), you can simply list them using the recursive option on ‘ls’ like this:

ls -alhR | awk '$6 >= "Jun" && $7 >= 1 && $8 >= 2010 {print $6 $7 $8 $9 }'

If you’re looking for a particular file or set of files, then you might use:

find . -name "*.pdf" -ls | awk '$8 >= "Jun" && $8 >= 1 && $10 >= 2010 {print $8 $9 $10 $11 }'

Alternatively, if you wanted a set of files for all years starting from June 1st of 2010 (as of July 9, 2013), you might instead use:

find . -name "*.pdf" -mtime -1134 -ls | awk '{print $8 $9 $10 $11 }'

Want the information in the list tab-separated? Here’s all the files from March 1st of 2013:

find . -name "*.pdf" -ls | awk '$8 >= "Jun" && $8 >= 1 && $10 >= 2013 {print $8 "t" $9 "t" $10 "t" $11 }'

or, if you simply want all fields to use the same delimiter, you could replace the above line with:

find . -name "*.pdf" -ls | awk '$8 >= "Jun" && $8 >= 1 && $10 >= 2013 {OFS="t"; print $8, $9, $10, $11 }'

Leave a Reply

Your email address will not be published. Required fields are marked *