Solved

Limit Unix find command to certain level

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Doing a DR (Disaster Recovery) Test on Red Hat Linux Servers. 2 100
Unix Question 19 45
MarkLogic 1 69
Login to computer through Admin Priviligies 9 88
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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…
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.:
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now