How does '~' represent your home directory?

QuestionsQuestions8 SkillsProDec, 25 2025
0151

That's a great question! In Linux, the use of ~ (tilde) as a shortcut for the home directory is a feature of the Shell (the program that interprets your commands, like Bash or Zsh).

Here is how it works:

1. Shell Expansion

When you type a command containing ~, the shell performs something called Tilde Expansion. Before the command is actually executed, the shell looks for the ~ symbol and replaces it with the value stored in a system variable called $HOME.

2. A Bit of History

The tradition of using ~ dates back to the late 1970s. On the Lear-Siegler ADM-3A terminal (a very popular terminal at the time), the "Home" key and the "Tilde" key were actually the same physical key.

  • To get to the "start" of the screen (the home position), users pressed that key.
  • Programmers naturally started using that symbol as a shorthand for the "Home" directory in the file system as well.

3. How to see it in action

You can see the "hidden" variable that the shell uses by running this command in your terminal:

echo $HOME

You will notice it gives you the exact same result as echo ~. Both point to /home/labex.

It’s essentially a "nickname" for your personal space on the computer! Does that help clear up the mystery of the tilde?

0 Comments

no data
Be the first to share your comment!