- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need script help with "find" command
Categories
Company
Local Language
Forums
Discussions
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Knowledge Base
Forums
Discussions
- Cloud Mentoring and Education
- Software - General
- HPE OneView
- HPE Ezmeral Software platform
- HPE OpsRamp
Knowledge Base
Discussions
Forums
Discussions
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
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
02-08-2002 01:32 PM
02-08-2002 01:32 PM
I thought I had a good start with the following find statement:
===========
find /main_dir \( -name 'M.*' \) -mtime +1 -exec mv {} /main_dir/hist \;
===========
But the -mtime +1 doesn't move yesterday's dated files.
How can I accomplish what I need?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2002 01:37 PM
02-08-2002 01:37 PM
Re: Need script help with "find" command
Change your +1 to +0. Also, you MAY want to restrict to regular files only; int that case add the -type f argument as well.
It is always a good idea to replace a potentially hazardous command with an innocuous command like -exec echo {} \; before doing the real thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2002 01:38 PM
02-08-2002 01:38 PM
Re: Need script help with "find" command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2002 01:40 PM
02-08-2002 01:40 PM
Re: Need script help with "find" command
Use '+0' instead of '+1'
find . -mtime +0 ......
HTH,
Shiju
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2002 01:44 PM
02-08-2002 01:44 PM
Re: Need script help with "find" command
Yet another useful method is to use the '-newer' argument with a reference file that you create with a date and time to granularize your returns:
# touch -mt 200202081648 /tmp/ref
# find /dir -type f -newer /tmp/ref
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2002 01:55 PM
02-08-2002 01:55 PM
Re: Need script help with "find" command
However, the script is also trying to move files I've already moved to the /main/hist directory again, and I'm getting errors that I'm trying to mv files on top of each other...how do I just move files directly under /main and not further subdirectories down?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2002 02:23 PM
02-08-2002 02:23 PM
Re: Need script help with "find" command
DATE=`date +%m%d%y`
mv filename filename.$DATE
thus when you do searches you could key of the date and only move files without a date stamp.
Just a thought,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2002 02:46 PM
02-08-2002 02:46 PM
SolutionTo add to the "newer" idea...
"-mtime +0" will tell find to select files older than 24 hours ago. If you run that find command at 3pm you will miss all files created yesterday between 3pm and midnight.
To get all files older than today, use a reference file and "not" logic with the "-newer" arg:
touch `date +%m%d`0000 /tmp/ref
find /main ! -newer /tmp/ref
Use the appropriate "-name" args to get the files you want. Also note /tmp/ref would be selected by "! -newer" if it was in /main.
To keep from moving files in subdirectories of /main, you could capture find's output to a file, use grep, awk, sed, or whatever to select only files in /main itself. But since you want files that have an earlier date than today and if files don't have a future date you could do:
DTE=`date '+%b %e'`
for file in `ll /main | grep -v "$DTE" | grep -v total | grep ^- | awk '{print $NF}'`
do
mv /main/$file /main/hist/$file
done
This selects regular files (grep ^-), omits ll's total line, and omits files with todays date. Of course, files dated a year or years ago today would be omitted also.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2002 07:16 PM
02-08-2002 07:16 PM
Re: Need script help with "find" command
You can use this script:
find /main_dir \( -name 'M.*' \) -mtime +1 -print > /tmp/tmpfile
while read file
do
file1=`echo $file | cut -d/ -f3`
if [ "$file1" != "hist" ] ; then
mv $file /main_dir/hist/$file1
fi
done < /tmp/tmpfile
Hope this helps.
Kenny.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2002 08:01 PM
02-08-2002 08:01 PM
Re: Need script help with "find" command
>> ...how do I just move files directly under /main and not further subdirectories down?
Use the -prune option in find.
If the current entry is a directory, prune will cause find to skip that directory. This can be useful to avoid walking certain directories, or to avoid recursive loops.
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2002 10:00 AM
02-09-2002 10:00 AM
Re: Need script help with "find" command
find /main_dir \( -name 'M.*' \) -mtime +0 |
grep -v "\/main_dir\/hist" |
xargs -i mv {} /main_dir/hist
live free or fir
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2002 11:54 PM
02-10-2002 11:54 PM
Re: Need script help with "find" command
For your information
The -mtime option is based upon
"-1" last 24 hours,
"1" between 24 and 48 hours
"+1" 48 or more hours old.
the full explanation of the argument n is
in the man page under expressions and your
HP-UX Reference at www.docs.hp.com .
Steve Steel