Skip to main content
18 events
when toggle format what by license comment
Sep 26, 2022 at 10:06 comment added Adel how to open the file in addition to show its name? Thanks!
Aug 21, 2022 at 18:53 history edited Chris Stryczynski CC BY-SA 4.0
added 57 characters in body
Apr 5, 2022 at 11:21 comment added Gregor Hartl Watters Thanks for the answer! How would one siphon this into another command? For example, how could you use rm -rf to remove the latest file spat out by the command you give?
Dec 30, 2021 at 13:31 comment added 12431234123412341234123 This lists the most recent file of a folder not the most recent file of a directory.
Aug 26, 2021 at 7:39 history edited mgutt CC BY-SA 4.0
Added explanation of used flags
Aug 15, 2020 at 8:51 review Suggested edits
Aug 15, 2020 at 20:38
Jun 3, 2020 at 19:00 comment added igo Works on Mac :)
Feb 5, 2018 at 0:21 comment added Peter Scott I think that the intended benefit of using tail instead of head may be to exclude the inclusion of the line describing total returned by the ls.
Jun 16, 2015 at 15:23 comment added Alan For those who just want the filename: $(ls -rt | tail -n 1)
May 15, 2015 at 12:01 comment added 89n3ur0n @dmckee you should either remove -r from command or change tail to head :D
Mar 13, 2015 at 18:06 comment added Sildoreth Note that this solution includes directories as well as files. This could be a good thing or a bad thing; it depends on what the individual user wants. The reason I bring this up is that the original question says "file".
Nov 14, 2014 at 16:01 comment added dmckee --- ex-moderator kitten @TrueY I quite agree. Chaos' answer is better for efficiency.
Nov 14, 2014 at 8:51 comment added TrueY A minor issue: This version pipes all the output of ls to tail, then prints only the LAST line. IMHO it is better to sort in ascending order and use head instead, as chaos suggested. After printing the first line head quits, so sending the next line (actually next block) will rise a SIGPIPE and ls will quit as well.
Sep 18, 2014 at 14:37 comment added Josir using ls -Artls you can also view the file date.
Jun 18, 2009 at 23:21 vote accept ack
Jun 18, 2009 at 23:19 history edited dmckee --- ex-moderator kitten CC BY-SA 2.5
Fix for Jared
Jun 18, 2009 at 23:19 history edited Zifre CC BY-SA 2.5
removed extra backquote
Jun 18, 2009 at 23:17 history answered dmckee --- ex-moderator kitten CC BY-SA 2.5