How to find the oldest and newest file in directory in Linux shell

Complex way, but allowed you to customise the output.

find /home/juzhax/ -type f -printf '%T- %p\n' | sort | head -n 1

Simple and shorter way

ls -lt | tail -1

Extra: Find the newest files in shell

ls -ltr | tail -1

Tags:

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.