Get the newest directory in bash to a variables

后端 未结 8 2100
北恋
北恋 2020-12-13 13:17

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

Something like this:

ls -t /backups | head -1 &         


        
8条回答
  •  忘掉有多难
    2020-12-13 13:45

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

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

提交回复
热议问题