Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compress an entire directory

Status
Not open for further replies.

solvetek

Programmer
Jul 17, 2001
12
US
is there a utility or way to compress an entire directory?
 
Put everything in a tar file and then compress the tar file would be the best way. Do you need more info than that?

Greg.
 
You can tar and gzip all in one command, if you do use the -z argument. Since I was frustrated at having to constantly type:
Code:
tar -zpscf tarfilename directoryname
, I whipped up this little Perl utility which compresses an entire directory and names it after the directory, while appending the current date and time into the name:

Code:
#!/usr/bin/perl
$dir_in=shift(@ARGV);
chomp($dir_in);
print "Archiving $dir_in/* ...\n";
use POSIX qw(strftime);
$now_string = strftime "%m-%d-%Y_%H%M", localtime;
$tarname=$dir_in."_".$now_string.".tar.gz";
$execstring="tar -zpscf ".$tarname." ".$dir_in."/*";
#print($execstring); # for debugging...
exec($execstring);
print("\n");

I called this "rarch" for "recursive archiver", and placed it in /usr/local/bin. Now, let's say I have a directory called "htmlfiles", and I want to archive and compress the whole directory, and be able to tell at a glance exactly when I did this, I just go one level outside that directory and type "rarch htmlfiles" (without the trailing slash "/"). This creates a gzipped tarfile called htmlfiles_07-23-2001_1027.tar.gz (Assuming current time is 7/23/2001 at 10:27 AM)

Obviously, since this does not also use Seconds in the time, if you call this utility twice in less than a minute on the same directory, you will overwrite the last file. If you really want seconds, or even microseconds it's no trouble to add it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top