?
Solved

Want to tar/gzip a few files into a specific directory structure?

Posted on 2011-09-16
6
Medium Priority
?
297 Views
Last Modified: 2012-05-12
Hello,

I have several images that I want to tar or gzip into specific directories.  For instance:
image1.png => my_images/image1.png
image2.png => thumbnail/image2.png

So basically I want to specify when creating the archive, "put these files in this directory in the archive and these files in another directory".

That is the first part of the question.  The second part is while uncompressing I want to also specify a different destination for all the files depending on the directory they are in.  If the second part is not possible I can uncompress them all and then just run copy commands for each specific file.

I'm doing this in PHP but I probably will end up calling a shell script to all of it.  Thanks for any help or advice!!
0
Comment
Question by:parlays
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 79

Accepted Solution

by:
arnold earned 1000 total points
ID: 36550887
The file has to be in the directory.

presumably you are appending data to an existing tar archive?
tar --append --file=oldarchive.tar my_images/image1.png
http://www.gnu.org/software/automake/manual/tar/appending-files.html
0
 
LVL 79

Expert Comment

by:arnold
ID: 36550943
Oh, it would be a two step process sine the append can only be done to the raw archive versus compressed one.

Not sure whether you can append a compresed tar archive entry into a Gziped file.
0
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 500 total points
ID: 36554031
Easiest way to do this is copy or move the files to the required directories first and then tar/gz the directories. Do you know which files need to go into which directory? Is there a pattern?

So you could do, assuming that the current directory is where the images are:

mkdir my_images thumbnails
mv <filepattern1> my_images/
mv <filepattern2> thumbnail/
tar cf images.tar my_images thumbnail
gzip images.tar

Open in new window


Note that <filepattern1> and <filepattern2> are somthing like image*.png and thumb*.png, depending on your filenames.

When uncompressing you can do it in a similar way by creating a tmp directory (t.t) first:

mkdir t.t
gunzip images.tar.gz
mv images.tar t.t/
cd t.t
tar xf images.tar
mv my_images/* <destination dir for images>/
mv  thumbnail/* <destination dir for thumbnails>/

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 19

Assisted Solution

by:xterm
xterm earned 500 total points
ID: 36581264
FYI, modern gnu tar has g(un)zip capabilities built-in, so you can save a few steps:

tar czf images.tar.gz my_images thumbnail

and

tar xzf images.tar.gz

(and omit the gzip/gunzip stuff)
0
 
LVL 79

Assisted Solution

by:arnold
arnold earned 1000 total points
ID: 36581691
While the gunzip/gzip option exist, it does not work with adding files into an existing archive.

i.e. the user has an existing archive into which directory/file needs to be added/appended.

tar -cf tarfile.tar somedirectory
tar -rf tarfile.tar somenewdirectory
0
 

Author Closing Comment

by:parlays
ID: 36582099
thanks everyone!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question