I’m in the process of switching my machines to Linux Mint from Windows and on my network drive I have a bunch of folders that are sorted with the help of preceding underscores (like this “__folder1” “___folder2”)) so that folders appear in a specific order.

When my Mint machines access the drive they sort by the first letter skipping the underscores and I’d really like to have that functionality back rather than having to rename a bunch of folders to try to sort them again. (I’d like to avoid a preceding ‘A’ workaround if possible as there’s a bunch of folders)

Any suggestions? A setting I’m missing (very likely) or something?

Edit: The more I look the more it looks like I’m going to have to make a custom locale to be able to get the sorting I want from the default Mint file manager.

    • thingsiplay@beehaw.org
      link
      fedilink
      arrow-up
      5
      ·
      7 months ago

      add export LC_COLLATE=C to your “~/.profile”, log off, log back on.

      I’m not sure if this is a good idea to add it to .profile, which would affect every Bash session and program. Global variable like these should be set for the applications you want to affect and not more to avoid side effects, if possible.

      • Papamousse@beehaw.org
        link
        fedilink
        arrow-up
        3
        ·
        7 months ago

        yup, my ll alias is like this for yyyeeaaarrrrsssss because of this

        alias ll='LC_COLLATE=C ls -alFh'
        
    • Gormadt@lemmy.blahaj.zoneOP
      link
      fedilink
      arrow-up
      3
      ·
      7 months ago

      It’s kinda worked

      Now the underscores appear between uppercase names and lowercase names

      So it’s a step in the right direction for me for sure now that they’re at least bunched together

      • s38b35M5@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        7 months ago

        Not a fix, but a workaround I use when symbols and punctuation are treated this way: I use lowercase letters to precede folder names to get the sort I want.

        aFolder1
        bFolder2

        Not elegant, but it works in your case. You could also try other file managers, like Thunar to see if they manage sorting differently

        • Gormadt@lemmy.blahaj.zoneOP
          link
          fedilink
          arrow-up
          2
          ·
          7 months ago

          Honestly I think I’m just going to have to go through and rename the folders as faffing about with locales isn’t my idea of fun lol

          I was going to install Dolphin file manager (which has a sort option that does it the way Windows does) until I saw a known bug of “sometimes crashes without error and just loses the files you were moving” which is an absolute deal breaker for me. I do photography as one of my hobbies and I’d lose my shit if I lost the pictures I took in the process of making backups.

          • s38b35M5@lemmy.world
            link
            fedilink
            English
            arrow-up
            2
            ·
            7 months ago

            Yeah, that sounds like a better long-term solution for you. Once you change your workflow, you shouldn’t have to do it again anyway!

            • Gormadt@lemmy.blahaj.zoneOP
              link
              fedilink
              arrow-up
              1
              ·
              7 months ago

              Plus I wouldn’t have to worry about the issue again on other distros

              It’s just going to really really suck renaming all those folders

              • s38b35M5@lemmy.world
                link
                fedilink
                English
                arrow-up
                2
                ·
                7 months ago

                If you dare, you can automated it with some simple scripting. If I had more than 20 or 30, I’d probably go that route.

                • Gormadt@lemmy.blahaj.zoneOP
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  7 months ago

                  There’s definitely more than that lol

                  Any tips on where to start in that regard?

                  I heard that Nemo (the default file manager for Linux Mint) has bulk rename abilities baked in but that’s all I’ve heard about that

                  • Para_lyzed@lemmy.world
                    link
                    fedilink
                    arrow-up
                    2
                    ·
                    7 months ago

                    Hey, I wrote a script for you since this was a really simple operation. I have 2 versions depending on what you want them to do.

                    I recommend that you make a test folder with a bunch of test directories and subdirectories to make sure this works as expected on your machine.

                    The first will only rename folders with a depth of 1 (meaning it won’t rename subdirectories). This is for if you want to control which specific directories you run this on.

                    Non-subdirectory version

                    #!/bin/bash
                    
                    find . -maxdepth 1 -type d -name "_*" | while read FOLDER; do
                        newfolder="$(echo ${FOLDER} | sed -e 's/^\.\/___/a/' | sed -e 's/^\.\/__/b/' | sed -e 's/^\.\/_/c/')" ;
                        mv "${FOLDER}" "${newfolder}" ;
                    done
                    

                    The second renames all folders including subdirectories (it goes 1 layer deeper at a time). So if you want to just run this from your home directory (or wherever the drive you want to run it on is mounted), you can run it once and be done with it. It only goes 100 folders deep, but you can modify that by changing the {2..100} to another range, like {2..500} for 500 folders deep. Running more layers deep increases runtime, so I assumed you wouldn’t have more than 100 layers of folders, but if you do you can adjust it.

                    Subdirectory version

                    #!/bin/bash
                    
                    find . -maxdepth 1 -type d -name "_*" | while read FOLDER; do
                        newfolder="$(echo ${FOLDER} | sed -e 's/^\.\/___/a/' | sed -e 's/^\.\/__/b/' | sed -e 's/^\.\/_/c/')" ;
                        mv "${FOLDER}" "${newfolder}" ;
                    done
                    
                    for i in {2..100};
                    do
                        find . -mindepth $i -maxdepth $i -type d -name "_*" | while read FOLDER; do
                            newfolder="$(echo ${FOLDER} | sed -e 's/\/___/\/a/' | sed -e 's/\/__/\/b/' | sed -e 's/\/_/\/c/')" ;
                            mv "${FOLDER}" "${newfolder}" ;
                        done
                    done
                    

                    I assume that you at most have 3 underscores preceding a folder name. If that is not the case, you can modify the script as following.

                    If you have more, copy one | sed 's/.../' part for each find section up to the next | symbol (there is only 1 find section for the no subdirectory version and 2 find sections for the subdirectory version) and paste it before or after the others. If you are using the subdirectory version, make sure you copy the corresponding version of the sed command because they differ (the first one containes “^.” that the second one doesn’t)! On your new pasted copy, add an underscore to the part of the text you pasted that has underscores. Then for each of the other sed blocks, change the letter they are replaced with to match.

                    Here is an example with 4 max underscores on the subdirectory script:

                    #!/bin/bash
                    
                    find . -maxdepth 1 -type d -name "_*" | while read FOLDER; do
                        newfolder="$(echo ${FOLDER} | sed -e 's/^\.\/____/a/' | sed -e 's/^\.\/___/b/' | sed -e 's/^\.\/__/c/' | sed -e 's/^\.\/_/d/')" ;
                        mv "${FOLDER}" "${newfolder}" ;
                    done
                    
                    for i in {2..100};
                    do
                        find . -mindepth $i -maxdepth $i -type d -name "_*" | while read FOLDER; do
                            newfolder="$(echo ${FOLDER} | sed -e 's/\/____/\/a/' | sed -e 's/\/___/\/b/' | sed -e 's/\/__/\/c/' | sed -e 's/\/_/\/d/')" ;
                            mv "${FOLDER}" "${newfolder}" ;
                        done
                    done
                    

                    If you have fewer than 3 max underscores, you just delete the relevant sed parts and update the letters.

                    You can also let me know how you want if modified and I can do it for you if you’d like.

                    Using the subdirectory version

                    If you want to use the one that works on subdirectories, create a text file renamesubdirectories.sh in the folder you want it to start from, and paste in the subdirectory script into that file with whatever text editor you prefer. You can then modify the script if necessary.

                    I’m going to try to give GUI instructions, but I haven’t used Nemo in a long time, so I’ve also provided terminal instructions in case those don’t work.

                    Nemo

                    Navigate to the folder you want to start from in Nemo. Copy or move the renamesubdirectories.sh file into this folder (or create the file here if you haven’t done so already, and paste in the subdirectory script, modifying if necessary). Right click on the file and open its properties/permissions (maybe details? Can’t remember exactly what the option is called). Find the setting to adjust permissions of the file, and allow it to be executed as a program/mark it executable, whatever adding the executable permission is called in Nemo. Now you can exit the permissions/properties/details window, and right click the file and run. After a few seconds, refresh (F5 usually). You should now be done and can delete the file.

                    Terminal

                    Navigate to the folder you want to start from, and right click > Open in terminal (I believe Nemo has that option, but it’s been awhile; let me know if not, and I can explain now to navigate there from terminal). Now make the file executable with chmod +x renameunderscores.sh. Run it with ./renameunderscores.sh. Once the next line prints (with your username, hostname, and directory), the command is done and you can exit the terminal and delete the file.

                    Using the non-subdirectory version

                    This will require you to either move the script every time you want to run it, or installing it locally and using the terminal (which is easier). I will explain the terminal version only for this, as moving the script every time you want to use it is very tedious.

                    Again, create the renamesubdirectories.sh file using the text editor of your choice, and modify as necessary. Then create a folder called bin in your home folder (this should automatically be in your path) and copy or move the renamesubdirectories.sh file into that folder. Then (in the bin folder) right click and open in terminal in Nemo, or just open a terminal from applications and navigate to the folder with cd ~/bin. Now make the file executable with chmod +x renameunderscores.sh.

                    You should now be able to navigate to any folder you want, then right click open in terminal, and run the command renameunderscores.sh. Once you are finished, you can delete the bin folder.

                  • s38b35M5@lemmy.world
                    link
                    fedilink
                    English
                    arrow-up
                    2
                    ·
                    edit-2
                    7 months ago

                    I’d use the find command piped to mv and play with some empty test folders first. I’m not familiar with Nemo, though I’ve used it for a short while. I’ve never tried the bulk renaming features if they exist.

                    Depending in how much variation you have in the preceding underscores, REGEX may be useful, but if its just a lot of single underscores you can easily trim them with a single version of the script.

                    Edit: corrected second command typo. I think there’s a rename command I haven’t used in ages that may have args to help here too, but I’m away from the PC

      • thingsiplay@beehaw.org
        link
        fedilink
        arrow-up
        2
        arrow-down
        1
        ·
        edit-2
        7 months ago

        That’s exactly what the last 2 comments from the previously linked issue thread is saying too. According to a comment from Stack Overflow, the LC_COLLATE=C environmental variable setting is dependent on the system locale, which will

        This is likely caused by a difference in locale. In the en_US.UTF-8 locale, underscores (_) sort after letters and numbers, whereas in the POSIX C locale they sort after uppercase letters and numbers, but before lowercase letters.

        -- https://stackoverflow.com/questions/1184268/unix-sort-treatment-of-underscore-character

        So either way, this setting is wrong for your use case. And it shouldn’t be set in .profile all applications by default as well, unless you know what you are doing. You can use this variable with specific applications only too. But as explained, this would not solve your issue anyway.