I'm working on a backup script and want to tar up a file directory:
tar czf ~/backup.tgz /home/username/drupal/sites/default/files
This tars it up, but when I untar the resulting file, it includes the full file structure: the files are in home/username/drupal/sites/default/files
.
Is there a way to exclude the parent directories, so that the resulting tar just knows about the last directory (files
)?
cd /home/username/drupal/sites/default/files
tar czf ~/backup.tgz *
You can also use the -C option of tar.
cd is not recommended and error prone, e.g. big scripts or makefiles. The answer below is more generally usable and correct.
Tries
-C
and--directory
didn't work for me on Ubuntu 16.04. This is only option that works.This is the only option that works -C add a . root folder, which is not what we want.