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.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
pritamdutt's code works just fine
Can be put into a script like this:
./script basedir file
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
make the script above executable and call like this:./script basedir file
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,