List the last created file

If you want to find the newest file inside directory, you can use the ls & tail combination.

ls -t | head -1

Output

bash$ ls -t | head -1
id695.txt

Another option is with the next command

ls -lrth | tail -1

Output

bash$ ls -lrth | tail -1
-rw-r-----   1 user      ugroup         85 Nov 11 15:38 id695.txt

Note:
| is used to send the output of the first command as input to the second one.
tail — outputs the last files
-1 — denotes the number of lines u want to display (in case you don’t set -1, by default you will get the last 10 lines)

Leave a Reply

Your email address will not be published. Required fields are marked *