Get the newest directory in bash to a variables

后端 未结 8 2089
北恋
北恋 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:43

    Your "something like this" was almost a hit:

    BACKUPDIR=$(ls -t ./backups | head -1)
    

    Combining what you wrote with what I have learned solved my problem too. Thank you for rising this question.

    Note: I run the line above from GitBash within Windows environment in file called ./something.bash.

提交回复
热议问题