1

Is there a command on Unix systems which checks the "last accessed" date of every file on the system (or, better yet, recursively from the directory the command is run from) and then prints out the 10 (or otherwise defined number of) files which were least recently accessed?

(I'm currently doing a file clear-out on my Mac and want to identify which files I should delete, but I'm interested in the correct Unix way of doing this rather than anything Apple specific).

  • Just a note, make sure you run this on a directory with your files in it. If you run it filesystem wide, there are going to be some pretty old files, but they most likely aren't safe to delete. – cutrightjm Apr 26 '21 at 19:08

1 Answers1

0

As answered in Find latest files, the command on a standard Unix/Linux computer is:

find . -type f -exec stat -c '%X %n' {} \; | sort -nr | awk 'NR==1,NR==10 {print $2}'

If you're using a Mac, the flags are modified slightly so that the command is:

find . -type f -exec stat -f '%a %N' {} \; | sort -nr | awk 'NR==1,NR==10 {print $2}'

In both commands, edit NR=10 to the number of files you wish to see.