Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Linux中打开子目录中的最新文件?_Linux_Ubuntu_Ls_Xargs_Unix Head - Fatal编程技术网

如何在Linux中打开子目录中的最新文件?

如何在Linux中打开子目录中的最新文件?,linux,ubuntu,ls,xargs,unix-head,Linux,Ubuntu,Ls,Xargs,Unix Head,我有一个logs/目录,其中包含许多日志文件。我想打开最新的日志文件。我的env是ubuntu16 我知道最新文件的名称。但是文件位于logs/dir中。在这种情况下,如何通过xargs判断相对传递 $ ls -t logs/ | head -1 20180615-184233.log $ ls -t logs/ | head -1 | xargs less failed 我自己找到的。我需要*来打印整个相对路径 $ ls -t logs/ | head -1 20180615-18423

我有一个
logs/
目录,其中包含许多日志文件。我想打开最新的日志文件。我的env是ubuntu16

我知道最新文件的名称。但是文件位于
logs/
dir中。在这种情况下,如何通过
xargs
判断相对传递

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

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

我自己找到的。我需要
*
来打印整个相对路径

$ 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