37

Sometimes it makes practical sense for a folder name to contain a dot (.). For example, you are storing data for an experiment conducted at L=0.5. So the folder might be named:

experiment_L0.5

A similar issue may arise for file names. For example:

file_L0.5.txt

Working in Ubuntu, is this bad practice? What about sharing these directories with a Windows user?

1
  • 5
    If the dot is the first character, the folder will be hidden. Other than that, I don't think it matters. Jan 30, 2014 at 16:40

5 Answers 5

46

As far as I know there are no issues with naming folders and files with a single or multiple dots.

Ubuntu generally does not use the dot and three characters (such as .txt) to identify the file type. So this has no special meaning in the Ubuntu context. This is useful when sharing files with Windows. Ubuntu uses Magic Numbers in the first few bytes of the file to identify the file type. However, Nautilus ignores the magic numbers if the dot and three characters extension is available to identify the file type. This setting can be changed. See Force nautilus to ignore extensions

In Ubuntu, starting a file or folder names with a dot, such as .experiment_L0.5, makes the file or folder hidden. You can toggle the display of hidden files by pressing Ctrl+H in Nautilus. In Windows a file name starting with a . in front of it is not hidden. So if you transfer a hidden file named .experiment_L0.5 into a Windows system, it will be plainly visible.

In Ubuntu a file name can end with a dot, as it has no special meaning placed at the end. However, in Windows a dot separates the file name and extension, and a file name ending with a dot but no extension is not allowed. When I tried to create such a file in Windows I got a file with just the name, no dot, no extension.

Reference: Wiki on Filenames

Hope this helps.

7
  • 5
    This is correct. If you share files with windows, you have to avoid the colon : char, illegal in windows file names, which will create problems (and it does). See also here.
    – Rmano
    Jan 30, 2014 at 16:57
  • Thanks @Rmano. I have added a link to the wiki in my answer.
    – user68186
    Jan 30, 2014 at 17:07
  • 1
    Speaking about compatibility, I think that a trailing dot (like fname.) is not allowed in Windows neither.
    – Rmano
    Jan 30, 2014 at 17:38
  • Thanks again @Rmano. I ran a few quick tests and failed to create a file named test. in Windows. I will update my answer.
    – user68186
    Jan 30, 2014 at 19:01
  • 1
    To add to Rmano's comment - this can be an issue on Ubuntu if you have a Windows drive mounted via VirtualBox. Trying to mkdir a name with a trailing dot fails with 'Protocol error'.
    – bvanlew
    Apr 6, 2017 at 10:49
17

The short answer

  • Windows does not allow the following characters: <>:"/\|?* (source)
  • More characters that are discouraged are: space and dot . (source)
    • Command line tools are harder to use when you have spaces in names (harder, not impossible)
    • Dots are used in RegEx (e.g. when you want to use grep). A leading dot makes a file hidden by convention in Linux. In Windows, dots are used in the file extension, which is used for file type detection.
  • Windows also will not allow filenames CON, PRN, AUX, CLOCK$, NUL COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9 LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. (source)
  • The only characters not allowed in Unix file systems I know are / and null (the null byte, \0).
  • See also: File system limits (I don't know to which Windows you want to be compatible).

The long answer

Technical background: File System

Ubuntu makes use of the ext4 file system. A file system tracks where files are stored on the underlying storage (disk or SSD or whatever), permissions in the form of owner/group/other can read/write/execute, timestamps, name.

The file system structures the available storage. The first block is called the "superblock". This block is used to mount a file system. As far as I know, every modern file system divides it's space in blocks. I think (and I'm not too sure about it) that most file systems also have a fixed block size, though the block size can be configured when the file system is created. ext4 (and also ext2 and ext3) make use of so called "inodes" for files and directories. Those inodes contain pointers to other blocks (that might also be inodes or be "data blocks"). And the "first" inode of a file contains all of the information I mentioned above.

One other information is the "type" of the file. "Type" can be:

  • regular file
  • directory
  • device file (block or character device)
  • ...

In fact, you can also open directories with an editor:

vim /home

As the directory does not contain the full path, but only the names of the content I don't see a reason why files can not contain a /. I guess it might be convenience. (Does anybody know why / is not allowed?)

However, things are different for other file systems. The FAT16 and FAT32 used a so called "file allocation table". This means there is a table that contains all files that are stored on your file, at which "cluster" they start and at which cluster they end as a singly linked list.

The important thing I wanted to tell you is that disallowed characters might also depend on the file system.

Technical background: File Types

  • Windows uses file extensions to detect file types
  • Linux uses "Magic Bytes" to detect file types. Magic Bytes are part of the content of the file and hence completely independent of the name. These bytes are part of the specification of the file type (see png specification as an example). It also uses the filename extensions for files with the same magic bytes such as .txt or .html (both are text files).

Related

2
  • Your guess regarding how FAT stores filenames is not quite correct: en.wikipedia.org/wiki/FAT32#File_Allocation_Table - the actual "FAT" stores the list of clusters, while directories store a list of filenames with a pointer to the first cluster of a file, similar to how you describe ext4. :) Also, .txt and .html files do indeed have different "magic values" - try renaming a html file to test.txt and running file test.txt. It doesn't have much relevance to the original question, but still :)
    – Sergey
    Feb 7, 2014 at 3:38
  • 1
    Thanks, I've removed the wrong part about FAT. about the magic values and file: file does not only use magic values to determine the type of a file. Every valid HTML-file is a text file (in the sense that it does contain readable characters), but not every valid text file is a valid HTML file (in the sense that it validates against W3C validators). So quite a lot of file types (html, xml, csv, js, php, c, h, cpp, ...) are in fact text files. Only binary files have magic bytes that are on well-defined positions. All of the files I named above can have arbitrary whitespace before content. Feb 7, 2014 at 7:49
6

For completeness' sake, the names which consist only of a single dot . or two dots .. are special:

  • . refers to the current directory
  • .. refers to the parent directory

Those entries are added automatically and always exist, so you can't have a file named . or ...

1
  • Good point. This applies to both Windows and Ubuntu.
    – user68186
    Feb 4, 2014 at 21:56
1

This do not matter, not in linux nor in windows.

It's a common practice to have folder named "program.d" - to save configuration and stuff for a program (look in /etc directory)

1

File naming is very flexible in Unix, Linux file-systems. The only file-name you can't have is a null character or the one containing a / in its name. But it surely would be a good practice to avoid using the characters that are forbidden/reserved in other systems from name-portability point of view; like you shouldn't use any of " * : < > ? \ / | characters (restricted by NTFS) in your file-name if you want to access the file in a Windows system.

And about using a . (period) in file-name, I think it should be fine as it doesn't seem to be a "reserved" character in any of the systems (except for OpenVMS, MS-DOS and Windows where its use in file/directory name is allowed but the last occurrence will be interpreted to be the extension separator in VMS, MS-DOS and Windows) as mentioned in the Wikipedia link that follows:

In other systems, usually considered as part of the filename, and more than one period may be allowed. In Unix, a leading period means the file or folder is normally hidden.

0

You must log in to answer this question.

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