0

I have on my Linux NAS miscellaneous folders with identical names, except for case,like this:

  • /data/libraries
  • /Data/libraries/presets
  • /Data/Libraries/presets
  • /Data/Libraries/Presets
  • /merged/readme
  • /merged/Readme
  • /merged/ReadMe
  • /merged/README
  • etc.

This is ok-ish on Linux, even though not desirable, but because this is on a NAS that services Windows PCs, the client PCs get confused and only actually show the content of one of the folders, despite showing all the variations...

There are so many, that I want to automate merging these folders together.

What capitalization we end up with is really irrelevant, although a format of 'Capitalized First Letter Of Each Word' would be preferred, if remotely possible, the ultimate goal is to just have one of each folder name.

(NOTE: I am aware that there may be conflicts in the file names contained in these folders as well, but after discussing, I'm willing to take the risk that there might be identically named files with different content, simply because currently a lot of the content isn't even readily accessible anyway!)

Are there any ready-made CLI tools (or BASH scripts) to do this?

8
  • Are these meant to be the same case-insensitive file/folder names? in that case, you should use a case-insensitive filesystem. What kind of NAS is it? a DIY NAS running Linux? If so, you can use ext4 with the case-insensitivity feature (requires kernel 5.2 or later), or ZFS (I run my steam folders on zfs datasets with casesensitivity=insensitive to avoid problems caused by lazy windows developers who don't use consistent capitalisation for file/dir names.....and symlinks for the dumb ones that make both "Electronic Arts" and mis-spelled "Electrontic Arts" folders). Commented Oct 9, 2021 at 1:15
  • I'm not all that familiar with ext4's case-insensitivity but AFAIK, if you're using ext4, enabling it will require a backup, reformat with mkfs -t ext4 -O casefold ..., and restore. Then you can selectively enable case-insensitivity on directories with chattr +F. Commented Oct 9, 2021 at 1:17
  • As for merging the directories, pick one and just move the files in the others into it. Resolving any conflicts will probably be difficult and require individual examination of each file to decide which one to keep. You could check the sizes or use something like md5sum to compare the files. I'd recommend NOT just overwriting any conflicting files but renaming them to .bak or .1, .2, .3, etc. Turn the other directories into symlinks (or, better yet, convert the fs to enable case-insensitivity). Commented Oct 9, 2021 at 1:20
  • Thanks for the comments... I'ts self built and I am using ZFS, and in hindsight a case insensitive FS would have been nice. I could create a separate dataset for the NAS Share 'folder' with case insensitivity. I assume that when I copy the data to the new dataset, the additional folders would get compacted in to the first instance that was written, ie based on the above list, '/Data/Libraries/Presets' would get merged in to '/Data/libraries/presets'? Commented Oct 9, 2021 at 6:52
  • I'll have to investigate whether ZFS without case-sensitivity does still preserve case where possible, but this might just be a good option. I've ran find . -type d | sort -f | uniq -Di | wc -l, and the answer is 1208... A little too much to do manually, esp. on a headless CLI only system. Commented Oct 9, 2021 at 6:53

1 Answer 1

0

So I ended up creating a separate case-insensitive dataset for the most important subfolder (after renaming the original subfolder) and then ran rsync to move the data in to that new dataset...

Everything is now nicely consolidated, and I'm pretty happy with the end result. AFAICT we didn't lose any relevant data... ;) (Before starting I ran find . | sort -f | uniq -Di, and I only saw folders, no files, so I doubt we could have lost anything!)

There are recommendations out there to NOT do this for a Samba share because Samba is case-aware, bla bla bla, but the worst issue they can cite is that you cannot rename a file from 'Readme.txt' to 'ReadMe,txt', because the underlying ZFS will report that that file already exists... The workaround is obvious: give it a name that is different like "Read Me.txt", or temporarily rename it 'readme1.txt' before renaming it as you want... What none of those that recommend NOT using case-insensitive FS underneath have an answer for is exactly the issue I was running in to!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.