Listing all directories except one

bash, linux, shell

Solution

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.

Problem

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.

Original source