Last Updated: February 25, 2016
·
363
· maikel22

See which files are just touched

If you want to know what the hell just happened on your system, run this command and it will show you the 10 most recently touched files in the current directory. If you do this in '/' it will take obviously a long long time.

Mac:

find . -type f -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -10 | cut -f2- -d" "

Linux:

find . -type f -printf '%T@ %p\n' | sort -n | tail -10 | cut -f2- -d" "

2 Responses
Add your response

Extra bonus tip: make an alias of it in .bashrc or .zshrc

over 1 year ago ·

Or save this bash script like this somewhere in a bin directory:

!/bin/bash

dir=$1
limit=$2
if [ "$dir" == "" ];then
    dir="$PWD"
fi
if [ "$limit" == "" ];then
    limit="20"
fi

files="$(find $dir -type f -print0 | xargs -0 stat -f "%m%N" | sort -rn | head -$limit)"
files=${files//" "/"\s"}
for i in $files;do
    secs=${i:0:10}
    file=${i:10}
    file=${file#$dir/}
    time_=$(date -r $secs +"%H:%M:%S")
    date=$(date -r $secs +"%y-%m-%d")
    today=$(date +"%y-%m-%d")
    yesterday=$(date -v "-1d" +"%y-%m-%d")
    if [ "$date" == "$today" ];then
        day="Today    "
    elif [ "$date" == "$yesterday" ];then
        day="Yesterday"
    else
        day="$date "
    fi

    echo -e "$day $time_ ${file//"\s"/ }"
    toggle=1
done
over 1 year ago ·