【发布时间】:2012-10-13 14:02:40
【问题描述】:
我用这个命令找到了当前目录下所有包含.mp3的目录,只过滤掉了目录名:
find . -iname "*.mp3" | sed -e 's!/[^/]*$!!' -e 's!^\./!!' | sort -u
我现在想要相反,但我发现它有点难。我不能只添加一个“!”到 find 命令,因为它只会在打印时排除 .mp3,而不是查找不包含 .mp3 的目录。
我用谷歌搜索了这个并在 stackoverflow 和 unix.stackexchange.com 上进行了搜索。 到目前为止,我已经尝试过这个脚本,它返回这个错误:
#!/bin/bash
find . -type d | while read dir
do
if [[! -f $dir/*.mp3 ]]
then
echo $dir
fi
done
/home/user/bin/try.sh: 第 5 行: [[!: command not found
#!/bin/bash
find . -type d | while read dir
do
if [! -f $dir/*.mp3 ]
then
echo $dir
fi
done
/home/user/bin/try.sh: 第 5 行: [!: command not found
#!/bin/bash
find . -type d | while read dir
do
if [[! -f "$dir/*.mp3" ]]
then
echo $dir
fi
done
/home/user/bin/try.sh: 第 5 行: [!: command not found
我认为这与 test 命令的多个参数有关。
由于我正在测试变量将要更改的所有目录,因此我使用通配符作为文件名。
非常感谢任何帮助。谢谢。
【问题讨论】:
标签: bash shell testing wildcard