Solved

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

Posted on 2011-09-16
6
294 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 78

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 78

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 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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 78

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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