如何使用head在bash中创建文件路径以查找最新路径

时间:2017-10-27 05:27:36

标签: bash directory filepath

我需要将脚本定向到最近目录中的最新文件

cd /my/path/latestdirectory/more/path/latestfile.trp

我可以使用

找到最新的目录
ls -t | head -n1

但我不知道如何将输出值分配给剩余的路径名

1 个答案:

答案 0 :(得分:0)

您将latestdirectory的值存储在变量中。 然后将变量与剩余文件路径的值连接起来。

像这样:

latest_dir=$(ls -t /my/path | head -n1)
ls ${latest_dir}/more/path/latestfile.trp