Frequently Asked Questions

« Previous
How do I add an article or a paper from an online database to Zotero?
Next »
How do I install Adobe software with a Named user license?

windows ubuntu macos xibo network zenworks android storage

14. How do I find specific files like the last updated, the one with the longest file name, or the largest one?

See also: How do I compare the content of two directories?
These tools work on Linux (Ubuntu/CentOS/etc) and probably on macOS too.

Find the most recently updated file

Here is a small script that displays the most recently updated files in a directory. In the example this FAQ entry was the most recently updated!

$ find . -type f -print0 | xargs -0 -P 1 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head -3 2018-04-27 08:55:47.517999369 +0200 ./last.updated.file.txt 2018-04-27 08:54:07.277999790 +0200 ./last.updated.file.txt~ 2018-04-27 08:51:50.658000281 +0200 ./compare.directories.txt $ _

Find the most recently accessed file

This small script does the same, but looks for the most recently accessed file instead.

Please note that this may or may not work on different file systems. For example a network file system may be mounted noatime which means that the last accessed information is not stored. It requires a meta-data write for every accessed file which affect performance.

$ find . -type f -print0 | xargs -0 -P 1 stat --format '%X :%x %n' | sort -nr | cut -d: -f2- | head -1 2020-01-27 09:30:03.320448622 +0100 ./#last.updated.file# $ _

Find the number of files and the file with the longest file name

This little script display the number of files in the current directory, the character length of the longest file name and the name of that file. There were in total 219 files and the longest filename has 49 characters in the path was ./

$ find . -type f | awk 'BEGIN{N=0} {N=N+1; if ( length > L ) { L=length ;s=$0 } }END{ print N" "L" "s }' 219 49 ./ $ _

Find the files with the longest file names

This little snippet just find print the files with the longest names:

$ find . -type f | while read ; do echo ${#REPLY} $REPLY ; done | sort -nr | head -3 45 ./ 33 ./ 30 ./win.default.printer.settings $ _

Find the largest files

This will list the largest files. It will print a list of all files, in parallell do a stat on them, sort the list and then print the largest ones.

$ find . -print0 -type f | xargs -0 stat -c "%s %n" | sort -rn | head -3 23637 ./network.8021x 20285 ./platform 18051 ./ $ _


This entry last.updated.file was last modified 2020-01-27


This documentation is covered by GNU Free Documentation License. 14 ms