gpt4 book ai didi

用于列出未找到文件的 Bash 脚本

转载 作者:行者123 更新时间:2023-11-29 09:49:14 30 4
gpt4 key购买 nike

我一直在寻找一种方法来从需要存在的文件列表中列出不存在的文件。这些文件可以存在于多个位置。我现在拥有的:

#!/bin/bash
fileslist="$1"
while read fn
do
if [ ! -f `find . -type f -name $fn ` ];
then
echo $fn
fi
done < $fileslist

如果文件不存在,查找命令将不会打印任何内容,测试也不会进行。删除 not 并创建 if then else 条件并不能解决问题。

如何打印未从文件名列表中找到的文件名?

新脚本:

#!/bin/bash
fileslist="$1"
foundfiles="~/tmp/tmp`date +%Y%m%d%H%M%S`.txt"
touch $foundfiles
while read fn
do
`find . -type f -name $fn | sed 's:./.*/::' >> $foundfiles`
done < $fileslist
cat $fileslist $foundfiles | sort | uniq -u
rm $foundfiles

最佳答案

#!/bin/bash
fileslist="$1"
while read fn
do
FPATH=`find . -type f -name $fn`
if [ "$FPATH." = "." ]
then
echo $fn
fi
done < $fileslist

你很接近!

关于用于列出未找到文件的 Bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8948104/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com