zsh -c 'zmodload zsh/stat
[[ $(zstat -N +size -- *(.om[1,4])) =~ $'\''(.*)\n\\1\n\\1\n\\1'\'' ]]' && exit
Would exit if the 4 newest non-hidden regular files in the current directory all have the same size.
On a GNU system, you could also do:
find . -maxdepth 1 ! -name '.*' -type f -printf '%T@ %s\n' |
sort -rn |
awk 'NR == 1 {v = $0}; v != $0 {exit}; NR == 4 {exit 1}' || exit
POSIXly:
ls -tnq -- "$dir_path" |
awk '!/^-/ {next}
n++ == 0 {v = $5}
v != $5 {exit}
n == 4 {exit 1}' || exit
If like in your own approach, instead of the 4 newest ones, you want the last 4 (regardless of whether they're regular files or symlinks or sockets...) in the ls
output (which is an alphabetically sorted list), you can do (still POSIXly):
ls -rnq -- "$dir_path" |
awk 'NR == 1 {next}
NR == 2 {v = $5}
v != $5 {exit}
NR > 4 {exit 1}' || exit