HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Find files which were modified for a period of 3 days and eliminate /opt, /var, tmp, /usr & stand

 
SOLVED
Go to solution
Kennedy G. Doss
Regular Advisor

Find files which were modified for a period of 3 days and eliminate /opt, /var, tmp, /usr & stand

HP-UX SAs:

I am trying to list out files which were modified on Feb 17, 18, 19th and then, eliminate files from /opt, /var, /tmp, /usr and /stand. Can I achieve it using the "find" string? (Or anyother reliable means) There are atleast 40,000 files therefore, I do not want to eliminate it manually. I was able to achive the first part of my question with the syntax, "# find / -mtime +20 -mtime -23 -exec ls -ltr {} \;", but I am unable to eliminate the listing of the files from the filesystems mentioned above. Any suggestions?
9 REPLIES
James R. Ferguson
Acclaimed Contributor
Solution

Re: Find files which were modified for a period of 3 days and eliminate /opt, /var, tmp, /usr & stand

Hi:

Are you attmepting to examine '/' without visiting mountpoints? If so, add '-xdev' as:

# find / -xdev ...

As for a range of dates, you can do:

# touch -amt 02170000.00 /tmp/ref1
# touch -amt 02192359.59
# find / -xdev -type f -newer /tmp/ref1 ! -newer /tmp/ref2 -exec ls -lt {} +

Regards!

...JRF...
Torsten.
Acclaimed Contributor

Re: Find files which were modified for a period of 3 days and eliminate /opt, /var, tmp, /usr & stand

list out files which were modified on Feb 17, 18, 19th and then, eliminate files from /opt, /var, /tmp, /usr and /stand.

This sounds dangerous.
What if you delete the active and the backup kernel or other important files?

Why do you want to do this?

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Pete Randall
Outstanding Contributor

Re: Find files which were modified for a period of 3 days and eliminate /opt, /var, tmp, /usr & stand

I might be tempted to just list the directories you're willing to visit, using the -newer and ! -newer options as James points out:

find /home /mydir /myotherdir -type f -newer . . . . . .


Pete


Pete
Kennedy G. Doss
Regular Advisor

Re: Find files which were modified for a period of 3 days and eliminate /opt, /var, tmp, /usr & stand

Just want to be a little more specific:

I do not intend to eliminate the files from /var, /tmp etc. etc from the server. I just want to get a file list and eliminate files from the listing. (I will use the file listing to perform a restore another server. -That is why I dont need /var, /tmp, /, /stand etc. etc.)

Re: Find files which were modified for a period of 3 days and eliminate /opt, /var, tmp, /usr & stand

You can do it various ways.
1) You can pipe it to grep to exclude those names.
2) You can only use find on the filesystems that you want.
3) You can use ! -path to exclude those names.
4) The most efficient would be to use -prune on those directories. (Unfortunately the syntax is complicated.)

You also want to replace that "\;" by "+" and add -d to your ls, or use "-type f".

>Torsten: What if you delete the active and the backup kernel or other important files?

I assume by "eliminate" he meant exclude, not print.
Michael Mike Reaser
Valued Contributor

Re: Find files which were modified for a period of 3 days and eliminate /opt, /var, tmp, /usr & stand

Try

find / -mtime +20 -mtime -23 | grep -v -e ^/opt/ -e ^/var/ -e ^/tmp/ -e ^/usr/ -e ^/stand/

This should produce a list of files without any from the file systems you mentioned, while leaving all other mount points in the listing.
There's no place like 127.0.0.1

HP-Server-Literate since 1979

Re: Find files which were modified for a period of 3 days and eliminate /opt, /var, tmp, /usr & stand

Here is how to use -prune:
find / -name opt -prune -o -name var -prune -o -name tmp -prune -o \
-name usr -prune -o -name stand -o \
-mtime +20 -mtime -23 -exec ls -dltr {} +

Re: Find files which were modified for a period of 3 days and eliminate /opt, /var, tmp, /usr & stand

# find / -mtime +20 -mtime -23

The problem with -mtime is that it changes every second you delay and it based on the time when you execute the command. It also truncates to a 24 hour period. So JRF's touch may be better.
Arturo Galbiati
Esteemed Contributor

Re: Find files which were modified for a period of 3 days and eliminate /opt, /var, tmp, /usr & stand

Hi,
touch -amt 02170000.00 /tmp/mon-date
touch -amt 02192359.59 /tmp/max-date
find / -name opt -prune \
-o -name var -prune \
-o -name tmp -prune \
-o -name usr -prune \
-o -name stand -prune \
-xdev -type f \
-newer /tmp/min-date \
! -newer /tmp/max-date -exec ls -lt {} +

HTH,
Art