Compress or move multiple files

what is the compress syntax for compressing multiple files for a specific date?

Archive log space is filling up and I need to compress and move the files.  Syntax can be either compress or move?

Who is Participating?
ahoffmannConnect With a Mentor Commented:
> -mtime 42 -exec gzip {}\;     when I typed this in it went to a > prompt   and nothing happened.
what should this do?

> ..  my Unix does not recognize -mtime.
Please read
  man find

which Unix do you have? there should be at least one option for find similar to -mtime
find /path/to/files -mtime 42 -exec gzip {} \;
# compresses files older than 42 days
mjimison1956Author Commented:
I am receiving error that my Unix does not recognize -mtime.

I changed directories to the location of the archive logs and typed in

-mtime 42 -exec gzip {}\;     when I typed this in it went to a > prompt   and nothing happened.

Any ideas?  I did a man on mtime.... not recognized.

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

mjimison1956Author Commented:
HP-UX B.11.11 U(64) is the OS

here is what I found on the man find reference time:

-mtime n                 True if the file modification time subtracted
                         from the initialization time is n-1 to n
                         multiples of 24 h.  The initialization time
                         shall be a time between the invocation of the
                         find utility and the first access by that
                         invocation of the find utility to any file
                         specified in its path operands.

-ctime n                 True if the time of last change of file
                         status information subtracted from the
                         initialization time is n-1 to n multiples of
                         24 h.  The initialization time shall be a
                         time between the invocation of the find
                         utility and the first access by that
                         invocation of the find utility to any file
                         specified by its path operands.
You were missing the find statement!

Read again, should be

find /path/to/die -mtime 42 -exec gzip {} \;

Note that the space after {} is important.
For old then 42 days you should use:
  42 - means exactly 42 day
  -42  less than 42 day

  man find

  I would put all the file in tar ball then  gzip the tar ball

  tar cf /path-to/backup.tar `find /path/to/die -mtime +42`
  gzip /path-to/backup.tar

  If you have GNU tar installed in your system, you can do:
  (assume you installed it in /usr/local/bin):

    /usr/local/bin/tar -zcvf /path-to/backup.tar.gz `find /path/to/die -mtime +42`

 You can download GUN tar binary package for HP-UX from:
  (remember to install all the dependencie)
we have some housekeeping scripts, Ive setup a config file whereby u can select what directory and what action to do in a number of days
e.g. archive all files in directory /fred that are over 15days old

basically the command built up is how ahoffman has described.

But the answer supplied by ahoffman works and works fine. If u use that correctly and put in your parameters, you will see it works.

The only additions I have to this is

1. I only check for files. If I have data directories that need archiving, I don't archive the directory, just the files inside it
2. I use -f on gzip to force the compression otherwise, if u try to compress to a file that already exists, then it won't do it


find /fred/data -mtime +15 -type f -name 'fred*.log'  -exec gzip -f {} \;

u say u want to compress and move the files, is that right?
I guess u can then find file types of .gz and exec mv
after u run the first find

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.