Shell command to get directory with least access date/time

前端 未结 6 1448
无人共我
无人共我 2021-01-29 01:45

Is there any sort option available in find command to get directory with least access date/time

6条回答
  •  伪装坚强ぢ
    2021-01-29 02:40

    A simple shell script will also do:

    unset -v oldest
    for i in "$dir"/*; do
        [ "$i" -ot "$oldest" -o "$oldest" = "" ] && oldest="$i"
    done
    

    note: to find the oldest directory use "$dir"/*/ above (thanks Cyrus) and -type d below with the find command.

    In bash if you need a recursive solution, then you can rewrite it as a while loop with process substitution using find

    unset -v oldest
    while IFS= read -r i; do
        [ "$i" -ot "$oldest" -o "$oldest" = "" ] && oldest="$i"
    done < <(find "$dir" -type f)
    

提交回复
热议问题