I have a following directory structure
libs logs src etc .........
|-- logs
|-- src
|-- inc
"logs" directory is everywhere inside. So I want to list all directories except "logs". What will be shell command for that.
Something like
#!/bin/bash
for dir in `find * -type d`; do
if [[ ${dir} != "{logs}*" ]]; then
echo ${dir}
fi
done
but this does not seems to be working.
Regards, Farrukh Arshad.
Rather than trying to process these things one at a time with checks, why don't you get all directories and just filter out the ones you don't want:
find * -type d | egrep -v '^logs/|/logs/'
The grep
simply removes lines containing either logs/
at the start or /logs/
anywhere.
That's going to be a lot faster than individually checking every single directory one-by-one.
As mentioned in the above comment you can use egrep and | to separate patterns or like below define it all in find
find . -type d -print
.
./logs1
./test
./logs
$ find . -type d -not -name logs -not -name logs1 -print
.
./test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With