Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

To create a backup of entire directory I do:

tar -cPzf /home/misha/path/to/tar/tar_name.tar.gz 
    -C /home/misha/path/to/directory/to/backup .

In the resulting tar_name.tar.gz beside the files themselves I see also the . directory.

Is it possible not to create it ?

share|improve this question
up vote 1 down vote accepted


tar czf mybackup.tar.gz /home/misha/path/to/directory/to/backup

This command will compress the directory /home/misha/path/to/directory/to/backup into mybackup.tar.gz in your current directory.

share|improve this answer
I'm not interested in making the tar in the current directory. I would like it to be in /home/misha/path/to/tar (and I prefer not to cd to this directory, if possible). – Misha Moroshko Jul 1 '11 at 7:18
Then do tar cvf /home/misha/path/to/tar.tgz /home/misha/path/to/directory/to/backup – Barry Brown Jul 1 '11 at 7:32
Barry is right. Just add the full path and you can run the tar in any directory you like. +1 Baz :-) – slotishtype Jul 1 '11 at 7:38
The problem with your suggestion is that the created tar contains all the directories, i.e. home->misha->path->to->directory->to->backup, rather than just the files themselves. How could I enforce not to create this directory structure ? – Misha Moroshko Jul 1 '11 at 8:56
Ok. I understand what you want now. Use -C to chdir. For example: tar -czf myfile.tar.gz -C /mylocation myfile.txt -C /file2 file2.txt -C /other/dir afile.html – slotishtype Jul 1 '11 at 10:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .