rachid
rachid

Reputation: 2486

display the most recent file in a directory using linux shell

I need to display the content of the recent file in a directory, for my example it's a log file that gets generated for each execution hence I need to display the newest one the command :

ls -Art | tail -n 1 

output the right name, meaning the most recent file in a directory, my goal is to output the content of this file by further piping How could we do this?

Upvotes: 0

Views: 61

Answers (1)

bukkojot
bukkojot

Reputation: 1530

cat `ls -Art | tail -n1`

or,

ls -Art | tail -n 1 | xargs cat

Upvotes: 4

Related Questions