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

Unix Power ToolsUnix Power ToolsSearch this book

15.9. Compressing a Directory Tree: Fine-Tuning

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

-sizeSection 9.14, xargs Section 28.17

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

This command finds all files that are the following:

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 the following:

% 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 (Section 25.5) or cron (Section 25.2).

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.