Harness the Combinatoric Power of Command-Line Tools and Utilities
Find Modified Files
Published May 17, 2024
Warning
❗ This article is more than six months old. Some things may not work as written.
In the current directory, you can see the most recently modified files with the ls -ltr
command, which sorts the listing with the most recently changed directories and files last.
To search a directory and its children for the most recently-changed files, use the find
command and send the results to the sort
command:
find ~/Documents -type f -printf "%T@ %T+ %p\n" | sort -n
Here’s how it works:
find ~/Documents -type f
: This part of the command searches for all files (-type f
) within the~/Documents
directory.-printf "%T@ %T+ %p\n"
: This specifies the output format for each file found:%T@
prints the modification time as a numeric timestamp, which will be whatsort
uses to sort the results.%T+
prints the modification time in a human-readable format.%p
prints the file path.\n
ensures that each file’s information is printed on a new line.
| sort -n
: This pipes the output of thefind
command tosort
, which sorts the lines numerically (-n
), based on the timestamp printed by%T@
.
The most recent files are at the end of the list.