Link to home
Start Free TrialLog in
Avatar of new_perl_user
new_perl_user

asked on

File Grep in unix

Hi,

Can anyone help me with a code snippet to search for a file  recursively in Dir/sub dir and if it is not then print that sub dire name.
Avatar of pritamdutt
pritamdutt
Flag of India image

Here is a sample....


find / -type d '!' -exec test -f '{}/.qmail' ';' -print

Open in new window


where

find - is find command in unix
/ - is the path to search in
-type d - search for directories only
'!' - negate the output of -exec command
-exec - execute sub command
test -f '{}/.qmail' - where it will test for existence of .qmail filename... replace with your desired filename
-print - prints matching list

Hope this helps!

Regards,
Avatar of new_perl_user
new_perl_user

ASKER

instead of printing the matching list can we do the non-matching list and I just want to find no need to replace anything.
ASKER CERTIFIED SOLUTION
Avatar of pritamdutt
pritamdutt
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
pritamdutt's code works just fine

Can be put into a script like this:
if [ $# != 2 ]
then
	echo "$0 <dir> <file>"
else
	find $1 -type d '!' -exec test -f "{}/$2" ';' -print
fi

Open in new window

make the script above executable and call like this:

./script basedir file