7

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?

2 Answers 2

2

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 *
7
  • 1
    Keep in mind that globbing like this will not get file's which name begins with a dot.
    – user1931
    Feb 1, 2010 at 5:34
  • How do I get 'dot' files included too?
    – mea
    Feb 1, 2010 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, 2010 at 7:17
  • @mea, do you want to preserve the directory structure inside the /var/www folder?
    – user1931
    Feb 2, 2010 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, 2010 at 0:40
9

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.

You must log in to answer this question.