Solved

Limit Unix find command to certain level

Posted on 2008-10-17
4
1,313 Views
Last Modified: 2013-12-21
I am using the Solaris Security Toolkit to harden my Unix server. However, one of the hardening script "print-rhosts.fin" takes between 4 -20 minutes to finish. This script is to capture all the ".hiosts" and "hosts.equiv" on the system. The main action within the script is the "find" command as:

find ${JASS_ROOT_DIR} ! -local -prune -o ( -name .rhosts -o -name hosts.equiv ) -ls

I think that .hosts and hosts.equiv most likley exist only at 2nd level from the root directoy such as /etc/.hosts and /etc/hosts.equiv.

So to reduce the time runing this script, I want to customize it. Is there a way to improve the find command so that it only search down maximum to the 2nd level. I know Linux has a option "-maxdept". Not sure Solaris has something equivalent. Please help!
0
Comment
Question by:gs_kanata
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:ghostdog74
ID: 22747175
change ${JASS_ROOT_DIR}  to /etc/
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22747251
what about users' home directories? they are usually at /export/home/username
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22747254
what about users' home directories? they are usually at /export/home/username? if it is /etc dir only then no need for the find command
0
 
LVL 5

Accepted Solution

by:
ifreq earned 500 total points
ID: 22747458
GNU find can do this with "-maxdepth 1", but Solaris find can't. To get the same functionality for Solaris find, you can use this hack: find /some/path/. \( -type d -a \! -name . -prune \) -o -type f -print

That is, first prune all directories that aren't named ".", then print the names of the remaining files. It's important that the path be "/some/path/." instead of "/some/path", because that's what enables special treatment for the top level directory.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: btan
The intent is not to repeat what many has know about Ransomware but more to join its dots of what is it, who are the victims, why it exists, when and how we respond on infection. Lastly, sum up in a glance to share such information with more to help…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question