LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-19-2011, 04:28 PM   #1
razor7
LQ Newbie
 
Registered: Apr 2004
Location: Argentina
Distribution: Ubuntu GNU/Linux
Posts: 12

Rep: Reputation: 0
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!
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 01-19-2011, 04:35 PM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Just cd into /home/martin before you create the tar archive and then archive ./.
 
Old 01-19-2011, 04:37 PM   #3
tsg
Member
 
Registered: Mar 2008
Posts: 155

Rep: Reputation: 30
or you can use the -C parameter which does the same thing.
 
Old 01-19-2011, 04:40 PM   #4
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
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
 
2 members found this post helpful.
Old 01-19-2011, 07:07 PM   #5
razor7
LQ Newbie
 
Registered: Apr 2004
Location: Argentina
Distribution: Ubuntu GNU/Linux
Posts: 12

Original Poster
Rep: Reputation: 0
Hi the -C with th . at the end did the trick.

Thanks a lot!
 
Old 01-20-2011, 01:18 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,254

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Please mark as SOLVED once you have a solution.
 
Old 11-14-2016, 05:57 AM   #7
ankit91
LQ Newbie
 
Registered: Nov 2016
Posts: 1

Rep: Reputation: Disabled
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tar with parameter -T (or --files-from) does not compress? Babelduo Linux - Server 3 01-18-2011 09:23 AM
tar doesn't compress .hidden files in the same directory it is run in? BassKozz Linux - Newbie 2 06-02-2009 05:46 PM
Resize (*.jpg) -> Rename -> Compress (xyz.tar) ? control_guy Linux - Newbie 6 05-22-2008 02:34 PM
compress a directory using tar muskiediver Linux - General 4 07-18-2006 11:24 AM
recursively listing directories full paths kubicon Linux - Newbie 2 02-22-2004 04:55 PM


All times are GMT -5. The time now is 10:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration