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 |
%
|
|---|
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 ) .
-