find . -name "2013-*" -type d | xargs tar cvpzf "2013 logs.tar.gz"
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.
- Old code I’ve been using to backup our website. Hopefully should cover this in a later article