Sof*_*ros 6 filesystems filenames files
我有数千个文件名为 1.txt 2.txt 等等。其中一些文件丢失了。找出哪些文件丢失的最简单方法是什么?
ub=1000 # Replace this with the largest existing file's number.
seq "$ub" | while read -r i; do
[[ -f "$i.txt" ]] || echo "$i.txt is missing"
done
Run Code Online (Sandbox Code Playgroud)
您可以ub通过执行ls | sort -n或类似操作轻松找到合适的值。这依赖于格式为 输出的文件seq,特别是这里没有前导零。
$ ls
1.txt 3.txt
$ seq 1 10 | xargs -I {} ls {}.txt >/dev/null
ls: cannot access 2.txt: No such file or directory
ls: cannot access 4.txt: No such file or directory
ls: cannot access 5.txt: No such file or directory
ls: cannot access 6.txt: No such file or directory
ls: cannot access 7.txt: No such file or directory
ls: cannot access 8.txt: No such file or directory
ls: cannot access 9.txt: No such file or directory
ls: cannot access 10.txt: No such file or directory
$
Run Code Online (Sandbox Code Playgroud)