Files

如何查找具有順序名稱的失去文件?

  • October 14, 2015

我有數千個名為 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

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
$

引用自:https://unix.stackexchange.com/questions/236164