Frequently Asked Questions

« Previous
Some Cisco switch commands
Next »
How do I connect to the VPN using Ubuntu?

windows ubuntu macos xibo network zenworks android storage


55. How do I find the last updated file or the file with the longest file name?

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

Finding the last updated file

Here is a way of displaying the last updated file.

bash$ find directory -type f -print0 | xargs -0 -P 1 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head

In this example the script is run in the files in this FAQ. This FAQ entry is the last one updated!
$ find .  -type f -print0 | xargs -0 -P 1 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head
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
2018-04-26 15:40:44.030253321 +0200 ./compare.directories.txt~
2018-04-25 13:39:28.802347956 +0200 ./vlan.txt
2018-04-23 08:19:00.582125333 +0200 ./platform.txt
2018-04-20 16:01:09.194378641 +0200 ./serverroom.use.txt
2018-04-17 14:20:59.742186698 +0200 ./storage.txt
2018-04-13 13:28:04.770412453 +0200 ./spss.txt
2018-04-09 12:51:46.146083485 +0200 ./support.txt
$ _

Finding 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.
$ find directory1 | awk 'BEGIN{N=0} {N=N+1; if ( length > L ) { L=length ;s=$0 } }END{ print N" "L" "s }'
$ _

Here is an example running on the files in this FAQ. There are in total 219 files and the longest filename has 49 characters in the path which is ./how.to.map.network.drive.via.SMB.on.Windows.txt.

$ find . | awk 'BEGIN{N=0} {N=N+1; if ( length > L ) { L=length ;s=$0 } }END{ print N" "L" "s }'
219 49 ./how.to.map.network.drive.via.SMB.on.Windows.txt
$ _


 

This entry last.updated.file was last modified 2018-08-21

   

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