Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何列出不包含';文件列表中不存在_Linux_Bash_Shell_Sh - Fatal编程技术网

Linux 如何列出不包含';文件列表中不存在

Linux 如何列出不包含';文件列表中不存在,linux,bash,shell,sh,Linux,Bash,Shell,Sh,我有一个文本文件a.txt,其中包含一个文件列表: photo/a.jpg photo/b.jpg photo/c.jpg etc 我想获取不存在的文件列表。您可以使用: xargs -I % bash -c '[[ ! -e $1 ]] && echo "$1"' _ % < a.txt > b.txt xargs-I%bash-c'[!-e$1]]和&echo“$1”\%a.txt>b.txt xargs将为a.txt中的每一行运行bash-c[!-e$1]

我有一个文本文件
a.txt
,其中包含一个文件列表:

photo/a.jpg
photo/b.jpg
photo/c.jpg
etc
我想获取不存在的文件列表。

您可以使用:

xargs -I % bash -c '[[ ! -e $1 ]] && echo "$1"' _ % < a.txt > b.txt
xargs-I%bash-c'[!-e$1]]和&echo“$1”\%a.txt>b.txt

xargs
将为
a.txt
中的每一行运行
bash-c
[!-e$1]
将检查每个条目是否存在。

无需涉及
cat
,也无需为文件中的每一行调用单独的shell;在这里,一个简单的
while read
循环就足够了:

while read -r file
do
    [ -e "$file" ] || echo "$file"
done < a.txt
读取-r文件时
做
[-e“$file”]| | echo“$file”
完成
逐行读。测试每个文件是否存在,如果不存在,则打印其名称


正如使用
out.txt将输入传递到循环一样,谢谢。然后把它放入一个文件中(因为我正在检查40k个文件,输出将很长),我只需要在该命令上附加
>b.txt
,对吗?是的,这是正确的,
cata.txt | xargs-I%bash-c'[[!-e$1]&&echo“$1”“\%>b.txt
将参数传递给
bash-c
\/code>的
\/code>的
\/code>的含义是什么。它也可以是
cata.txt | xargs-I%bash-c'[!-e$1]]&&echo“$1”'%
。啊,明白了!我发现
cat a.txt | xargs-I%bash-c'[!-e$0]]和&echo“$0”%
也在工作。。但是感谢您告诉我在使用
bash-c
时没有设置
$0
!一个oneliner
xargs-n1-I{}bash-c“[!-e{}]]&&echo{}”b.txt