• Gyroplast@pawb.social
      link
      fedilink
      English
      arrow-up
      18
      ·
      11 hours 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
        link
        fedilink
        arrow-up
        5
        ·
        9 hours 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
      link
      fedilink
      arrow-up
      3
      arrow-down
      2
      ·
      13 hours 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.

  • MudMan@fedia.io
    link
    fedilink
    arrow-up
    5
    arrow-down
    2
    ·
    13 hours ago

    See, there’s a lot of online chatter about how much sense Linux folder structures make, with everything grouped by type all over the filesystem. And then this happens.

    DOS 5.1 folder structure or bust, I say. Home directories are evil, if your filename doesn’t fit in 8.3 characters you’re doing it wrong and if you can’t find it with dir . /w it shouldn’t exist.

    • _NetNomad@fedia.io
      link
      fedilink
      arrow-up
      1
      ·
      7 hours ago

      it’s a shame ReactOs is only in alpha and FreeDOS is single-tasking. it’s probably sacrelige to say this in a linux community but i wish we had foss os options that are to DOS and CP/M what modern linuxes are to Research Unix