LinuxQuestions.org
Review your favorite Linux distribution.
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 12-04-2012, 06:36 AM   #1
srg46srg
LQ Newbie
 
Registered: Dec 2012
Posts: 1

Rep: Reputation: Disabled
Compress several files without directory structure


Hi, I am trying to compress files in different directories without preserving structure (like if all files where in the same directory).

For example:

I have a directory 'a' with a file '1' and a directory 'b' with a file '2'.

Then my need is compress these files without directory structure in order to uncompress them later and getting them in the same directory. (Both '1' and '2' inthe local dir, e.g.)

I am trying with tar command but I did not succeed

Thanks in advance
 
Old 12-04-2012, 07:01 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Hi and welcome to LinuxQuestions!

You can use find to select the files you want to put into the archive and use tar from inside the directory where the files are, using -execdir. Example:
Code:
find . -type f -execdir tar --append -f /path/to/my/archive.tar {} \; && gzip /path/to/my/archive.tar
This will archive all the files existing in the current working directory. You have to refine your search criteria in order to select only the desired files. Note that since it uses the --append option, tar cannot work on compressed archives, therefore you have to compress the archive later (as shown in the command line above). Just an idea.
 
  


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
[SOLVED] rm files only - retain directory structure schneidz Programming 15 05-30-2013 04:08 PM
How to copy an entire directory structure except certain files? thanhvn Programming 9 01-27-2012 11:41 AM
using tar to compress specific files in a directory named a certain way slinky66 Linux - Newbie 3 11-25-2009 01:31 PM
tar doesn't compress .hidden files in the same directory it is run in? BassKozz Linux - Newbie 2 06-02-2009 04:46 PM
Program files and directory structure Carel Linux - Newbie 5 04-11-2001 10:57 AM


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