Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have multiple sub-directories (which are named using GUIDs), which contain results files from computer simulations that I have been running. The files are all named in the following way:, where xxxx is a four-digit number from 0000 upwards; the latest file has the highest four-digit number. I would like to be able to list the latest file in each subdirectory, along with the directory that it is in.

So, for example, given sub-directory fc86783b-bcc5-4456-8964-049682ee81aa containing files to, and directory e608273d-35bd-442c-9de1-0ec184aa0d95 containing files to, I need a command that produces the output:

share|improve this question
A helpful user left an answer but deleted it before I could accept. The following command gave me the output that I needed: find n512/ -type d | while read d; do ls -ltr $d/hydro* | tail -n 1; done |awk -F " " '{print $8}' >out.txt – endian Oct 12 '11 at 12:33
up vote 2 down vote accepted

Create bash script with the following content:

ls -1tr "$1" | tail -n1

Run chmod +x to make it executable.

Then execute the following command:

find test -mindepth 1 -type d -name "hydro_configuration_*" -printf "%p/" -a -exec ./ {} \;

This will find all directories matching the pattern and print their names followed by a /, followed by the name of the latest file in there.

share|improve this answer
Thanks, I actually used an alternative approach but I'm sure yours would work as well. Since the original user who helped me deleted his answer, I will accept yours instead! – endian Oct 12 '11 at 13:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.