Making a shell script...

Lowell Gilbert freebsd-questions-local at
Mon May 12 12:14:12 PDT 2003

"Xpression" <admin at> writes:

>             I try to make a script to rotate some log files every month,
> file must be appear like this   (Month-Year.tgz)...the question is: how can
> I compress all files in a sub-dir that contains many sub-dirs without
> compress sub-dirs too...sample:
> /mydir/one-dir
>           /another-one
>           file1
>           file2
>           file3
> I try to tar & compress file[1..3] without compress /one-dir, /another-one
> directories...I'm already looked at man pages without a response...thanks

This is what newsyslog(8) is for, but test(1) is what you're looking
for.  There may be a builtin version in your shell, but you can get
the one from the man page by specifying /bin/test.

Something like 

for fil in * ; 
    if test -f $fil ; 
        then gzip $fil

[untested, and the syntax is for sh-style shells]

More information about the freebsd-questions mailing list