LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   tar files not the folders (https://www.linuxquestions.org/questions/linux-desktop-74/tar-files-not-the-folders-879470/)

takayama 05-08-2011 07:47 AM

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?

EricTRA 05-08-2011 08:53 AM

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

MTK358 05-08-2011 03:10 PM

Quote:

Originally Posted by EricTRA (Post 4350009)
Don't forget to terminate your command with a . (dot).

What does that mean?

EricTRA 05-09-2011 12:50 AM

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

takayama 05-12-2011 02:34 PM

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

EricTRA 05-13-2011 01:01 AM

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


All times are GMT -5. The time now is 07:39 AM.