Just wondering how could I less
the latest log file in a directory in Linux?
I'm after a oneliner, possibly considering an alias!
Something like this?
ls -1dtr /your/dir/{*,.*} | tail -1 | xargs less
Note that for the first block of ls
I am using an answer of Unix ls command: show full path when using options
As it requires a parameter, we create a function instead of an alias. Store the following in ~/.bashrc
:
my_less_func ()
{
ls -1dtr "$1"/{*,.*} | tail -1 | xargs less
}
Source it (it is enough doing . ~/.bashrc
) and call it with:
my_less_func your/path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With