![연속된 이름을 가진 누락된 파일을 찾는 방법은 무엇입니까? [복사]](https://linux55.com/image/75131/%EC%97%B0%EC%86%8D%EB%90%9C%20%EC%9D%B4%EB%A6%84%EC%9D%84%20%EA%B0%80%EC%A7%84%20%EB%88%84%EB%9D%BD%EB%90%9C%20%ED%8C%8C%EC%9D%BC%EC%9D%84%20%EC%B0%BE%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F%20%5B%EB%B3%B5%EC%82%AC%5D.png)
1.txt, 2.txt 등의 이름으로 수천 개의 파일이 있습니다. 이 파일 중 일부가 누락되었습니다. 어떤 파일이 누락되었는지 확인하는 가장 쉬운 방법은 무엇입니까?
답변1
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
, 특히 여기에는 앞에 0이 없습니다.
답변2
$ 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
$
답변3
제가 사용할 기능은 이렇습니다
missing () {
#ub gets the largest sequential number
ub=$(ls | sort -n | tail -n 1 | xargs basename -s .txt)
seq "$ub" | while read -r i; do
[[ -f "$i.jpg" ]] || echo "$i.txt is missing"
done
}
답변4
다른( bash
):
comm -23 <(printf '%d.txt\n' {1..1000} | sort) <(ls *.txt |sort)