I'm writing a script that can tar any given folder and place it in my home/bkp. the script will read like this,
tar czvf /home/me/bkp/`basename $1`.tar.gz $1
well now, to use it.,
backup-script.sh /home/me/folder/sub/to-be-backed-up/
Well and good.
Now when I untar it, it creates home/me/folder/sub/to-be-backed-up/*files*
I just want to-be-backed-up开发者_如何学C/*files*
Is there any option while creating the tar files that i compress it relatively ?
You could use the -C
option of tar so that it changes to a given directory first. I often use the trick of appending /..
to the path to get the parent directory, so that your script would be something like:
# backupscript.sh <folder>
tar cvzf /home/me/bkp/`basename $1`.tar.gz -C $1/.. `basename $1`
Or you could perhaps use dirname
instead to change to the right directory first
精彩评论