10

I'm using Ubuntu 10 and I'm quickly finding out that it's case sensitive when it's inconvenient for it to be so (like when autocompleting file paths with tab in terminal) but also case INsensitive when using the MV and CP commands (also inconvenient when trying to duplicate a filename with a different case).

In essence, I need this command to work but it doesn't.

cp ./filename.txt ./FileName.txt

I just end up with filename.txt:

enter image description here

How can I get the same file with a different case but same name in the same directory?

EDIT: Maerics' comment below helped me remember that I'm actually developing on a Windows shared drive running NTFS which is case INsensitive. This is why even though CP and MV don't generate an error, the file isn't copied (or more likely IS copied, but Windows replaces the already existing one).

6
  • 1
    That's strange : I tested this command without surprise... I have no problem with different cases in the same directory. May 31, 2012 at 19:18
  • 5
    Note that this behavior may depend on the type of filesystem on which these files exist. For example, FAT32 may not differentiate these filenames.
    – maerics
    May 31, 2012 at 19:23
  • WOW. This was the answer Maerics. The files are stored on a mounted drive which is running NTFS. I completely forgot since I'm developing cross platform that I'm using Windows to store the files. May 31, 2012 at 19:25
  • 1
    @advocate: NTFS is case-sensitive, so you should be able to mount it the way you like. However, the question is whether this is what you want :) May 31, 2012 at 19:57
  • Testing is showing that Windows 7 doesn't appear to be case sensitive. May 31, 2012 at 22:50

4 Answers 4

7

NTFS1 and VFAT are not case-sensitive, they are just case-preserving. That means if you create a file named FileName.txt, the file system will preserve the mixed case name, but you can access the file with whatever case combination of the same letters, like FILENAME.TXT, filename.txt or fileNAME.txt. This explains you cannot have two files with the same spelling with only a variation of upper/lower case in the same directory.

SMB exported file system have to implement this behavior not to confuse Windows clients.

ZFS can be configured to behave that way with the casesensitivity=mixed property.

1 Technically, NTFS is case sensitive but the OSes mounting file systems of this type are almost always configured to hide this underlying feature and only preserve the case. Windows can however enable case sensitivity with modifying this register key HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\kernel\dword:ObCaseInsensitive and Linux can mount these file systems with various behaviors depending on the ignore_case and windows_names mount options.

2
  • 5
    NTFS absolutely is case-sensitive. However, Win32 is not case-sensitive, so for practical reasons most people assume that NTFS isn't either. Jun 17, 2017 at 11:58
  • @CodyGray Yes, your are right, thanks for pointing this feature. The underlying NTFS file system allows different file names only differing by the case.
    – jlliagre
    Jun 17, 2017 at 13:37
11

You can enable case-insensitive file name completion in bash by adding the following line to $HOME/.inputrc:

set completion-ignore-case On

Regarding the file names: This depends on the file system. On Linux file systems, there should be no problem. On other file systems, the behavior can be controlled with options to the mount command. See the manual page mount(8) for more information on the available options to mount.

3
  • You are correct. The underlying file system wasn't a Linux filesystem so while CP and MV work, Windows chooses to keep the already existing file (when overriding because of case INsensitivity) case which makes it appear in Unix terminal like the command didn't work at all. Also, thanks for the completion ignore case, that will help a lot! May 31, 2012 at 19:31
  • Is 'On' case sensitive? ;)
    – Arj
    Jun 29, 2016 at 7:32
  • Sadly this won't help you in a script. Aug 28, 2019 at 20:03
2

Is this a property of the filesystem or something else?

pa-ubuntu-11388$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.04.3 LTS
Release:        10.04
Codename:       lucid
pa-ubuntu-11388$ ls -l
pa-ubuntu-11388$ touch filename.txt
pa-ubuntu-11388$ ls -l
-rw-r--r-- 1 dshawley dev 0 May 31 15:17 filename.txt
pa-ubuntu-11388$ cp ./filename.txt ./FileName.txt
pa-ubuntu-11388$ ls -l
-rw-r--r-- 1 dshawley dev 0 May 31 15:17 FileName.txt
-rw-r--r-- 1 dshawley dev 0 May 31 15:17 filename.txt

It works fine for me.

1
  • Maerics above helped me solve the problem. I'm developing in Ubuntu a windows -> linux port but the files are stored on the Windows computer and I forgot I had the drive mounted. The underlying NTFS was preventing both files from existing at the same time. May 31, 2012 at 19:28
1

Ubuntu is not partially case sensitive. It's always case sensitive. filename.txt and Filename.txt are two different files and can be placed in the same directory. So this command:

cp ./filename.txt ./FileName.txt

will work without any problem in the same directory.

5
  • It doesn't though. I've been trying to figure it out for the last hour. May 31, 2012 at 19:19
  • 2
    may be, you don't have filename.txt itself in ur current directory?
    – P.P
    May 31, 2012 at 19:20
  • It's definitely in there. May 31, 2012 at 19:22
  • Maerics above helped me solve the problem. I'm developing in Ubuntu a windows -> linux port but the files are stored on the Windows computer and I forgot I had the drive mounted. The underlying NTFS was preventing both files from existing at the same time. May 31, 2012 at 19:27
  • 2
    I saw Maerics comment. thx
    – P.P
    May 31, 2012 at 19:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .