I love awk…and grep…and sed…and terminals

ShareShare on FacebookTweet about this on TwitterPin on PinterestShare on Google+Share on Reddit

Today’s terminal fun:

find /Volumes/Data/ -mtime -2d -exec ls -al {} \; | grep “Oct  7” | grep -v “.DS_Store” | grep “/” | awk ‘$8 ~ /\:/ { print $3″,”$5″,”$8″,” substr($0, index($0,$9)) }’ > October7.csv

That will find all files modified more recently than 2 days ago, execute an ls -al on them, search that output for Oct 7, exclude any .DS_Store files, search that output for a forward slash (to exclude only file references), make sure there is a time in field 8 (which confirms it was Oct of this year…because it could be Oct 7 of 2 years FROM now) and then outputs the user, size time modified and directory/file name to a .csv file.

So, I end up with crucial information on files modified on October 7th.

I KNOW there are probably way, WAY better ways to do this, but that’s the cool thing about Linux/OSX…you can do it how it comes to you first.

I’d love to know other (better?) ways to get this info…

This entry was posted in technology and tagged . Bookmark the permalink.

Leave a Reply

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