Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 1 down vote accepted

Try:

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
2  
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
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.