LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 05-08-2011, 07:47 AM   #1
takayama
Member
 
Registered: Sep 2009
Posts: 97

Rep: Reputation: 0
tar files not the folders


Hello
Im trying to tar a some stuff in a other folder with this command
tar czvf test.tat.gz /home/apa/test/ (just a test)
But when i extract it later i get the hole /home/apa/test/ structure, is there anyway of tar just the files?
 
Old 05-08-2011, 08:53 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

Have a look at the man page for tar. The -C option changes to the directory and tars them. Don't forget to terminate your command with a . (dot). Or do it manually, that is, change to the directory and just tar the files.

Kind regards,

Eric
 
Old 05-08-2011, 03:10 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Quote:
Originally Posted by EricTRA View Post
Don't forget to terminate your command with a . (dot).
What does that mean?
 
Old 05-09-2011, 12:50 AM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

Sorry if I was unclear, after re-reading my post I understand it must be confusing. I refer to the dot when using the command from within the directory, meaning first cd into the directory you want to include files from and then run tar like this:
Code:
tar cvf tarfile.tar -C <dir> .
where the dot means the current directory.

Kind regards,

Eric
 
Old 05-12-2011, 02:34 PM   #5
takayama
Member
 
Registered: Sep 2009
Posts: 97

Original Poster
Rep: Reputation: 0
Cool!
Is it possible to do just get the folder where all the files are in, sounds strange, i think its easier to show a example.

/opt/logs/1/hejsan.txt
/opt/logs/2/hejsan.txt
/opt/logs/3/hejsan.txt

what i want is to be able to be in one directory (say /home/apa) and create a tar archive from there that, and when you untar in you get
1/hejsan.txt
or
2/hejsan.txt
 
Old 05-13-2011, 01:01 AM   #6
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

When you change into the directory /opt/logs:
Code:
cd /opt/logs
and run this:
Code:
tar cvf filename.tar .
You'll get a tarfile with the subdirectories and files included. If you move for example that tar file to your home directory and untar it there with:
Code:
tar xvf filename.tar
it will create the subdirectories you tarred in your home directory and the files in them. You can add the z option to compress. Have a look at the man page for tar:
Code:
man tar
it explains those possibilities and a lot more.

Kind regards,

Eric
 
  


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
find and unzip selected sub folders in tar.gz files samanp Linux - Server 1 11-05-2010 09:16 AM
find -exec command to recursively delete files and folders in folders with X name Joan Murt Linux - Newbie 2 07-08-2009 04:35 PM
tar multiple folders and files at once sinister1 Linux - General 4 12-10-2007 02:49 AM
getting downloaded rpm/cups and tar files into correct folders mookie2125 Linux - Newbie 4 07-17-2005 08:35 PM
move files in tar.gz back to into original folders GUIPenguin Linux - General 1 05-09-2005 12:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 12:09 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