Last Updated: February 25, 2016
· design48

bash alias to get latest/most recent file


$ alias latest="find . | sort | tail -n 1"

This allows you to have an alias to get file name of most recently modified file in the current directory. Save in your .bashrc or .aliases file.


$ vi `latest`

Opens most recently modified file in vim

$ open `latest`

If in pictures directory, will open your most recently modified photo in image preview (in OSX)

2 Responses
Add your response

There's a missing parameter to find?

over 1 year ago ·

You're right @redolent, I will update so it read find . -d 1 | sort | tail -n 1 so it doesn't descend so many levels deep and only sorts on current directory. Good catch!

over 1 year ago ·