Bash 寻找丢失的文件
Bash to find missing file
我正在计算照片文件夹中的文件数:
% find . -type f | wc -l
22188
然后我计算每个扩展名的文件数:
% find . -type f | sed -n 's/..*\.//p' | sort | uniq -c
268 AVI
14983 JPG
61 MOV
1 MP4
131 MPG
1 VOB
21 avi
1 jpeg
6602 jpg
12 mov
20 mp4
74 mpg
12 png
总和是 22187,而不是 22188。所以我认为它可能是一个没有扩展名的文件:
% find . -type f ! -name "*.*"
但是结果是空的。可能是一个以 .
:
开头的文件
% find . -type f ! -name "?*.*"
但也是空的。我怎样才能找出那个文件是什么?
我使用的是 macOS 10.15。
此命令应该可以找到丢失的文件:
comm -3 <(find . -type f | sort) <(find . -type f | sed -n '/..*\./p' | sort)
可能是带有嵌入式回车 return(或换行符)的文件?
很想知道这会生成什么:
find . -type f | grep -Eiv '\.avi|\.jpg|\.mov|\.mp4|\.mpg|\.vob|\.avi|\.jpeg|\.png'
你要不要试试:
find . -type f -name $'*\n*'
它将选择包含换行符的文件名。
ANSI-C quoting
在 MacOS 上被 bash-3.2.x 左右支持。
我正在计算照片文件夹中的文件数:
% find . -type f | wc -l
22188
然后我计算每个扩展名的文件数:
% find . -type f | sed -n 's/..*\.//p' | sort | uniq -c
268 AVI
14983 JPG
61 MOV
1 MP4
131 MPG
1 VOB
21 avi
1 jpeg
6602 jpg
12 mov
20 mp4
74 mpg
12 png
总和是 22187,而不是 22188。所以我认为它可能是一个没有扩展名的文件:
% find . -type f ! -name "*.*"
但是结果是空的。可能是一个以 .
:
% find . -type f ! -name "?*.*"
但也是空的。我怎样才能找出那个文件是什么?
我使用的是 macOS 10.15。
此命令应该可以找到丢失的文件:
comm -3 <(find . -type f | sort) <(find . -type f | sed -n '/..*\./p' | sort)
可能是带有嵌入式回车 return(或换行符)的文件?
很想知道这会生成什么:
find . -type f | grep -Eiv '\.avi|\.jpg|\.mov|\.mp4|\.mpg|\.vob|\.avi|\.jpeg|\.png'
你要不要试试:
find . -type f -name $'*\n*'
它将选择包含换行符的文件名。
ANSI-C quoting
在 MacOS 上被 bash-3.2.x 左右支持。