Good Day.

I am creating a script that moves all 'logA' files in a certain folder and adds timestamp every 3 hours, afterwards it will be zipped.

This is the base of the script:

cd /logs
mv *logA+timestamp /backupDIR
cd /backupDIR

--then the GZIP part--

Since it will run every 3 hours, there will be a time there are already .gzip files in the /backupDIR. Sample:


How can I exclude the already zipped file in the script? Should I do loop that will check if there are still .logA+timestamp?

2 Answers 2


The gzip program already does this for you: It refuses to zip .gz files with

gzip: <file>.gz already has .gz suffix -- unchanged

So you don't need to exclude the already zipped files.
To suppress the error message, use gzip -q.


Since you haven't provided the gzip command you are running, I'm going to assume you are doing something trivial along the lines of gzip * or gzip someprefix*, and these will probably work in the majority of circumstances (taking note of Juergen's answer.)

However, if there are lots of files in the directory that you don't want to consider (and only a few that you do) it could cause an issue with parameter exhaustion (and/or a small speed hit while gzip is figuring out which files to work with).

There are numerous ways to tackle that, here's one:

find /backupDIR -type f ! -name '*.gz' -print0 | xargs -0 gzip

If you have sub directories that you don't want to traverse amend as follows:

find /backupDIR -maxdepth 1 -type f ! -name '*.gz' -print0 | xargs -0 gzip

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .