Shell command to get directory with least access date/time

前端 未结 6 1449
无人共我
无人共我 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:16
     find . -type d -printf "%A@ %p\n" | sort -n | tail -n 1 | cut -d " " -f 2-
    

    If you prefer the filename without leading path, replace %p by %f.

    0 讨论(0)
  • 2021-01-29 02:19

    This sound like more of a job for ls:

    ls -ultd *|grep ^d
    

    The problem with using find, at least on my system (cygwin/bash), is that find accesses the dirs, so all access-times result in current time, defeating your apparent purpose.

    0 讨论(0)
  • 2021-01-29 02:21
    find -type d -printf '%T+ %p\n' | sort | head -1
    

    source

    0 讨论(0)
  • 2021-01-29 02:36
    • the below linux command displays the access and modified time along with size

      stat -f

    0 讨论(0)
  • 2021-01-29 02:40
    find -type d -printf '%T+ %p\n' | sort
    
    0 讨论(0)
  • 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)
    
    0 讨论(0)
提交回复
热议问题