15

Initially I thought it was a coincidence, but now I see there's even a tag for it: all hidden file names start with a dot. Is this a convention? Why was it chosen? Can it be changed? Or in other words (as a related question @evilsoup suggested that implies the answer to a bunch of others): can I hide files without renaming them (using . as the first character of their name)?

  • Or "why do all hidden file names start with a dot?", if you prefer. – JMCF125 Aug 30 '13 at 14:14
  • 2
    Yes it's a convention, as to why it was chosen who knows, go ask the UNIX pioneers, it's an old convention. – terdon Aug 30 '13 at 14:16
  • 4
    Read the related Wikipedia article about hidden files and plus.google.com/101960720994009339267/posts/R58WgWwN9jp for the history aspects. It cannot be changed. – jofel Aug 30 '13 at 14:19
  • I thought Linux was fully customizable... – JMCF125 Aug 30 '13 at 14:25
  • 1
    @JMCF125 actually that comment came out as a bit more sarcastic than I intended, sorry about that. Are you actually asking: 'can I hide files without renaming them?' -- if that is the case, you should edit that into your question. – evilsoup Aug 30 '13 at 16:39
25

According to Wikipedia,

The notion that filenames preceded by a . should be hidden is the result of a software bug in the early days of Unix. When the special . and .. directory entries were added to the filesystem, it was decided that the ls command should not display them. However, the program was mistakenly written to exclude any file whose name started with a . character, rather than the exact names . or ...

...so it started off as a bug, and then it was embraced as a feature (for the record, . is a link to the current directory and .. is a link to the directory above it, but I'm sure you know that already). Since this method of hiding files actually is good enough most of the time, I suppose nobody ever bothered to implement Windows-style file hiding.

There's also the fact that implementing different behaviour would produce an even greater amount of fragmentation to the *nix world, which is the last thing anyone wants.

There is another method for hiding files that doesn't involve renaming them, but it only works for GUI file managers (and it's not universal amongst those -- the major Linux ones use it, but I don't think OSX's Finder does, and the more niche Linux file managers are less likely to support this behaviour): you can create a file called .hidden, and put the filenames you want to hide inside it, one per line. ls and shell globs won't respect this, but it might be useful to you, still.

  • That hiding doesn't work on Unity though. But as you directly addressed all questions, I'll mark this as the accepted answer (although I upvoted both answers). – JMCF125 Aug 30 '13 at 20:14
  • 3
    The Wikipedia page no longer contains information on this. However, Rob Pike worked on UNIX at Bell Labs and made a short post about the topic: plus.google.com/u/0/+RobPikeTheHuman/posts/R58WgWwN9jp – Alexander Mar 12 '14 at 10:30
14

Files starting with a dot are ignored by default by the command "ls", which has more or less the same effect of "hidden" files but is not the same (other commands may choose to do the same or not). Files starting with a dot are not "hidden" because "hidden" is not one of their attributes. Unlike in DOS/Windows, "hidden" is not an attribute in Unix. There are many attributes in Unix ("man chattr" will tell you all of them) but hidden is not one of them.

The reason why dot-files are ignored by "ls" is actually quite funny / embarassing. It was not a design decision but the result of a software bug in the early days of Unix. When the special . and .. directory entries were added to the filesystem, it was decided that the ls command should not display them becasue they were getting in the way. However, the program was hastily written to exclude any file whose name started with a . character, rather than the exact names "." or "..". And it created a precedent that has been followed since then in Unix. Funnily enough, when the Unix guys moved on to create Plan 9 they did not put dot-files in it on purpose.

  • I did try man chattr, though I thought perhaps I'd need some package or specific program to make other hidden files possible. – JMCF125 Aug 30 '13 at 17:17
0

Whether you can hide files or not, and on what conditions, depends on the filesystem you're using and its driver. Traditional Unix filesystems don't have a "hide" attribute for files.

A filesystem driver can hide any files it wants, by simply omitting their names when it provides results to system calls that are used to get a directory listing. As sergut described in his answer, files starting with a dot are not truly hidden.

(This is also how rootkits can hide their files: they hook into the system calls that produce directory listings, and filter out the files they want to hide.)

For example, in Oracle ACFS cluster filesystems, the directory <filesystem mountpoint>/.ACFS/ is truly hidden: it just won't be listed at all, not even with ls -a. But if you know it's there, you can access it just fine.

If you're using the snapshot feature of the ACFS filesystem, you can access any existing filesystem snapshots of that filesystem through that .ACFS directory. If it wasn't hidden, a backup program might end up backing up both the current contents of the filesystem and the contents of any existing snapshots, which would probably be undesirable; normally you would want to back up either the current state or the state of one specific snapshot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.