How to tar a directory?

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
Sinemacula
Forum Contributor
Posts: 110
Joined: Sat Feb 08, 2003 2:36 am
Location: San Jose, CA

How to tar a directory?

Post by Sinemacula »

I've done a search here and discovered that I can't gzip a whole directory - that I have to tar it first... but I can't seem to find any examples of how to tar a directory.

Ideally, I'd like to tar the directory, then gzip it appending the date to the filename, and place the gzip file in another directory.

Any pointers or sample code I could use as a start?

Thanks,
Scott
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

What's not explained in man tar?

Here's how i do it:

Code: Select all

# generate tar-gzipped archive of homedirectory
tar -czf /tmp/backup.tgz ~

# move backup to homedirectory and change name
mv /tmp/backup.tgz ~/madoka-`date +%F`.tgz
Sinemacula
Forum Contributor
Posts: 110
Joined: Sat Feb 08, 2003 2:36 am
Location: San Jose, CA

Post by Sinemacula »

Thanks, timvw...

I hadn't looked at the man entry (not being much of a command-line user, it didn't occur to me)... but does it show how to make that work in a php script?

Here are some more details to help clarify what I'm looking for:

I've got a php script that pulls data from a mysql database and creates a separate file for each record and puts them all in directory1. What I want is for that same script to then tar and gzip directory1 and put the resulting archive in directory2.

Ideally, the script will then delete all the individual files in directory1 (but leaving directory1 itself).

So, what I need is to know if this is possible within a php script?

I have found some sample php code that will allow me to gzip a file and put the archive in a different directory, but I need something that will do a whole directory.

Thanks,
Scott
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Moved to .. Linux! :roll:
Sinemacula
Forum Contributor
Posts: 110
Joined: Sat Feb 08, 2003 2:36 am
Location: San Jose, CA

Post by Sinemacula »

Actually, although the answer was for the command line, what I was looking for was php code.

However, the problem has been solved by the zip class in Code Snippets (which you pointed me to in another thread - thanks!)
Post Reply