Passing the most recent file in a directory to a program

27 views Asked by At

What would be the correct way to do the following:

$ ls -t | head -n1 | vim -

Currently, this will read the 'filename' into vim, but I'm looking at actual open that filename that's passed to it as a string. How would this be done?

Without opening the file we get:

$ ls -t | head -n1
2020-11-05.txt
1

There are 1 answers

0
samuelbrody1249 On BEST ANSWER

You can pass it like this:

$ vim "$(ls -t | head -n1)"