Solved

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

Posted on 2011-09-16
6
280 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
6 Comments
 
LVL 77

Accepted Solution

by:
arnold earned 250 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 77

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 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 125 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 19

Assisted Solution

by:xterm
xterm earned 125 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 77

Assisted Solution

by:arnold
arnold earned 250 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
The viewer will learn how to count occurrences of each item in an array.

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now