I use fd to find file names containing only zeros. I want adopt this code to work with all files in folders, not with the only one file... This works not bad
$ fdfind -tf -x bash -c '[ -s {} ] && (tr -d "\0" <{} | grep -q -m 1 ^ || (printf "{} " && wc -c <{}))'
./24.21.bin 1024
./24.2.bin 1024
./24.20.bin 1024
(Where [ -s {} ] &&
is to check that file is 0 bytes and exclude it).
But I don't want alphabetical order, I want Natural sort. I can try to use -X
option of fd
or try to use pipe, this is draft with pipe
$ fdfind -tf | sort --version-sort | xargs -d '\n'
24.2.bin 24.20.bin 24.21.bin
Sorting is natural, next steps should be 1) add all-zeros check 2) print filename. How to do it? For example this code contains all-zeros check (with result in $?
), but I don't know how to print filename, so this code print nothing...
fdfind -tf | sort --version-sort | xargs -d '\n' grep -qavE '^(00)*$'
P.S. To test my code you need all-zeros files, generate it using
truncate -s 1K 24.2.bin
truncate -s 1K 24.20.bin
truncate -s 1K 24.21.bin