Create a Dot-Prefixed File

Create a Dot-Prefixed File

A small school tool needs somewhere to keep its class setting. You can use a dot-prefixed file such as .school-config, following a common convention for configuration files. You create and write it using the same tools you use for other regular files.

The dot only affects conventions such as a default listing. It does not encrypt the setting or prevent someone from opening the known path. Keep that distinction in mind before putting anything private in a 'hidden' file.

What you’ll learn

  • Create a dot-prefixed configuration file.
  • Explain why hiding a filename does not protect its contents.

A hidden configuration is still a normal file

  1. Name

    The leading dot follows the hidden-name convention.

    .school-config
  2. Content

    The file stores ordinary text, just like a visible configuration file.

    class=10A
  3. Access

    A known pathname can still be read when permissions allow it.

    cat .school-config
Use dot-prefixed files to follow a useful configuration convention.

Write and read .school-config

Prepare the example

Use a fresh practice folder. We will save an ordinary text setting and read it back. The leading dot is part of the filename in both commands; omitting it would refer to a different entry named school-config.

Bash · Linux terminal

printf 'class=10A\n' > .school-config
cat .school-config

Expected result

class=10A

printf produces the line class=10A, and > sends it into .school-config. cat .school-config then opens that known name directly and prints the saved setting. No special read command is needed simply because the name begins with a dot.

If you use a plain directory listing afterward, the file may be omitted. Use ls -A to include it. That omission does not change the file's permissions: another user who knows the path and has the required access can still read it. Use actual access controls for protection rather than relying on someone not noticing the name.

Create, reveal and write a dot-prefixed file

Linux does not use a special hidden-file attribute for ordinary dotfiles. A file becomes hidden from normal ls output when its name starts with ..

Open a terminal in the directory for the hidden file

First things first, open your terminal. You can do this by pressing Ctrl + Alt + T on most Linux systems, or by searching for "Terminal" in your application menu.

Step 2: Use the touch Command

To create a hidden file, we use the touch command, but we make sure the filename starts with a dot.

touch .myhiddenfile

This command will instantly create an empty hidden file named .myhiddenfile in your current directory.

Step 3: Verify the File is Hidden

If you run the regular ls command, the hidden file won’t show up:

ls
  (no output for hidden files)

To actually see hidden files, you need to use the -a (all) option with ls:

ls -a
.  ..  .myhiddenfile

And there it is! The .myhiddenfile shows up along with the current (.) and parent (..) directory markers.

Step 4: Add Some Content (Optional)

You can edit the hidden file using a text editor like nano or vim. For example:

nano .myhiddenfile

Type anything you like, then press Ctrl + O to save and Ctrl + X to exit.

Create and verify hidden files

Next time, we'll look into how to hide entire directories and how to manage them confidently.

Try it, then check the worked answer

Your task: Does a leading dot stop another authorized user reading the file?

Use a fresh practice folder. We will save an ordinary text setting and read it back. The leading dot is part of the filename in both commands; omitting it would refer to a different entry named school-config.

Bash · complete example for this question

printf 'class=10A\n' > .school-config
cat .school-config

Expected result

class=10A

Worked answer

No; permissions still determine access.

A dot-prefixed name does not stop an authorized user from reading the file. The command can name it directly. To restrict access, inspect the permission and directory traversal rules; renaming it with a dot is not an alternative to those rules.

Check your decision

Does a leading dot stop another authorized user reading the file?
Choose one answer. You can try again.

Answer and explanation

No; permissions still determine access.

A dot-prefixed name does not stop an authorized user from reading the file. The command can name it directly. To restrict access, inspect the permission and directory traversal rules; renaming it with a dot is not an alternative to those rules.

A leading dot does not encrypt a file

Use dot-prefixed files to follow a useful configuration convention. Read, write and inspect them as normal files, taking the dot into account in the path. When a setting is sensitive, solve the access problem with permissions or other appropriate protection.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Create a Hidden Directory →