LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   compress with tar without saving full paths (https://www.linuxquestions.org/questions/linux-newbie-8/compress-with-tar-without-saving-full-paths-857368/)

razor7 01-19-2011 03:28 PM

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!

pwc101 01-19-2011 03:35 PM

Just cd into /home/martin before you create the tar archive and then archive ./.

tsg 01-19-2011 03:37 PM

or you can use the -C parameter which does the same thing.

xeleema 01-19-2011 03:40 PM

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

razor7 01-19-2011 06:07 PM

Hi the -C with th . at the end did the trick.

Thanks a lot!

grail 01-20-2011 12:18 AM

Please mark as SOLVED once you have a solution.

ankit91 11-14-2016 04:57 AM

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
I am running above code but system returns
"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 .
then the contents of directory_to_add will be added and not the directory itself.

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.