获取最新目录到Bash中的变量 [英] Get the newest directory to a variable in Bash

查看:61
本文介绍了获取最新目录到Bash中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在目录中找到最新的子目录,并将结果保存到bash中的变量中.

I would like to find the newest sub directory in a directory and save the result to variable in bash.

类似这样的东西:

ls -t /backups | head -1 > $BACKUPDIR

任何人都可以帮忙吗?

推荐答案

BACKUPDIR=$(ls -td /backups/*/ | head -1)

$(...)在子shell中评估该语句并返回输出.

$(...) evaluates the statement in a subshell and returns the output.

这篇关于获取最新目录到Bash中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆