arnpry
arnpry

Reputation: 1141

Find Most Recent File in a Directory That Matches Certain File Size

I need to find the most recently modified file in a directory that matches 3.0 MB.

First Attempt

ls -t /home/weather/some.cool*.file | head -n +1 | grep "3.0M"

Second Attempt

find /home/weather/ -maxdepth 1 -type f -name "some.cool*.file" -size 3M -exec ls -t "{}" +; | head -n +1

Am I close?

Upvotes: 1

Views: 192

Answers (2)

Abhilash G
Abhilash G

Reputation: 86

I hope this is of some use -

ls -ltr --block-size=MB | grep 3MB

The latest modified files will be displayed at the bottom of the output.

The -r flag shows the output in reverse order and the --block-size=MB will show the size of files in MB.

Upvotes: 2

ZeppRock
ZeppRock

Reputation: 1138

This should work:

ls -lh --sort=time /path/to/directory/*.file | grep "3.0M" | head -n =1

Upvotes: 1

Related Questions