Solved

Limit Unix find command to certain level

Posted on 2008-10-17
4
1,315 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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

Many people tend to confuse the function of a virus with the one of adware, this misunderstanding of the basic of what each software is and how it operates causes users and organizations to take the wrong security measures that would protect them ag…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

717 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