Search code examples
linuxunixgnutar

How do I tar a directory without retaining the directory structure?


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)?


Solution

  • cd /home/username/drupal/sites/default/files
    tar czf ~/backup.tgz *