4 ms·
Here you go: sort all files in the current directory by modification time, whitespace-in-filenames-safe. The `printf (od -> sed)' construction converts back ou
by whelming_wave 7y ago
Here you go: sort all files in the current directory by modification time, whitespace-in-filenames-safe.
The `printf (od -> sed)' construction converts back out of null-separated characters into newline-separated, though feel free to replace that with anything accepting null-separated input. Granted, `sort --zero-terminated' is a GNU extension and kinda cheating, but it's even available on macOS so it's probably fine.
printf '%b' $(
find . -maxdepth 1 -exec sh -c '
printf '\''%s %s\0'\'' "$(stat -f '\''%m'\'' "$1")" "$1"
' sh {} \; | \
sort --zero-terminated | \
od -v -b | \
sed 's/^[^ ]*//
s/ *$//
s/ */ \\/g
s/\\000/\\012/g')
If you're running this under zsh, you'll need to prefix it with `command' to use the system executable: zsh's builtin printf doesn't support printing octal escape codes for normally printable characters, and you may have to assign the output to a variable and explicitly word-split it.
This is all POSIX as far as I know, except for the sort.