Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I'm trying to tar my website files that are on my test server to be able to upload them to 'real' server.

tar -cf mysite.tar /var/www

It creates archive fine... but when I open that archive it has var directory, which contains www directory... How do I create archive that has /var/www content in its root, not in subfolders like it's right now?

share|improve this question
up vote 2 down vote accepted

I think you are wanting all the files and folders that are in the www folder. If I am misunderstanding you im sorry. If that is what you want you could cd into the www directory and run

tar -cvf backup.tar *
share|improve this answer
1  
Keep in mind that globbing like this will not get file's which name begins with a dot. – John T Feb 1 '10 at 5:34
    
How do I get 'dot' files included too? – mea Feb 1 '10 at 5:55
    
Im not good enough with regular expression to figure this one out. I tried something like tar -cvf backup.tar .??* but that backs up only the hidden files. – Justin S Feb 1 '10 at 7:17
    
@mea, do you want to preserve the directory structure inside the /var/www folder? – John T Feb 2 '10 at 17:48
    
@mea. John T got it right. You're asking for trouble when using * with tar. Often it may not matter, but when it does, you probably won't even notice the missing "dot" files (and directories!) until much later. Consider accepting this instead: superuser.com/questions/103170/tar-a-directory/103177#103177 – Jonik Feb 14 '10 at 0:40

You can use the -C (capital c) option to make tar change to a directory before it begins it's work. This will effectively remove the directory parents from the archive.

Your other option is to simply run the command from inside the /var/www directory itself and avoid this altogether.

share|improve this answer

Your Answer

 
discard

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