0

I have a logs/ directory which contains many log files. I would like to open the latest log file. My env is Ubuntu 16.

I know the name of the latest file. But the file is in logs/ dir. In such a case, how do I tell the relative pass via xargs?

$ ls -t logs/ | head -1
20180615-184233.log

$ ls -t logs/ | head -1 | xargs less
failed 
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
jef
  • 3,890
  • 10
  • 42
  • 76

1 Answers1

0

I found it by myself. I need * for printing the whole relative path.

$ ls -t logs/ | head -1
20180615-184233.log

$ ls -t logs/ | head -1 | xargs less
failed 

$ ls -t logs/* | head -1
logs/20180615-184233.log

$ ls -t logs/* | head -1 | xargs less
success
jef
  • 3,890
  • 10
  • 42
  • 76