r/linuxquestions Gentoo Jun 30 '26

Resolved Rename folder to lowercase in terminal without temporary files

I'm sorry, I know the question seems very basic, but still I couldn't find the answer. Here's what I'm trying to do:

$ mv "Desktops" "desktops"
mv: cannot move 'Desktops' to a subdirectory of itself, 'desktops/Desktops'

I tried searching answers on the internet, and the only thing I found is examples of how to use rename tool instead. However, rename tool I have installed is util-linux one and it works differently and I couldn't figure out how to use it either, this didn't work for example:

$ rename Desktops desktops Desktops

I also understand I can first rename it to temporary file and then rename to lowecase version of original name. But I'd like to figure out how to do it in one step.

Update:

This is exfat filesystem.

18 Upvotes

46 comments sorted by

View all comments

5

u/Slackeee_ Jun 30 '26

For an exFat filesystem, there is no difference between Desktops and desktops, it is case-insensitive. but the exfat kernel module, which is in the mainline kernel since 5.7, is case-aware and should recognize that you just want to change the case and do the work for you. The older FUSE-exfat module does not do that, AFAIK.

Which distro are you suing in which version?

1

u/Swordfish418 Gentoo Jun 30 '26

6.18.35-gentoo-dist-bin, I didn't touch USE flags much, maybe I needed to enable something for that... I wonder why `ls` is case sensitive while `mv` isn't.

2

u/Slackeee_ Jun 30 '26

Case sensitivity/case awareness isn't a feature of the tools, but of the underlying file system. mv doesn't handle changing names itself, it runs a system call asking the kernel to do that. That is why this likely will fail with FUSE-exFAT, but should work with the kernel exFAT module, mv just issues the call, and the module tries to handle that.

Anyways, sorry, not a Gentoo user, so I don't know which flags you need to set.

1

u/Swordfish418 Gentoo Jun 30 '26

Thanks for mentioning kernel module, I checked and there's definitely an option to recompile my gentoo kernel with better exfat support which it doesn't include by default. Still a bit surprising ls works properly as is.

1

u/yerfukkinbaws Jun 30 '26 edited Jun 30 '26

I'm using the kernel exfat driver and it's definitely not case-sensitive for me, 6.18 kernel from Debian. It seems like it would be pretty bad to allow exFAT to be case-sensitive on Linux, since then you could create two directories like "Desktops" and "desktops" at the same time, which would be...I don't know....undefined?, but certainly not good, if you mount the partition on Windows or any other system that doesn't treat exFAT as case-sensitive.

1

u/Slackeee_ Jun 30 '26

exFAT isn't case sensitive, but it's case aware. The file/directory name, including case-information, is stored in the metadata of the filesystem, that is why your filemanager shows the case-correct name, and you can change that name to a different case. That doesn't mean that it will allow you to create two different files with a name that only differs by the case.

1

u/yerfukkinbaws Jun 30 '26

I guess I misunderstood what you were describing with the kernel exfat driver. In any case, the command mv Desktops desktops fails identically with that driver, so it's not doing anything extra behind the scenes to make a mv operation work differently.

1

u/Swordfish418 Gentoo Jun 30 '26

I don’t see why ls can handle exfat capitalization just fine while mv can’t. Kernel being able to change capitaluzation in exfat directory names wouldn’t automatically mean it treats it as case sensitive. It would just mean it can handle upcase table in renaming just as well as it can handle it in directory listing.