start page | rating of books | rating of authors | reviews | copyrights

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:

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 gzipped (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 ToolsNext: 24.13 Save Space in Executable Files with strip
24.11 Edit Compressed Files with zvi, zex, and zed Book Index24.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