
Does -prune work like -maxdepth in Unix "find" on AIX?
Dave, I purchased your Wicked Cool Shell Scripts book a month or so ago (great book), and have used it to "learn by example" in writing some shell scripts, as I've a long way to go in this area.
I need to rotate logs on an IBM AIX 5.1 Unix box, and tried using your script #55, rotatelogs for this but it didn't work, as -maxdepth is not supported in AIX's find command. So, I commented it out, and it worked, but also rotated everything in the subdirectories as well (no problem...backed up directory first, then restored). I am trying to get it to work using -prune which my search in Google found to be a good fix for the lack of –maxdepth, but it's not doing what I want. Help! Hmmm... I don't have access to an AIX Unix box, but are you sure that they don't have a copy of GNU find tucked away somewhere on the box? Try using something like find / -name "find" -print as root to see if there's more than one copy of the app on the system. I'm not sure that -prune is what you want, though. Here's what the find man page on my system says about it: -prune This primary always evaluates to true. It causes find to not descend into the current file. Note, the -prune primary has no effect if the -d option was specified. Is this a viable replacement for -maxdepth? When I run it the output isn't useful: $ find . -prune -print . $Hmmmm.... replacing the "." with a "*" proves interesting (yes, I'm making the find more interesting too, just matching files that are non-zero in size): $ find * -prune -type f -size +0c -print African Singing.aif Branding for Writers.doc GYBGCH12.doc KF BPlan-04-1123.doc Parent Night.aif Rahima Keynote.aif lumxtiger_outline final.doc master-adwords.pdf $Maybe that's what you need (ignore the specific files I have. You can see what I'm working on as this is my desktop. ;-) Try what I suggested, see what kind of results you get!
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.
Categorized:
Shell Script Programming
, Unix and Linux Help
(Article 3813)
Tagged: Previous: How do I get rid of Windows Security Alerts? Next: Can I use my Palm Desktop address book data in shell scripts? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. AIX find indeed does not have the -maxdepth flag option. The man page returns this for the -prune flag on my AIX 5.2 system. Only one find also, /usr/bin/find -prune Always evaluates to the value True. Stops the descent of the current path name if it is a directory. If the -depth flag is specified, the -prune flag is ignored. Posted by: Scott at December 17, 2004 2:59 PMSome "creative" use of grep / sed / awk applied against the find output should allow you to select only to a (selected) depth; given a relatively stable structure, you might also be as well off by driving from a stored list of directories instead of "building on the fly". Posted by: Mike C. Baker at February 11, 2005 4:04 PMWell yes, you can do this: find /tmp/* -prune which limits the search to only the /tmp directory (no subdirs). However, "/tmp/*" is evaluated by the shell before being passed to "find" and could possibly exceed the maximum allowed length. And while it is certainly possible to parse the output for the desired results, this does not stop the "find" command from needless searching. The find could be lengthy if the filesystem is large and/or over a network. Without a "maxdepth" option, the best way to list all files in a given directory is: (cd $DIR && find . ! -name . -prune) Other options to "find" can be added as needed, and the parentheses can be removed if the changedir is not bothersome. Posted by: Gus Schlachter at March 23, 2007 2:30 PMI have a lot to say, but ...
I do have a comment, now that you mention it!
|
Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|