linux - 查找不包含 "*.sql"文件的目录

标签 linux bash find

我有几个目录如下。我想列出没有 SQL 文件的目录。例如下面示例中的“dev.mysite.com”。我使用的是 ubuntu 14.04 LTS

orange.com/
    orange.com.sql
    10.10.10.1/public_html/...

apple.edu.us/
    apple.edu.sql
    10.10.10.2/public_html/...

dev.mysite.com/
    10.10.10.3/public_html/

example.com/
    mysql_dbdump20150911.sql
    10.10.11.11/public_html/...

我尝试使用带有“cut”和“xargs”的“find”并将这些目录移动到“dirwithsql”目录并将其余目录作为手动没有sql文件的目录来实现这一点。

find . -maxdepth 2 -iname "*.sql" | cut -d'/' -f 2 | xargs -n 1 -I {} mv {} /backup/dirwithsql/{}

我试过

find -maxdepth 2 ! -iname "*.sql" -exec dirname {} \;

但是上面的命令显示了所有目录

有没有更好的方法? 谢谢

最佳答案

我最近遇到了类似的问题,这对我有用

for f in $(find . -type d -maxdepth 2); do if [[ $(ls -1 $f | grep '.sql$'|wc -l) == 0 ]] ; then echo $f; fi; done

关于linux - 查找不包含 "*.sql"文件的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33369886/

相关文章:

c++ - 使用 fstream 访问 linux 用户主目录

bash - `sed -i -e` 和 `sed -ie` 有什么区别?

docker 安装 MYSQL 错误

regex - "Grouped expression is missing ' ) '",除非它不是

linux - 带有 exec echo 选项的查找命令包含 ./in 文件名

linux - 为什么 find 的 -exec 选项包含 'non-matched' 项?

linux - ARI 身份验证( Asterisk )

linux - 比较两个文件并仅获取差异 - shell 脚本

linux - vim 将光标移动到我想要的第一个字符所在的行?

python - Mac OS X 10.10 合并错误