Search code examples
unixfindcut

Format find output into one field


I am doing a find command to get items sorted by access time:

$ find . -printf "%A+\t%p\n" | sort -r

The output looks like this:

2020-05-05+06:00:55.5569719990  ./form.py
2020-05-05+06:00:55.5569719990  ./amazon.js
2020-05-04+12:48:24.8209719990  ./historical.py

However, I would like to only show the filepath and remove the timestamp after it's been sorted like that, so getting:

./form.py
./amazon.js
./historical.py

What would be the best way to do this?


Solution

  • Like this:

    find . -printf "%A+\t%p\n" | sort -r | cut -d$'\t' -f2- 
    

    Or if you want to use , you should use TAB as delimiter (if not, it breaks on files with spaces on filenames):

    find . -printf "%A+\t%p\n" | sort -r | awk -F$'\t' '{print $2}'