• katy ✨@piefed.blahaj.zone
    link
    fedilink
    English
    arrow-up
    17
    ·
    10 hours ago

    the struggle between spaces in filenames look cute and oh fuck what’s the code to reference a space in a filename in terminal?

    • kamen@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      2 hours ago

      Just put the whole thing in quotes. You might have to escape extra sets of quotes, usually with a backslash.

  • lemming741@lemmy.world
    link
    fedilink
    English
    arrow-up
    148
    ·
    14 hours ago

    Microsoft intentionally made programs install to C:\Program Files on Windows 95+ to force programmers to deal with spaces in filenames.

    Someone make one of those “statements made by the utterly deranged” memes about it, please and thank you.

    • nialv7@lemmy.world
      link
      fedilink
      arrow-up
      14
      ·
      11 hours ago

      unix filenames are just string of bytes, the operating system does not interpret it in anyway. this is a much saner approach compared to Windows where language settings can change file system behavior.

      • who@feddit.org
        link
        fedilink
        English
        arrow-up
        4
        ·
        11 hours ago

        the operating system does not interpret it in anyway.

        *in any_way. ;)

    • FrostyPolicy@suppo.fi
      link
      fedilink
      arrow-up
      62
      ·
      edit-2
      15 hours ago

      On Linux file systems you can use any character except NULL, and / is a reserved character.

      E.g. on ext-4 “All characters and character sequences permitted, except for NULL (‘\0’), ‘/’, and the special file names “.” and “…” which are reserved for indicating (respectively) current and parent directories.”

      • xthexder@l.sw0.com
        link
        fedilink
        arrow-up
        44
        ·
        14 hours ago

        I once accidentally created a file with a newline character in it… it was pretty tricky to fix from command line.

        • lad@programming.dev
          link
          fedilink
          English
          arrow-up
          1
          ·
          3 hours ago

          I created a file with backspace in name, it was hard to understand why filename doesn’t match

        • GenderNeutralBro@lemmy.sdf.org
          link
          fedilink
          English
          arrow-up
          9
          ·
          13 hours ago

          I actually did this a lot on classic Mac OS. Intentionally.

          The reason was that you could put a carriage return as the first character of a file, and it would sort above everything else by name while otherwise being invisible. You just had to copy the carriage return from a text editor and then paste it into the rename field in the Finder.

          Since OS X / macOS can still read classic Mac HFS+ volumes, you can indeed still have carriage returns in file names on modern Macs. I don’t think you can create them on modern macOS, though. At least not in the Finder or with common Terminal commands.

        • Warl0k3@lemmy.world
          link
          fedilink
          arrow-up
          3
          ·
          edit-2
          13 hours ago

          Did you not just use tab? That’s the usual method of dealing with weird characters in filenames that I’ve found

          • Hupf@feddit.org
            link
            fedilink
            arrow-up
            1
            ·
            3 hours ago

            Too bad when there’s multiple files starting with and consisting mostly of e.g. kanji (when on a Latin keyboard).

          • xthexder@l.sw0.com
            link
            fedilink
            arrow-up
            3
            ·
            11 hours ago

            This was quite a while ago now, but I don’t think my shell escaped the tab complete properly, I remember it just printing a literal newline and evaluating it as a second command. I think there was other unicode in there too, otherwise I would have just typed it out. I had to do something with null terminated output and piping it in to mv, but I can’t remember what exactly.

        • toynbee@lemmy.world
          link
          fedilink
          arrow-up
          4
          ·
          14 hours ago

          I don’t conduct interviews very often, but when I do, one of my questions is always about interacting with files that have special characters in the filename.

      • CanadaPlus@lemmy.sdf.org
        link
        fedilink
        arrow-up
        6
        ·
        14 hours ago

        So … is allowed, or all whitespace, or Zalgo text.

        I mean, on the one hand, I guess why be restrictive, but on the other I feel like requiring something that looks like language somehow might be a good idea to avoid edge cases and attacks.

        • Hupf@feddit.org
          link
          fedilink
          arrow-up
          1
          ·
          3 hours ago

          could you have .​.? I assume most terminals would just spell out .\x200b.?

        • unalivejoy@lemmy.zip
          link
          fedilink
          English
          arrow-up
          11
          ·
          14 hours ago

          You can have new lines in your file names. YSAP has a good video/playlist about how to deal with these and many more.

    • 9point6@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      9 hours ago

      It’s all just Unicode

      You can have emoji as your WiFi network name too

      Kinda interesting to see what older devices do when faced with such a network

    • Gyroplast@pawb.social
      link
      fedilink
      English
      arrow-up
      16
      ·
      14 hours ago

      In filenames? AMATEURS! Use obscure Unicode in your passphrases for maximum security. Ctrl-Shift-U, enter arbitrary code point, bam! 🦊 Works even better with a Compose key and a nice, chonky .XCompose file to throw some gr∑∑k letters around, for instance, like some confused script kiddie. :)

      On topic: There are multiple variants of spaces in Unicode. You’re welcome, and now go and create something utterly deranged with that information.

      • wizardbeard@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        6
        ·
        12 hours ago

        I already deal far too much with trying to handle dumb fucking typos in employee data, and trying to turn human names into valid email addresses.

        The first time I encounter something like this there will be a body. It will not be found.

    • bigfondue@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      edit-2
      12 hours ago

      You can, but I downloaded some music the other day and I was trying to put the files onto my phone using KDE Connect, and I couldn’t understand why is wasn’t working until I got rid of the star character in the filenames. So I think Graphene/Android might still struggle with it.

      • Iced Raktajino@startrek.website
        link
        fedilink
        arrow-up
        1
        ·
        12 hours ago

        Lol, I think that’s how I learned it was possible, too. yt-dlp uses the title as the filename, and all of the emojis came along with it. Was trying to rename them from terminal, but couldn’t do much when half the filenames started with the fire emoji lol.

    • TootSweet@lemmy.world
      link
      fedilink
      English
      arrow-up
      7
      ·
      14 hours ago

      10 seconds of googling indicates this is true for Windows and Mac as well. I haven’t looked specifically, but I’d be a little surprised if it wasn’t true for Android and iOS as well.

      But really, why would they add rules to prevent people from using certain unicode codepoints in filenames? Should they disallow Klingon as well? Kanji? Of course not. Emojis are codepoints just like U+0061 is.

      Of course there are good reasons to disallow things like newlines and forward slashes in Linux filenames, but what specifically would even be the argument for preventing emojis?

    • Dr. Moose@lemmy.world
      link
      fedilink
      English
      arrow-up
      7
      arrow-down
      1
      ·
      7 hours ago

      Hyphens > underscores for filenames because all web standards prefer hyphens so if you ever want to network your files its a much smoother experience!

      • SaharaMaleikuhm@feddit.org
        link
        fedilink
        arrow-up
        2
        ·
        3 hours ago

        They suck hard. I use the renpy engine and there you reference file names directly but always lower case and spaces and hyphens turn to underscores. That can cause issues, so I just do underscores in my file names. Don’t give damn about the web.

        • Dr. Moose@lemmy.world
          link
          fedilink
          English
          arrow-up
          1
          ·
          2 hours ago

          Yeah I prefer underscores too but kebab case is definitely better for web and general ergonomics. Dash doesnt require a shift hold! Tho I still mix these depeding on tool or existing idioms. One thing for sure is that spaces and capital letters are stupid and we should do less of them.

      • livingcoder@programming.dev
        link
        fedilink
        arrow-up
        4
        ·
        7 hours ago

        This is what I need, an explicit reason that makes one choice better than another. If hyphens make for a smoother experience, then I’ll reconsider my default behavior.

        Thanks for pointing out this benefit.

    • BassTurd@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      12 hours ago

      I prefer lowercase with hyphens, but I’m transitioning into a team that does everything camelCase, which is the second best case, but I still strongly dislike it.

  • asdfranger@lemmynsfw.com
    link
    fedilink
    arrow-up
    37
    ·
    edit-2
    15 hours ago
    Oh\ come\ on,\ it\'s\ not\ that\ bad
    

    Some shells enclose those types of files within inverted commas. Such that:

    > ls
    file\ name.md
    

    is instead

    > ls
    'file name.md'
    

    (I use fish)

          • Revan343@lemmy.ca
            link
            fedilink
            arrow-up
            4
            ·
            12 hours ago

            On its own, the backtick is primarily used in computing, and so doesn’t have an old-timey-English name, nor does the Jargon File mention a Commonwealth Hackish name for it. While there are a variety of other names, I don’t think any of them are specific to the UK

            When used with a letter, it marks a grave accent; this was its original purpose on a typewriter

        • Luc@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          11 hours ago

          In dutch I’ve heard them be called flying commas unapologetically (vliegende comma’s — ironically has one in it because many plurals need it, it doesn’t mark possession)

  • Luc@lemmy.world
    link
    fedilink
    arrow-up
    7
    ·
    11 hours ago

    Now I’m imagining a shell that looks iteratively through arguments to find where quotes would make total sense

    $ ls
    my victims.ods
    $ wipe -f my victims.ods --thorough
    

    So the shell would go like

    1. wipe → command name found, ok
    2. -f → no file in the current directory starts with that, skip
    3. my → matches a file, keep in memory…
    4. my victims.ods → full match, but missing quotes!
    5. Prompt user:
    Filename "my victims.ods" found without quotes. Choose:
    [a]dd quotes this time
    [A]lways add quotes (dangerous)
    [n]o quotes today please
    [N]ever offer adding quotes again
    [t]ell me what could possibly go wrong when I choose to always add quotes
    [P]unch the person who proposed this feature
    
    • BatmanAoD@programming.dev
      link
      fedilink
      arrow-up
      5
      ·
      10 hours ago

      For interactive use, tab-completion essentially makes this a non-issue, because shells add escaping in the appropriate places.

      For scripting, where spaces are harder to deal with, unfortunately there’s just not much you can do; your two options are basically to learn all of your particular shell’s patterns for dealing with whitespace in filenames, or only write scripts in something other than a POSIX shell.

      • Luc@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        4 hours ago

        Scripting isn’t the issue, but for tab completion: the boundary is often at a space or parenthesis so that you need to type the backslash + char to continue tabbing to completion

  • AmazingAwesomator@lemmy.world
    link
    fedilink
    arrow-up
    17
    arrow-down
    1
    ·
    edit-2
    14 hours ago

    i think i am old. i grew up using DOS, and really hated spaces in filenames and folders because they appreared truncated at the first space with a tilde and index of that file/folder representation.

    ex: C:\folder name is bad\ == C:\folder~1

    i hated that so much that when i got to windows 3.1 i refrained from using spaces (some command line was still necessary in w3.1)

    i have jept that habit through the years, so when i moved from windoes to linux, my natural instincts of snake_case_folder_names made it so i didnt have to change : D

    • aaaaaaaaargh@feddit.org
      link
      fedilink
      arrow-up
      9
      ·
      13 hours ago

      That’s not even DOS I think. As far as I know Win 95 came up with this monstrosity in an attempt to circumvent the 8.3 character limitations present in older versions of DOS.

    • wizardbeard@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      4
      ·
      12 hours ago

      One of the fun things about modern Windows is that ~1 shit still appears every once in a rare while. Gotta love just stacking more and more shit on top of ancient systems in the name of backwards compatibility!

    • Onomatopoeia@lemmy.cafe
      link
      fedilink
      English
      arrow-up
      4
      ·
      edit-2
      12 hours ago

      Yea, Win 3.1 didn’t support long names - that came with Win95. Win 3.1 was a shell on DOS.

      But I understand - it all blends together after um… 40 years (ouch!).

    • db2@lemmy.world
      link
      fedilink
      arrow-up
      6
      ·
      14 hours ago

      I think you’re misremembering a little. Long filenames was introduced in Win95.

    • Sonotsugipaa@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      14
      ·
      14 hours ago

      They’re annoying to deal with when interactively using command-line shells, especially so when pasting unquoted and unescaped file paths, doubly especially so with Bash where parameter expansion makes no goddamn sense if you know at least one other programming language

      • ronigami@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        13 hours ago

        Example of how parameter expansion matters?

        Generally if you are pasting file paths there is a better way to do that. Use find with exec, or xargs, or a for loop. Or, get the list in Vim and escape (quote) every line at once. Unless you have double quotes in the filename too (which is actually a crazy thing) it shouldn’t be a big deal.

        • Sonotsugipaa@lemmy.dbzer0.com
          link
          fedilink
          English
          arrow-up
          1
          ·
          12 hours ago

          Expansion matters because using parameters without quotes automatically splits words, and IIRC a quoted array parameter can still be split into its members — as opposed to Zsh, where word splitting doesn’t happen unprompted and quoted array parameters are flattened into a single string.

          Generally if I want to run $HOME/random executable with spaces.exe through Wine in a terminal I copy the path in Dolphin (CTRL+SHIFT+C, or CTRL+ALT+C idr) and paste it, within quotes if needed (the four extra key inputs are the annoying part).

          I find that much faster than manually typing find "$HOME" -name "random executable with spaces.exe" -type x -exec wine "{}" \;, or opening an editor to insert backslashes.

          • ronigami@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            edit-2
            8 hours ago

            Why on earth not just type wine ~/random and then hit tab to autocomplete? Or you could do

            wine `echo random*`
            

            AFAIK, if $file is a filename with spaces, then some_util ${file} will not split the filename.

            • Sonotsugipaa@lemmy.dbzer0.com
              link
              fedilink
              English
              arrow-up
              1
              ·
              edit-2
              25 minutes ago

              If the path to the dir is longer than $HOME, say, $HOME/Tools/modding/hd2-audio-modder/wwise/v123456789_idr_but_its_a_long_one/random file name with spaces, it makes more sense.

              I’ll try using the braces syntax, if it does prevent word splitting I wasn’t aware of it, though it’s still slightly inconvenient (3 key inputs for each brace on my kb) and I’d probably still use quotes instead if I had to use Bash and had the file path in a variable for some reason.

              … though at this point I’m probably overthinking it, atm I don’t recall better examples of my distaste for Bash expansion shenanigans.


              Did some testing, here’s what I found.
              Beware, it devolves into a rant against Bash and has little to do with the original topic - I just needed to scream into the void a little.

              # Zsh
              function argn { echo $#; }
              
              var='spaced string'
              argn $var
              # Prints 1: makes sense, no word splitting here
              
              var=(array 'of strings')
              argn $var
              # Prints 2: makes sense, I'm using a 2-wide array where I would
              #           want 2 arguments (the second one happens to have
              #           a whitespace in it)
              
              # Bash
              function argn { echo $#; }
              
              var='spaced string'
              argn $var
              # Prints 2: non-array variable gets split in 2 with this simple reference;
              #           I hate it, but hey, it is what it is
              
              argn ${var}
              # Prints 2: no, braces do not prevent word splitting as I think you suggested
              
              var=(array 'of strings')
              argn $var
              # Prints 1: ... what?
              
              echo $var
              # Prints array: ... what?!?
              #               It implicitly takes the first element?
              #               At least it doesn't word-split said first element, right?
              
              var=('array of' strings)
              argn $var
              # Prints 2:
              


              Upon further investigation:

              # Bash
              mkdir /tmp/bashtest ; cd /tmp/bashtest
              touch 'file 1'
              touch 'file 2'
              
              stat file*
              # Prints the expected output of 'stat' called on both files;
              # no quotes or anything, globbing just expands into
              # 2 arguments without *word* splitting
              
              files=('file 1' 'file 2')
              stat $files
              # stat: cannot statx 'file'
              # stat: cannot statx '1'
              # WHY? WHY DOES GLOBBING ACT SENSIBLY WHEN ARRAYS DO NOT?
              

              I get that the Bash equivalent to Zsh’s $array is ${array[@]}, but making $array behave like it does in Bash has no advantage whatsoever.
              … IS WHAT I WOULD SAY IF THAT WERE TRUE! YOU ALSO HAVE TO QUOTE "${array[@]}" BECAUSE WE LOVE QUOTES HERE AT BASH HQ!

              # ... continued from before
              stat "prefix ${files[@]}"
              # stat: cannot statx 'prefix file 1'
              # (regular 'stat' output for 'file 2')
              

              While this behavior doesn’t make much sense to me, it also doesn’t make sense for me to write that “prefix” within the quotes in the first place, right?
              YES. BECAUSE SPLITTING IS NOT WHAT YOU EXPECT WHEN YOU PUT STUFF IN QUOTES.

              Sorry, I’ll stop.

              • ronigami@lemmy.world
                link
                fedilink
                arrow-up
                2
                ·
                37 minutes ago

                My bad, I was thinking of zsh. And I think it’s configurable there too so may not behave that way according to your settings. But it is at least the default on Mac.

                • Sonotsugipaa@lemmy.dbzer0.com
                  link
                  fedilink
                  English
                  arrow-up
                  1
                  ·
                  edit-2
                  21 minutes ago

                  I use Zsh too, though at this point is becoming detrimental to my (already limited) Bash skills because of features like the ${^array}{1,2,3} syntax which I use in some scripts of mine, which in turn I wouldn’t dare try to translate to Bash.

  • Lyra_Lycan@lemmy.blahaj.zone
    link
    fedilink
    English
    arrow-up
    8
    ·
    edit-2
    14 hours ago

    Windows is stupid as shit, trying to shift+right click > open Powershell in a path containing a space results in it throwing an error, and you have to paste the path in yourself anyway