70
whatever, it works (lemmy.world)
you are viewing a single comment's thread
view the rest of the comments
[-] RustyNova@lemmy.world 5 points 2 weeks ago
[-] Pfuiting@lemmynsfw.com 8 points 2 weeks ago

Ls - it lists all files in the current directory -l - It shows details like last edit. -R - It gets sorted by date. Head - it shows the ten last edited files

I use it very often myself, when I'm not sure about the file name.

[-] Gyroplast@pawb.social 4 points 2 weeks ago

Not what it implicitly advertises, unfortunately. It lists all files (ls) recursively in all subdirectories (-R), one per line with details (-l), sorted by time, newest first (-t). Only the first 10 files are shown (| head).

The problem is that the files are sorted by time per directory, and ls recursively descents into subdirectories in that order. It's not a "Depth First Search", if you're so inclined. Effectively, this shows the newest 10 files/dirs in the current directory before diving down, and if you have less files/dirs than that in your search base directory, you probably don't need this hack to begin with.

In good tradition, here's something that actually works as likely intended. find recursively lists (only) all regular files (-type f) starting in the current directory (.) and runs the ls command (-exec) to show details (-l) of each file passed as arguments ({} +), including a specific, sortable time format (--time-style). The resulting comprehensive list of all files is then sorted in reverse (-r) order, using the sixth whitespace-separated column of each line/file as the key (-k6), which just so happens to be the "sortable time format". Lastly, only the 10 most recent files are shown (| head), as before:

find . -type f -exec ls -l --time-style=+"%Y-%m-%dT%T" {} + | sort -r -k6 | head

Running this is a great way to start your day! It'll give you ample time to brew some coffee or tea, slip into your most comfortable programmer socks, and finish lunch by the time it scanned your 18.3 TB of furry smut to show you what you "touched" last.

It'll likely be irrelevant cache files, though, if you run it from your $HOME. Excluding directories is left as an exercise for the reader.

[-] palordrolap@fedia.io 1 points 2 weeks ago

Let me save you a few characters: %Y-%m-%d can be shortened to %F

For visualisation's sake I also like to put a space before the %F so that the year and the file size are separated a little more, but that's more of a taste thing than anything else.

(Caveat: %F's year is explicitly four digits in some libraries, whereas %Y is always the full year. If you're planning for your code to last 8000 years you might want to consider that.)

[-] claimsou@lemmy.world 0 points 2 weeks ago

It lists all the files. I do not get the joke. Possibly the joke is that the head command cuts to 10 characters which probably will not display the actual file name because the l command displays the file attributes. So you see just some timestamps. Many.

[-] wibble@reddthat.com 3 points 2 weeks ago

Ten lines, not characters

this post was submitted on 16 Dec 2025
70 points (92.7% liked)

linuxmemes

28647 readers
109 users here now

Hint: :q!


Sister communities:


Community rules (click to expand)

1. Follow the site-wide rules

2. Be civil
  • Understand the difference between a joke and an insult.
  • Do not harrass or attack users for any reason. This includes using blanket terms, like "every user of thing".
  • Don't get baited into back-and-forth insults. We are not animals.
  • Leave remarks of "peasantry" to the PCMR community. If you dislike an OS/service/application, attack the thing you dislike, not the individuals who use it. Some people may not have a choice.
  • Bigotry will not be tolerated.
  • 3. Post Linux-related content
  • Including Unix and BSD.
  • Non-Linux content is acceptable as long as it makes a reference to Linux. For example, the poorly made mockery of sudo in Windows.
  • No porn, no politics, no trolling or ragebaiting.
  • Don't come looking for advice, this is not the right community.
  • 4. No recent reposts
  • Everybody uses Arch btw, can't quit Vim, <loves/tolerates/hates> systemd, and wants to interject for a moment. You can stop now.
  • 5. ๐Ÿ‡ฌ๐Ÿ‡ง Language/ัะทั‹ะบ/Sprache
  • This is primarily an English-speaking community. ๐Ÿ‡ฌ๐Ÿ‡ง๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ‡บ๐Ÿ‡ธ
  • Comments written in other languages are allowed.
  • The substance of a post should be comprehensible for people who only speak English.
  • Titles and post bodies written in other languages will be allowed, but only as long as the above rule is observed.
  • 6. (NEW!) Regarding public figuresWe all have our opinions, and certain public figures can be divisive. Keep in mind that this is a community for memes and light-hearted fun, not for airing grievances or leveling accusations.
  • Keep discussions polite and free of disparagement.
  • We are never in possession of all of the facts. Defamatory comments will not be tolerated.
  • Discussions that get too heated will be locked and offending comments removed.
  • ย 

    Please report posts and comments that break these rules!


    Important: never execute code or follow advice that you don't understand or can't verify, especially here. The word of the day is credibility. This is a meme community -- even the most helpful comments might just be shitposts that can damage your system. Be aware, be smart, don't remove France.

    founded 2 years ago
    MODERATORS