Bash Shell One Liner: Find and compress files

Mostly wanted to write this down so I can find it later…

This bash shell snippet will search a directory tree for files matching a number of regular expression criteria, and then add them all to tar/gzipped file.


find -X . -name "*201009*" -o -name "*201010*" -o -name "*201011*" | xargs tar czvf ~/Desktop/corplogs.tgz

I was using the Mac OS X terminal…this took me a long time to figure out because all the find tutorials on the web have the find criteria inside parentheses.  Apparently the parentheses aren’t necessary in the Mac terminal.

In this case, I was looking for log files between September 2010 and November 2010.  The “-o” argument is a logical OR.  The find command spits out a list of file names, and xargs bundles them up and passes them to the tar command.

Advertisement

, , ,

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.