• Captain Aggravated@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      22
      ·
      2 days ago

      UGH that shit.

      rm deletes a file. It can’t delete a directory, you have to use

      rmdir to delete a directory…as long as there’s nothing in that directory. If there’s anything in the directory, you have to know to use

      rm -r to delete a directory and its contents, and no

      rmdir -r isn’t right somehow!

      • Matriks404@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        2 days ago

        I don’t think there’s any reason to use rmdir unless you write (Ba)sh scripts, and you want to make sure that the directory is indeed empty. Just use rm -r.

        Also note that you can use rmdir -p this/is/some/path to remove all nested directories including the parent (this here). But this will only work if there’s exactly one directory per parent directory, and the last directory doesn’t have any files (including directories). This might be helpful for some scripts.

        rmdir -r isn’t a thing, because that would invalidate the reason this command exists.

      • Opisek@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        2 days ago

        Reminds me of a little annoyance I have with cat and ls. Yeah they technically do different things, one is for files and one is for directories. But so often I just find myself wishing I could use one command for both. Like making cat directory act as ls. Maybe I’m the only one who feels that way.

      • setsubyou@lemmy.world
        link
        fedilink
        arrow-up
        3
        arrow-down
        1
        ·
        2 days ago

        On Linux, rm can delete empty directories with -d too, not just with -r.

        rmdir is the counterpart to mkdir, which creates empty directories, so of course it can only remove empty directories. After all mkdir can’t create full directories either. There however is rmdir -p as a counterpart to mkdir -p, so if there is something in the directory, you can use that, as long as the something is an empty directory.

        • Captain Aggravated@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          5
          arrow-down
          1
          ·
          edit-2
          2 days ago

          Yeah it still has a certain “AAAAH! You didn’t say simon says” feel to it when you’re actually trying to get things done. Like imagine if you had to choose a different option from a context menu to delete a folder in a GUI. If there was an option for Remove File and another one placed a little elsewhere in the menu that says Remove Directory.

          I’m still gonna call it an unsanded corner.

          • Ephera@lemmy.ml
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 day ago

            I feel like the main reason the distinction exists, is because deleting a whole directory can be potentially catastrophic.

            I looked at Trashy yesterday, which gives you a command trash my_file that just moves the file into the trashcan folder. Well, and that decided to make no distinction between files and directories, which does make sense to me, since you can just restore a deleted directory.

            • Captain Aggravated@sh.itjust.works
              link
              fedilink
              English
              arrow-up
              1
              ·
              1 day ago

              My solution: rm will remove an empty directory, while a full directory will throw either an “are you sure? y/N” or require you to use rm -r. Why have a command whose only job is to remove an empty directory?

              • Ephera@lemmy.ml
                link
                fedilink
                English
                arrow-up
                1
                ·
                9 hours ago

                Yeah, I feel like a big part of the reason it was designed like that, is because it was designed in the 70s, where you couldn’t really throw up interactive prompts. But interactive prompts are also somewhat tricky for scripting, as it’s difficult to detect whether a user could respond to the prompt, meaning the script might just hang there forever.

                That’s kind of the problem. You almost need separate tools for scripting and interactive use, but having separate tools is also not great, since people will inherently try to use the tool they know for everything…