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 &
There is a simple solution to this using only ls:
BACKUPDIR=$(ls -td /backups/*/ | head -1)
-t orders by time (latest first)-d only lists items from this folder*/ only lists directorieshead -1 returns the first itemI didn't know about */ until I found Listing only directories using ls in bash: An examination.