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

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

2 Answers 2

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
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: – 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


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