Is it possible to the output of find … -exec ls -ls ;
sorted alpabetically, by filename?
This is my cron command:
find /home/setefgge/public_html -type f -ctime -1 -exec ls -ls {} \;
This command works okay, for the most part. But the results are not sorted in any meaningful sequence. It would be very helpful if they would be sorted by the file name field.
Best Answer
I assume that your file names don't contain newlines.
Using
+
instead of;
to terminate the-exec
action makes it faster by batching the invocations ofls
. You can sort by piping through thesort
command; tell it to start sorting at the 10th field (the first 9 are the metadata: blocks, permissions, link count, user, group, size, and 3 date/time fields). The option-n
tellsls
to use numeric values for the user and group, which avoids the risk of user or group names containing whitespace.Alternatively, with zsh, you can get away with no assumption on any name by using glob qualifiers to collect and sort the files and
zargs
to runls
multiple times if the command line would be too long. You do need GNUls
(specifically its-f
option) to avoid re-sorting byls
(another approach would be to emulatels
with zsh'szstat
).