If there is a file and the filename starts with a dot, does that mean you created the file and you are hiding stuff in it, or can the files get created on their own without you creating the filename?
-
4It means the file is hidden. Period. You may create such a file, or it can be generated by the system. There are many hidden files in your home folder storing your configurations. If you use `bash`, one important file among those is `.bashrc`. – Weijun Zhou Mar 14 '19 at 08:25
-
2WeijunZhou, "_It means the file is hidden. Period._" I'm afraid that's just wrong. The default position of `ls`, most GUI file managers, and shell globs is to ignore such files, but that is all. Nothing else differentiates or even cares. – roaima Mar 14 '19 at 23:20
-
@roaima That is pretty much one can say about file names. It's like asking about what `.txt` means in Windows. You may say that only some programs care about the `.txt` suffix and others don't, but that is the convention people use. There's nothing special at all in the file system for `.txt` files but I think no one will question the answer that `.txt means the file is a text file in general` if asked about. – Weijun Zhou Mar 15 '19 at 10:40
-
@Olorin The main point of this question seems to be "what created the hidden file?". – Kusalananda Mar 15 '19 at 10:42
-
1@Kusalananda maybe, but that's not what's been asked. – roaima Mar 15 '19 at 11:15
-
I agree with leaving this one open separately, as 50% of the question is "can the files get created on their own without you creating the filename?"; the previous, linked questions are obviously good material to reference. – Jeff Schaller Mar 15 '19 at 17:23
1 Answers
The only thing "special" about a file or directory with a leading dot in its name, such as .myfile, is that it will not show up in the output of ls by default. It will also not be matched by a file name globbing pattern that does not explicitly match filenames starting with a dot.
Assuming an initially empty directory:
$ touch .myfile # this creates an empty hidden file
$ ls # this will output nothing
$ echo * # this will echo a *
*
These files are usually called "hidden". However, they are only hidden from ls and filename globbing patterns, and not hidden in the sense of "being a secret", or being malicious, or being undetectable or being unreadable by others (that depends on the file's permission and the permission of its parent folder(s)).
Anyone can create hidden files; it's just a matter of putting a dot at the start of the name. The fact that a file is hidden says nothing about how it was created (explicitly by a user or by running some program). For example, some applications create directories with hidden names (for storing configurations and cache files, etc.), and others create hidden files.
For example,
The
bashshell will often create.bash_historyin your home directory, containing the commands that you have typed at the command prompt (so that you can easily recall them in a later session without having to retype them). Upon starting up, the shell will also use.bash_profileand.bashrcin your home directory. If these files exist, they were likely copied to your account when it was created.If you use SSH, you will likely have a hidden directory called
.sshin your home directory. This directory contains public and private SSH keys and may include some configuration files. This directory should not be accessible by others. It is unlikely that you created this directory manually.Many desktop utilities will store their configuration files somewhere under
.configin your home directory and cache files under.cache. Again, it is unlikely that you created these directories manually.
Configuration files in users' home directories (and elsewhere) are often hidden in this way so that they don't clutter the output of ls.
To view all files in a directory, including hidden files, use the -a or -A option with ls (using -A will not show the . and .. names present in any Unix directory).
$ ls -a
. .. .myfile
$ ls -A
.myfile
In the bash shell, * and other shell globbing patterns will not match hidden names. To get them to do that, enable the dotglob shell option with shopt -s dotglob.
$ echo *
*
$ shopt -s dotglob
$ echo * # the * now matches a filename, so it is replaced by it
.myfile
- 320,670
- 36
- 633
- 936
-
Great answer from duplicate: https://unix.stackexchange.com/a/506366/259023 – Weijun Zhou Mar 15 '19 at 10:48