35

I was wondering what the difference between these two were:

~/somedirectory/file.txt

and

~/.somedirectory/file.txt

It's really difficult to ask this on Google since I didn't know how to explain the . when I didn't even know what to call it. But can someone describe the difference between including the dot and excluding it?

5 Answers5

25

Under unix-like systems, all directories contain two entries, . and .., which stand for the directory itself and its parent respectively. These entries are not interesting most of the time, so ls hides them, and shell wildcards like * don't include them. More generally, ls and wildcards hide all files whose name begins with a .; this is a simple way to exclude . and .. and allow users to hide other files from listings. Other than being excluded from listings, there's nothing special about these files.

Unix stores per-user configuration files in the user's home directory. If all configuration files appeared in file listings, the home directory would be cluttered with files that users don't care about every day. So configuration files always begin with a .: typically, the configuration file for the application Foo is called something like .foo or .foorc. For this reason, user configuration files are often known as dot files.

  • 1
    "More generally, ls and wildcards hide all files whose name begins with a .; this is a simple way to exclude . and .. and allow users to hide other files from listings." This sounds like the following: The concept of hiding files/directories that start with a dot has actually appeared to hide . ... But later, people realized that being able to hide some files/directories has a value in it and hence, they began to put a dot at the beginning of the files which they want to be hidden. Is that really the case or just a speculation? – Utku Oct 05 '15 at 14:17
  • 3
    @Utku Actually, it was the other way round, as least at first: the original developer intended to hide only . and .. but made a mistake. It's however possible that he was dissuaded from fixing it because some users found it useful, and the reason why user configuration files start with . is definitely so that they don't clutter the output of ls in the home directory. I think we have a question about this here but I can't find it, it may have been mistagged. – Gilles 'SO- stop being evil' Oct 05 '15 at 18:49
  • Early Unixes stored user configuration files in the user's $HOME directory, so they'd be easily findable. As the number of user configuration files grew, "namespace pollution" was seen as a problem (why does ls show me 17 configuration files, plus the 4 I care about?). So, it was decided to preface the user configuration files with a ".", and cause ls to default to not listing them. There are ls -a (list ALL) and ls -A(ALL except ., and..). This convention (don't list dotfiles) only applies to ls (and shell wildcards). Other tools see all the files all the time – waltinator Feb 07 '22 at 22:50
19

Directorys starting with a dot . are considered to be hidden. That means:

  • ~/somedirectory and ~/.somedirectory are different directories. That is if ~/somedirectory existed and you did mkdir ~/.somedirectory, you won't fail with a File Exists message.

  • The ls command will not show those directories starting with the .

  • The ls -a will show both directories

  • The ls -A displays files and directories that start with ., but doesn't include the . and .. entries.

Sid110307
  • 105
  • 5
Tom
  • 291
  • 7
    ls -A displays files and directories that start with . but doesn't include the . and .. entries. – Julian Sep 30 '11 at 15:47
7

For details on the Unix file system check the standard. Specifically, dot files are used for configuration files in a users directory, and if a program has more than one, it should put them into a dot directory.

This hides the files from the user, unless they want to find them. That way they don't get in the way, and tools don't go messing with them accidentally.

4

The leading "." in a directory or file name causes that directory or file to be hidden when doing a ls command.

2

Like @DaveNay already said, that period will cause the file or directory to be hidden.

For your second implicit question, this is how you search for that in google:

Just type in the search box: linux period before name