Dot files in Linux

Hidden files, folders .DS_Store

According to Wikipedia, a hidden folder or hidden file is a folder or file which filesystem utilities do not display by default when showing a directory listing. In Unix-like operating systems, any file or folder that starts with a dot character(.), known as a dot file or dotfile, is treated as hidden — that is, the ls command does not display them unless the -a flag is used with it (ls -a).

Use of dot files

The dot files are commonly used for storing user preferences or preserving the state of a utility, and are frequently created implicitly by using various utilities. For example, in the Apple macOS operating system, there is a file in each directory named .DS_Store(Desktop Services Store) which is a file that stores custom attributes of its containing folder, such as the position of icons or the choice of a background image. So .DS_Store stores metadata about the display options of folders, such as icon positions and view settings. The dot files are not a security mechanism as the access to them is not restricted but the idea behind them classified as hidden is that the files that were not created directly created by the user need not be displayed causing unnecessary clutter.


The history behind the dot files is very interesting. The notion that filenames starting with a . are hidden is because of a bug. In the early days, to allow easy navigation, a single file with a dot (.) was added to each directory and later a double dot file (..) was added to easily move up in the directory structure. Since these were just for navigation purposes, the programmers decided to not display these to the user. So they wrote the following code :

if(filename[0] == ‘.’) {
ignore the file

instead of :

if(filename == ‘.’ || filename == ‘..’) {
ignore the file

As a result all files starting with . was ignored. Later, this was embraced as a future and thus came the concept of hidden files.