I need to search and find sub-directories that contain a certain file, however if they contain this certain file + this other file, I do not want them to be listed.The statement looks something like this:Find the directories that contain the file password.oldIf the directory contains password.old and webvirtual don't list themIf the directory ONLY contains password.old and does not contain webvirtual then output directory path to > OLD.TXT fileThis is what I have thus far, is this totally wrong? It seems to be working correctly, but I'm fairly new to bash scripting and just wanted to make sure I'm not missing something... or maybe there's a better way to handle this?#!/bin/shif FILE=$(find ./ -path OLD/ -prune -o -name password.old) && FILE=$(find ./ -path OLD/ -prune -o -name webvirtual*)thenprintf %s\n $FILE > Not_Old_Ones.txtfiif FILE=$(find ./ -path OLD/ -prune -o -name password.old) && FILE=$(find ./ -path OLD/ -prune -o ! -name webvirtual*)thenprintf %s\n $FILE > Old_Ones.txtfi
Using Find Command in tandem with if and statements
bash;find
Slightly lengthy , but working solution, which should work for cases where -execdir is not available:$ tree. dir_one  password.old  webvirtual dir_two     password.old$ find . -iname *password.old -exec dirname {} \; 2>/dev/null | while IFS= read -r directory; do> [ -e $directory/webvirtual ] && continue || echo $directory> done./dir_twoThus , all you need to do now, it add > OLD.txt at the end of the done statement to redirect output to fileIn case the dirname command is not available, you can use the following script with directory as argument.#!/bin/shfind $1 -type f -iname *password.old  -printf %h\n |while IFS= read -r directory;do    [ -e $directory/webvirtual ] && continue || echo $directorydoneFor example:$ ./find_missing_webvirtual.sh ./TESTDIR/                                                                                ./TESTDIR/dir_two