Linux Tar, Zip, Gzip Matching Files In Current Directory

The Code

 find . -name "2013-*" -type d | xargs tar cvpzf "2013 logs.tar.gz" 

 

Explanation

We use the find command with “.” as the current directory we’re in, so I used “cd” – change directory to where I wanted to zip up files. The -name parameter is then finding any thing starting with “2013-“ followed by anything else via the “*” wildcard.  The “-type d” restricts the search to only directories.  We then use the pipe | over to xargs and run our tar command with the options c-create, v-verbose (See the process as it happens), p-preserve-permissions (great for taking backups if you ever have to restore) , z-gzip the more zipping the merrier, f-file allows you to specify the output file name.

References

Next Steps

This entry was posted in Interesting Finds and tagged , , , , , , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Trackback

Leave your thoughts...

You must be logged in to post a comment.