1831340 Members
3599 Online
110024 Solutions
New Discussion

Finding files

 
SOLVED
Go to solution
akarayil
Frequent Advisor

Finding files

Dear Experts,

If I want to find the files which are modified (or created) 6 hours ago which option I can use along with find cmd.
OS: HPUX 11.23

In Linux, there is an option mmin, that works fine. This is not working in HPUX.

Do you have any solution?

regards
8 REPLIES 8
Dennis Handly
Acclaimed Contributor

Re: Finding files

That option isn't available, only -mtime for days. You need to create a reference file and use -newer. See this thread:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1227469
Victor Fridyev
Honored Contributor

Re: Finding files

Hi,

You can play with the touch command.

Create a file with time stamp 6 hours before current time :
touch -t YYMMDDhhmm /tmp/stamp
and run find / -newer /tmp/stamp

HTH
Entities are not to be multiplied beyond necessity - RTFM
Jeeshan
Honored Contributor

Re: Finding files

Hi

You can use the sample perl scriptd to find your criteria

perl -MFile::Find -le 'find(sub{print $File::Find::name if -f $_ && -M _ <= 6/24},@ARGV)' /path
a warrior never quits
akarayil
Frequent Advisor

Re: Finding files

Dear all
I'll give you a better picture of my problem.
I'm exporting the oracle DB every two hours. I want to keep only the last two or three backups,rest of the files should be removed. I'm using a script to automate this process, in witch I'm using mtime option to find the files. So, system keeps 12 copies of backup files and rest of the files are removed.

Regards
Rasheed Tamton
Honored Contributor
Solution

Re: Finding files

Hi,

You could use something like below:

find /path -exec ls -lrt {} +|head -3|xargs -i ls {}

If you have 12 files left while running the script and you want to keep 3 files from that then you have to change the head -3 to head -9

find /path -exec ls -lrt {} +|head -3|xargs -i rm {}

Just fine tune your current script using head command. Try with ls first and once you are satisfied replace it with rm.

You can also play with ls -lt and tail instead of ls-lrt and head.

Regards,
Rasheed Tamton.
Steven Schweda
Honored Contributor

Re: Finding files

> In Linux, there is an option mmin, that
> works fine. This is not working in HPUX.

It might work if you used GNU "find".

http://www.gnu.org/software/findutils/

You need something better than the PA-RISC
bundled C compiler to build it, but GCC can
do it, or you could probably find a pre-built
depot in the usual places.

dy # gfind --version
GNU find version 4.2.33
Built using GNU gnulib version 8e128ebf42e16c8631f971a68f188c30962818be
Features enabled: O_NOFOLLOW(enabled) LEAF_OPTIMISATION

dy # gfind . -mmin 5
./lib
./lib/regexprops

dy # uname -a
HP-UX dy B.11.11 U 9000/785 2012616114 unlimited-user license

The same holds true for most Linux tools,
which are, in fact, GNU tools (running on
GNU/Linux).
Victor Fridyev
Honored Contributor

Re: Finding files

Hi,

If you want to delete all, except two (or three) backups, you can run the following in the directory where your exports are located:

ls -1t export* | awk 'NR>2 {system("rm " $1)}'

HTH
Entities are not to be multiplied beyond necessity - RTFM
akarayil
Frequent Advisor

Re: Finding files

I thank all of you.
I got the solution from Mr.Rasheed's suggestion. I implemented the same.

Once again, Thank you very much.

with best regards