I have a directory: /home/user/
How can I list every file in this directory (including those in sub directories) and order them by the date that they were last modified?
I have a directory: /home/user/
How can I list every file in this directory (including those in sub directories) and order them by the date that they were last modified?
MAC OSX 2019
If you don't care about what time it was created but you want your list sorted then use this command
==> ls -t
If you want to order and see date and user info use this command
===> ls -lt
For zsh users, you could also use glob qualifiers (also documented on man zshexpn):
echo *(om)
Where o stands for sort order, up and m stands for last modification time.
This can be useful when used in a for loop or another command:
for file in *(^om); do
[ -e "$file" ] || continue
# do something with file orderer from least recently modified to last modified
done
Or chained with another glob qualifier:
last_modified_file=(*(om[1]))