Find the oldest/newest files in a directory tree
October 03, 2009 21:34:35 Last update: October 03, 2009 21:34:56
One liners:
Shell scripts:
- Oldest
find . -printf "%T@ %Tx %TX %p\n" | sort -n | head | cut -d ' ' -f 2-
- Newest
find . -printf "%T@ %Tx %TX %p\n" | sort -n -r | head | cut -d ' ' -f 2-
Shell scripts:
- Oldest
#!/bin/ksh touch -t $(($(date "+%Y") + 1))$(date "+%m%d%H%M") compareTo OLDEST=compareTo find . -type f | while read f; do [[ $f -ot $OLDEST ]] && OLDEST=$f done echo oldest file: $OLDEST rm compareTo
- Newest
#!/bin/ksh touch -t 197001010000 compareTo NEWEST=compareTo find . -type f | while read f; do [[ $f -nt $NEWEST ]] && NEWEST=$f done echo newest file: $NEWEST rm compareTo