Posts tagged ‘bash’

How to backup a directory using tar in one line.

This is all terribly simple… but I’m rather inclined to forget it. The reason I’m putting this here is that I’ve written something like this at least twice.

file=$(basename `pwd`);
backupName=$file-$(date +%Y-%m-%d.tgz);
tar -C .. -czf $backupName $file --exclude=$file/$backupName

This creates a gunzipped tar file of the current directory, in the current directory and includes the current date in the name. This is quite useful for your home directory.

Advertisements

April 5, 2008 at 2:09 pm 1 comment


October 2017
M T W T F S S
« Nov    
 1
2345678
9101112131415
16171819202122
23242526272829
3031