Solved

Limit Unix find command to certain level

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
antivirus on mac 8 79
PCI scan - CIFS NULL Session Permitted 10 149
Writing a UNIX script menu allowing for multiple options. 5 85
Sweet32 Vulnerability in Microsoft IIS7.5 6 893
The term "Bad USB" is a buzz word that is usually used when talking about attacks on computer systems that involve USB devices. In this article, I will show what possibilities modern windows systems (win8.x and win10) offer to fight these attacks wi…
Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
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.

790 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