home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 24.11 Edit Compressed Files with zvi, zex, and zed Chapter 24
Other Ways to Get Disk Space
Next: 24.13 Save Space in Executable Files with strip
 

24.12 Compressing a Directory Tree: Fine-Tuning

Here's a quick little command that will compress (24.7 ) files in the current directory and below. It uses find (17.2 ) to find the files, recursively, and pick the files it should compress:

-size
 xargs
 
% find . ! -perm -0100 -size +1 -type f -print | xargs gzip -v

This command finds all files that:

  • Are not executable (!  -perm  -0100 ), so we don't compress shell scripts and other program files.

  • Are bigger than one block, since it won't save any disk space to compress a file that takes one disk block or less. But, depending on your filesystem, the -size +1 may not really match files that are one block long. You may need to use -size +2 , -size +1024c , or something else.

  • Are regular files (-type  f ) and not directories, named pipes, etc.

The -v switch to gzip tells you the names of the files and how much they're being compressed. If your system doesn't have xargs , use:

% find . ! -perm -0100 -size +1 -type f -exec gzip -v {} \;

Tune the find expressions to do what you want. Here are some ideas - for more, read your system's find manual page:

! -name \*.gz

Skip any file that's already gzip ped (filename ends with .gz  ).

-links 1

Only compress files that have no other (hard) links.

-user  yourname

Only compress files that belong to you.

-atime +60

Only compress files that haven't been accessed (read, edited, etc.) for more than 60 days.

You might want to put this in a job that's run every month or so by at (40.3 ) or cron (40.12 ) .

- JP


Previous: 24.11 Edit Compressed Files with zvi, zex, and zed UNIX Power Tools Next: 24.13 Save Space in Executable Files with strip
24.11 Edit Compressed Files with zvi, zex, and zed Book Index 24.13 Save Space in Executable Files with strip

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System