A list of the newest file, by type (.txt), after searching recursively, in the terminal

I am trying to get my terminal to return the last .txt file with an intact outline. I studied ls, grep, find and tail using '|' functionality for transferring results from one utility to the next. The end result would be to have a work path + result so that I can pass in a text editor.

I approached such tests: to find. | grep '.txt $' | tail -1

.. but I was not lucky when grep returned a new file - is there a flag that I am missing?

Trying to use find and ls also does not work:

to find. -name "* .txt" | ls -lrth

.. ls returns the current directories instead of the results of my search query.

Please, help!

+3
source share
4

.

vi "$(find . -name '*.txt' -exec ls -t {} + | head -1)"
+3
find /usr/share -name '*.txt' -printf '%C+ %p\n' | sort -r | head -1 | sed 's/^[^ ]* //'
+2

If you have bash4 +

ls -t ./**/*.txt | head -1

edit the last txt file

vim $(ls -t ./**/*.txt |head -1)

ps: required to be included shopt -s globstarin your .bashrc or .profile ...

+2
source

You can use the stat function to print each file with only the last time and modification name.

to find. -name "* .txt" -exec stat -c "% m% N" {} \; | sort

+1
source

All Articles