Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux: most recent file in a directory, excluding directories and . files

I would like to find the most recently changed file in a directory, excluding hidden files (the ones that start with .) and also excluding directories.

This question is headed in the right direction, but not exactly what I need:

Linux: Most recent file in a directory

The key here is to exclude directories...

like image 662
cwd Avatar asked Oct 16 '11 21:10

cwd


1 Answers

Like the answer there except without -A

ls -rt | tail -n 1

Look at man ls for more info.

To make it exclude directories, we use the -F option to add a "/" to each directory, and then filter for those that don't have the "/":

ls -Frt | grep "[^/]$" | tail -n 1
like image 102
oadams Avatar answered Oct 04 '22 07:10

oadams