UNIX find 用于查找未配对的文件名

发布于 2025-01-02 19:15:10 字数 188 浏览 2 评论 0原文

是否有一种简单的方法可以递归地查找目录层次结构中没有具有不同扩展名的匹配文件的所有文件?

例如,该目录有一堆以 .dat 结尾的文件,

我想找到没有附带 .out 文件的 .dat 文件。

我有一个 while 循环来检查每个条目,但这对于长列表来说很慢......

我正在使用 GNU find。

Is there a simple way to recursively find all files in a directory hierarchy, that do not have a matching file with a different extension?

For example the directory has a bunch of files ending in .dat

I want to find the .dat files that do not have an accompanying .out file.

I have a while loop that checks each entry, but that is slow for long lists...

I am using GNU find.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逐鹿 2025-01-09 19:15:10

也许是这样的?

find . -name "*.dat" -print | sort > column1.txt
find . -name "*.out" -print | sort > column2.txt
diff column1.txt column2.txt

我还没有测试过,但我认为它可能接近你的要求。

Perhaps something like this?

find . -name "*.dat" -print | sort > column1.txt
find . -name "*.out" -print | sort > column2.txt
diff column1.txt column2.txt

I haven't tested it, but I think it's probably close to what you're asking for.

街道布景 2025-01-09 19:15:10
find . -name '*.dat' -printf "[ -f %p ] || echo %p\n" | sed 's/\.dat/.out/' | sh
find . -name '*.dat' -printf "[ -f %p ] || echo %p\n" | sed 's/\.dat/.out/' | sh
心不设防 2025-01-09 19:15:10

我不得不在第一个解决方案中添加一堆花哨的东西,但这是一个好的开始,谢谢...

find 。 -打印| grep -Fi '.dat' | grep -Fi '.dat' | grep -vFi '.dat'。 |排序| sed -e 's/.dat //g' >列1.txt
寻找 。 -打印| grep -Fi '.out' | grep -Fi '.out' | grep -Fi '.out' | grep -Fi '.out' grep -vFi '.out'。 |排序| sed -e 's/.out //g' >列2.txt
sdiff -s 列1.txt 列2.txt | grep -F '<' |剪切-f1-d“<” > c12diff.txt

I had to add a bunch of bells and whistles to the 1st solution, but that was a good start, thanks...

find . -print | grep -Fi '.dat' | grep -vFi '.dat.' | sort | sed -e 's/.dat//g' > column1.txt
find . -print | grep -Fi '.out' | grep -vFi '.out.' | sort | sed -e 's/.out//g' > column2.txt
sdiff -s column1.txt column2.txt | grep -F '<' | cut -f1 -d"<" > c12diff.txt

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文