- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Powerfull Find
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2008 04:36 AM
09-21-2008 04:36 AM
Good day,
I have an issue with find command I would like to find files older than 2 days and move them to specific location. The issue is I want to build the exact same tree in the destination directory.
For example, I want to search /var/LOGS and move anything older than two days to /backup/var/LOGS. If there was a sub directories in the source I want to create it in the destination.
Regards,
Solved! Go to Solution.
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2008 04:52 AM
09-21-2008 04:52 AM
Re: Powerfull Find
try this command
#find /var/LOGS -type f -mtime +7 -exec mv -r {} /backup/var/LOGS \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2008 04:54 AM
09-21-2008 04:54 AM
Re: Powerfull Find
#find /var/LOGS -type f -mtime +2 -exec mv -r {} /backup/var/LOGS \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2008 05:21 AM
09-21-2008 05:21 AM
Re: Powerfull Find
# cd /var
# find ./LOGS -depth -mtime +2 -print | cpio -pudlvm /backup/var
...will *copy* and replicate the directory/file structure in the destination directory. You will then need to remove what you don't want from the source tree in a separate pass.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2008 11:53 AM
09-21-2008 11:53 AM
Re: Powerfull Find
Starting from Ahsan's basic find:
find /var/LOGS -type f -mtime +2 -exec fancy_script {} +
Then create fancy_script:
#!/usr/bin/ksh
# Move files to /backup, keeping directory paths
for file in $*; do
mkdir -p /backup/$(dirname $file)
mv $file /backup/$file
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2008 11:03 PM
09-21-2008 11:03 PM
Re: Powerfull Find
Dear ahsan, mv doesn't have -r option it's only in cp.
Dears Dennis Handly and James R. Ferguson, I have this idea already, creating a script and calling it from find command. the script will use cp -r -p $1 $2 to create the specific tree. but I want to use mv command. This solution is very good but I prefer mv.
FANCY SCRIPT :
cp -r -p $1 $2
rm $1
FIND COMMAND :
find /var/LOGS -type f -mtime +2 -exec FANCY_SCRIPT {} /backup/var/LOGS-DATE \;
Any suggestion.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2008 11:32 PM
09-21-2008 11:32 PM
Re: Powerfull Find
Step 1. Copy the entire directory structure to the new location. Including the files you don't want.
"cp -r" or "cp -p -r" to preserve permisssions
Step 2. Nuke the files from the new structure which you don't want.
I'd test this out first by replacing rm with ls -l just to make certain....I don't have a system to test this on today and this is from memory.
Example:
Find files in current directory only older than June 3rd 2008
1. Create reference file
touch -t 200806030000 /tmp/june3.ref
Format of the numeric is YYYYMMDDHHMM
- use some logic in the script to calculate proper value to represent 2 days agos. I like this because you can control it down to the minute.
2 Run the command
find ./loc/A/* ! -type d ! -newer /tmp/june3.ref -exec rm {} \;
If you like it then stick this in a script to automate.
I'll try to find my script which has all the little things like calculating the date etc for the touch command. But it'll be a few days.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2008 11:47 PM
09-21-2008 11:47 PM
Re: Powerfull Find
The previous example I put in goes into sub-directories.
However if at some point you only want to process the current directory stick in the -prune argument
find ./loc/A/* -prune ! -type d ! -newer /tmp/june3.ref -exec rm {} \;
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2008 12:14 AM
09-22-2008 12:14 AM
Re: Powerfull Find
A word of caution.
All it takes is about 4 finds starting out at root to totally bring even a powerful system to its knees.
Use carefully, preferably one at a time.
Very interesting thread.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2008 01:19 AM
09-22-2008 01:19 AM
Re: Powerfull Find
My script already does mv(1). What's wrong with it? It will only create the needed parts of the tree.
>find /var/LOGS -type f -mtime +2 -exec FANCY_SCRIPT {} /backup/var/LOGS-DATE \;
If you are changing the path in your target, then you'll need to fiddle with my script a little:
find /var/LOGS -type f -mtime +2 -exec FANCY_SCRIPT /backup/var/LOGS-DATE {} +
FANCY_SCRIPT:
#!/usr/bin/ksh
TARGET=$1
shift
for file in $*; do
mkdir -p $TARGET/$(dirname $file)
mv $file $TARGET/$file
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2008 03:41 AM
09-22-2008 03:41 AM
Re: Powerfull Find
> Dears Dennis Handly and James R. Ferguson, I have this idea already, creating a script and calling it from find command.
Well, that's exactly what Dennis suggested originally to you! I presented an alternative, less direct answer to your original query (using 'find' and a pipe to 'cpio'). I think you have everything you need to make your decision.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2008 10:47 AM
09-22-2008 10:47 AM
Re: Powerfull Find
Dear Kevin, I would like to ask you about the "!" mark. if you put it before -newer option is it mean find older files not newer onec ?
I think I can solve this by moving the all directory to temporary directory and then find all the files newer than certain date as Kevin suggest and the returen those back with there directories to source directory. doing this I can save a lot of I/O because I'm dealing with more than 2,500,000 files.
-----------------
Again Kevin, thank for -prune option, I will write tomorowo script that have to go to every directory and count the number of files. So, I think this can help me with find.
-----------------
Dear JRF, I will read more about cpio, and feedback soon.
Thanks all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2008 10:54 AM
09-22-2008 10:54 AM
Re: Powerfull Find
The opposite of newer is "NOT newer". Which is older or the same time.
>I think I can solve this by moving the all directory to temporary directory
What's wrong with my "mv" solution? (You can still use -newer if you want.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2008 10:31 PM
10-26-2008 10:31 PM
Re: Powerfull Find
I would like to ask about -mtime option.
In case you need to take all the files that were modified more than to days you need to use "-mtime +2". But this actually not finding all the files. Is this happened with you guys?
I have to put another find with -mtime 2 option to achieve my goal.
Any ideas ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2008 11:05 PM
10-26-2008 11:05 PM
Re: Powerfull Find
What's your goal? -mtime +2 should be all files modified more than 2*24 hours ago.
Have you read find(1)?
http://docs.hp.com/en/B2355-60130/find.1.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2008 01:40 AM
10-27-2008 01:40 AM
Re: Powerfull Find
I want to know the difference between -mtime 1 & -mtime +1. In Sun +1 mean find all files that modified time is more than 24 hour.
Look at this:
touch -t 0810250000 file
touch -t 0810260000 file1
touch -t 0810270000 file2
touch -mt 0810270000 file3
touch -mt 0810260000 file4
#ls :
Oct 25 00:00 file
Oct 26 00:00 file1
Oct 26 00:00 file4
Oct 27 00:00 file2
Oct 27 00:00 file3
# find . -mtime +1
./file
# find . -mtime 1
./file1
./file4
----
I think "find . -mtime +1" suppose to display "find . -mtime 1" result.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2008 01:54 AM
10-27-2008 01:54 AM
Re: Powerfull Find
+n means more than n, -n means less than n, and n means exactly n.
here it is n * 24 hours.
Aneesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2008 02:28 AM
10-27-2008 02:28 AM
Re: Powerfull Find
So why the first command didn't find ./file1 , ./file4 files ?
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2008 03:25 AM
10-27-2008 03:25 AM
Re: Powerfull Find
Try #find . -mtime +0 you will get it .
fyi:-
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.
Aneesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2008 04:56 AM
10-27-2008 04:56 AM
Re: Powerfull Find
How can we tell if you don't tell us what time it is?
From find(1) there is a 24 hour fuzziness in -mtime n, perhaps there is for +n?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2008 06:26 PM
10-27-2008 06:26 PM
Solutiontime is now 27:1800
25:0000 2*24:1800 26:0000 1*24:1800 27:0000 0*24:1800
file X file1 X file2 NOW
Default: takes time / day and truncates
2 X 1 X 0
+0 X +0 X X
+1 X X X -1
UNIX95: takes time in seconds and compares N thru N-1 as =, - as < N-1, + as > N
file X file1 X file2 NOW
3 X 2 X 1
+0 X +0 X +0
+1 X +1 X X
+2 X X X -2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2008 10:05 PM
11-11-2008 10:05 PM
Re: Powerfull Find
http://forums.itrc.hp.com/service/forums/helptips.do?#33
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2008 02:10 AM
11-12-2008 02:10 AM
Re: Powerfull Find
I didn't understand your last example, can you explain it a little.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2008 04:56 AM
11-12-2008 04:56 AM
Re: Powerfull Find
Which parts? How find(1) works with and without UNIX95?
Default:
25:0000 2*24:1800 26:0000 1*24:1800 27:0000 0*24:1800
This is a timeline, Oct 25, 0000; a time 2 days ago at 1800; then Oct 26, ... Oct 27, then "now at Oct 27, 1800.
Default: takes time / day and truncates
With UNIX95, it does this fuzzy compare that is documented in find(1).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2008 05:29 AM
11-12-2008 05:29 AM
Re: Powerfull Find
> Dennis: With UNIX95, it does this fuzzy compare that is documented in find(1).
And just where in the HP-UX manpages did you find [ no pun intended ] that? I can't seem to locate a reference to either XPG4 or UNIX95 that points at this logic. The GNU Linux manpages are a bit more explicit in stating that "... When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored..."
Regards!
...JRF...