Shell command to get directory with least access d

2019-03-06 00:34发布

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

标签: linux bash shell
6条回答
Melony?
2楼-- · 2019-03-06 01:08
  • the below linux command displays the access and modified time along with size

    stat -f

查看更多
淡お忘
3楼-- · 2019-03-06 01: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.

查看更多
爷、活的狠高调
4楼-- · 2019-03-06 01:22
 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.

查看更多
何必那么认真
5楼-- · 2019-03-06 01:23
find -type d -printf '%T+ %p\n' | sort
查看更多
姐就是有狂的资本
6楼-- · 2019-03-06 01:25
find -type d -printf '%T+ %p\n' | sort | head -1

source

查看更多
聊天终结者
7楼-- · 2019-03-06 01:28

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)
查看更多
登录 后发表回答