- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: using "find" without looking into subdirectori...
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
10-08-2008 12:12 PM
10-08-2008 12:12 PM
Below will not work for me:
cd /home/mahrendt
find . -type f -newer /tmp/frog -print
and from "man find" its seems that I could use "-prune" but have not been able to get that to work...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 12:23 PM
10-08-2008 12:23 PM
Re: using "find" without looking into subdirectories
ls -lrt >/tmp/file.lst
vi /tmp/file.lst to find frog, then remove all above frog line, you get the list of files younger than frog. Hope it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 12:32 PM
10-08-2008 12:32 PM
SolutionI have little luck with '-prune' on HP-UX's 'find'. Since you want to confine yourself to one directory level, you can do the following:
# cd /home/mahrendt
# ls -l|grep "^-"|while read X X X X X X X X FILE;do [ ${FILE} -nt /tmp/frog ] && echo ${FILE};done
This looks for regular files only and compares them to be newer ('-nt') or not to your "/tmp/frog" reference file.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 02:43 PM
10-08-2008 02:43 PM
Re: using "find" without looking into subdirectories
dy # ls -lR
total 16
-rw-r--r-- 1 root sys 4 Oct 8 17:23 aaa
drwxr-xr-x 2 root sys 96 Oct 8 17:23 sub-dir
./sub-dir:
total 16
-rw-r--r-- 1 root sys 4 Oct 8 17:23 bbb
dy # /usr/local/bin/find . -maxdepth 1
.
./aaa
./sub-dir
dy # /usr/local/bin/find . -maxdepth 1 ! -type d
./aaa
dy #
http://www.gnu.org/software/findutils/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 07:34 PM
10-08-2008 07:34 PM
Re: using "find" without looking into subdirectories
>> How can I use the "find" command (if this even even the best appraoch)
Whether it is the nest approache depends on what you want to do with the file, once you found it. The -exec options do not always allow to one to express things like renames.
So one ooften ends up just printing the names to re-read and do something with them.
Tools like perl could take immediate action.
Starting point:
perl -le '$ref = -M q(/tmp/frog); for $file (<*>) { print $file if -M $file < $ref }'
The <*> is a 'glob' function for all files. Ammend as desired.
The -M is fractional days since last modification.
And yes, perl has a file::find extention.
And no, it does not appear to have an easy maxdepth.
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 08:12 PM
10-08-2008 08:12 PM
Re: using "find" without looking into subdirectories
Right, we need better examples. :-(
This works if not too many files:
find * -type f -newer /tmp/frog -prune
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2008 07:22 AM
10-09-2008 07:22 AM
Re: using "find" without looking into subdirectories
James: Very helpful work-around to the "find" issue ...I used you code to get version 1 of my script working
Steve: The GNU "find" is exactly what I need ...just will have to incorporate it into a later/final version of my script (when I get to installing that program)
Hein: Your perl feedback was very helpful as it almost did what the code James posted ....except that it also listed the subdirectories. As you stated its a starting point, so most likely this will be in version 2 of my script because its perl ;)
Dennis: Thanks for the response but I never got "-prune" to work within a directory of 6 files and 1 subdirectory (having 2 files)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2008 08:05 AM
10-09-2008 08:05 AM
Re: using "find" without looking into subdirectories
Excellent. Indeed I did not show how to test for 'normal file'.
In perl that is the -f operator/function.
By default it acts on the default variable $_.
perl -le '$ref = -M q(x.pl); for (<*>) { next unless -f; print if -M $_ < $ref }'
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2008 09:36 AM
10-09-2008 09:36 AM
Re: using "find" without looking into subdirectories
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2008 12:33 PM
10-09-2008 12:33 PM
Re: using "find" without looking into subdirectories
Laurent: WOW, you addressed my initial hangup with "find"!! your options work perfectly and obviously "man find" made more sense to you than me ...can you explain/translate the command line options you used?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2008 04:19 PM
10-09-2008 04:19 PM
Re: using "find" without looking into subdirectories
You need to use the "*". But Laurent's solution works better.
>you addressed my initial hangup with "find"!! your options work perfectly and obviously "man find" made more sense to you than me. Can you explain/translate the command line options you used?
Unfortunately this isn't obvious in the man page. I.e. it is useless to use -prune unless there is that OR involved. Basically it now seems obvious. ;-)
\( -type f -o -name . -o -prune \) ...
This says to return true if it is a file, or the name is "." OR -prune (which is always true). Then AND that with the rest of the options.
What the fine print is really saying is that if it is a file or it is ".", do NOT do the prune actions, so it will look into ".".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2008 02:07 AM
10-10-2008 02:07 AM
Re: using "find" without looking into subdirectories
Example:
Find files in current directory (/loc/A) older than June 3rd 2008
1. Create reference file
touch -t 200806030000 /tmp/june3.ref
2 Run the command
find /loc/A/* -prune ! -type d ! -newer /tmp/june3.ref -exec ls {} \;
This has always worked for me regardless of the number of files. In your case simply my reference file /tmp/june3.ref with /tmp/frog and /loc/A with /home/mahrendt.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2008 02:39 AM
10-10-2008 02:39 AM
Re: using "find" without looking into subdirectories
About:
find /loc/A/* -prune ...
The side effect is it doesn't show files begining with .
so better:
find /loc/A/* /loc/A/.?* ....
.?* can match with .. but .. -prune will stop at .. so it is ok too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2008 07:17 PM
10-10-2008 07:17 PM
Re: using "find" without looking into subdirectories
This is an unhelpful statement. The correct statement is: I can see how using "*" would fail with zillions of files. The shell would have trouble expanding the command.
(I.e. first create a zillion files in your directory. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2008 07:01 AM
10-13-2008 07:01 AM
Re: using "find" without looking into subdirectories
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2008 11:01 PM
10-13-2008 11:01 PM
Re: using "find" without looking into subdirectories
But good point and I wonder if you'd know what would be the limitation of the find command I suggested? ...or a good guess anyways.
The command I provided is the one I use when other commands come up with "Arg list too long". And that find command has always been my fix....but when will it fail would be good to know.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2008 04:09 AM
10-14-2008 04:09 AM
Re: using "find" without looking into subdirectories
> know.
OS- and/or shell-dependent.
> And that find command has always been my
> fix.
A _good_ "find" command is one which does not
require the shell to expand a wildcard file
name specification. One of the primary
reasons to use "find" is to avoid a too-long
command line. Using "*" as a file spec in a
"find" command rather defeats that purpose,
making it not much of a "fix", in general.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2008 04:21 AM
10-14-2008 04:21 AM
Re: using "find" without looking into subdirectories
> Kevin: But good point and I wonder if you'd know what would be the limitation of the find command I suggested?
It is the shell that expands your "*" and this leads to a too large (long) list of arguments that then can't be passed. To see this, simply do sompething like:
# cd /var/adm/sw && echo *
You can prevent the shell from expanding if you did:
# set -f
# cd /var/adm/sw && echo
# set +f #...reset normal behavior...
Now, to find out how large is the largest (limit), simply ask your system:
# getconf ARG_MAX
2048000
This is the maximum length of the arguments for exec() in bytes, including environment data.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2008 11:00 PM
10-15-2008 11:00 PM
Re: using "find" without looking into subdirectories
Too bad I don't own the thread or I'd assign points.
Cheers