compress with tar without saving full paths
Hi, when I execute this command "tar -zcf /home/martin/documents.tar.gz /home/martin/Documents" all files in the compressed archive gets the full path, so whem decompressing i get something like this
/home/martin/documents/home/martin/Documents/archive1.txt /home/martin/documents/home/martin/Documents/archive2.txt /home/martin/documents/home/martin/Documents/archive3.txt I really want to have it this way, without the full path /home/martin/documents/archive1.txt /home/martin/documents/archive2.txt /home/martin/documents/archive3.txt Wich parameter i am missing? Thanks in advise! |
Just cd into /home/martin before you create the tar archive and then archive ./.
|
or you can use the -C parameter which does the same thing.
|
Greetingz!
Not sure if you're just trying to tar up "martin's" home directory, or every user's home directory, so I'm going to suggest the following; If you want to tar just martin's home directory; cd /home/martin That will give you a directory structure like ./Documents/archive1.txt ./Documents/archive2.txt ./Documents/archive3.txt However, my all-time favorite is the "-C" option of tar (that's a capital C, not lowercase). Downside is this isn't available on every single flavor of UNIX (like Solaris, HP-UX & AIX). So check your tar man page. It would basically look like this then; tar -zcf /home/martin/documents.tar.gz -C /home/martin/Documents . This will give you a directory structure that looks just like above (basically, just like if tar was ran from inside the directory specified with -C) ./Documents/archive1.txt ./Documents/archive2.txt ./Documents/archive3.txt |
Hi the -C with th . at the end did the trick.
Thanks a lot! |
Please mark as SOLVED once you have a solution.
|
How add a directory to tar archive by name and absolute path
I want to add a directory to tar by it's name and absolute path. Please remember I want to add directory itself and not just it's contents.
eg - Code:
tar -czpvf arc.tar.gz -C /var/www/html/directory_to_add "tar: Cowardly refusing to create an empty archive Try 'tar --help' or 'tar --usage' for more information." If I run Code:
tar -czpvf arc.tar.gz -C /var/www/html/directory_to_add . Is there any solution to add the directory itself by using absolute path. I am making a script in PHP but I found no solution with PHP inbuilt class PharData Please help. Thanks in advance. |
All times are GMT -5. The time now is 03:24 AM. |