# Arrange file by modified date

**URL:** <https://community.unix.com/t/arrange-file-by-modified-date/364995>\
**Category:** macOS\
**Created:** [February 10, 2017, 1:39pm UTC](https://community.unix.com/t/arrange-file-by-modified-date/364995 "2017-02-10T13:39:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gigagigosu](https://community.unix.com/letter_avatar/gigagigosu/32/5_5575768a8748004e209b776fc1b2916d.png) [@gigagigosu](https://community.unix.com/u/gigagigosu)\
**Post date:** [February 10, 2017, 1:39pm UTC](https://community.unix.com/t/arrange-file-by-modified-date/364995/1 "2017-02-10T13:39:54Z")

</div>

Hi,

Am performing a find based on filename and result can contain multiple files being found  
Let's say my find command is

```nohighlight
find /Archive -f -name 12345.pdf

```

and result of find command is

```nohighlight
/Archive/Folder A/12345.pdf
/Archive/Folder B/12345.pdf

```

please note white space in folder names

I need to get the file that has most recent modified date

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [February 10, 2017, 2:02pm UTC](https://community.unix.com/t/arrange-file-by-modified-date/364995/2 "2017-02-10T14:02:07Z")

</div>

```nohighlight
find /Archive -f -name 12345.pdf -printf "%T@ %p\n" | sort -rn | head -n 1

```

This will prepend a date in epoch seconds to every file name, which sort can order by time.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [February 10, 2017, 2:07pm UTC](https://community.unix.com/t/arrange-file-by-modified-date/364995/3 "2017-02-10T14:07:23Z")

</div>

A version using awk:

```nohighlight
find /Archive -f -name 12345.pdf -printf "%T@ %p\n" | awk '$1 > P { P=$0 } ; END { $0=P ; $1=""; print substr($0,2) }'

```
