[英]Listing all directories except one
I have a following directory structure 我有一个以下目录结构
libs logs src etc .........
|-- logs
|-- src
|-- inc
"logs" directory is everywhere inside. “logs”目录里面到处都是。 So I want to list all directories except "logs". 所以我想列出除“logs”之外的所有目录。 What will be shell command for that. 什么是shell命令。
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. 此致,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. grep
只是在开始时删除包含logs/
或/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 | 如上面评论中所述,您可以使用egrep和| to separate patterns or like below define it all in find 分开模式或类似下面在find中定义它们
find . -type d -print
.
./logs1
./test
./logs
$ find . -type d -not -name logs -not -name logs1 -print
.
./test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.