Linux Commands

What is Tilde in Linux

Tilde (~) is a meta character in Linux that has a special meaning within the confines of the terminal’s shell. It is a Linux “shortcut” that is used to represent the user’s home directory. Tilde (~) shows the user’s home folder of the current directory. The user can type commands like cd/ at the command prompt. This command changes the directory to the root folder.

If you ever come across tilde but don’t know how to use it, this guide is for you. In this guide, we will give you a brief information on tilde in Linux with the appropriate examples.

What is Tilde in Linux?

In this section, we will use multiple examples so that you can understand everything about tilde in Linux.

Example 1:
Let’s start with the basic example where we want to use the “Documents” as the current working directory in the terminal. First, execute the following command having the complete location of the directory:

cd /home/user/Downloads

On the other side, we can also execute the following command by only using tilde (~) along the slash (/) to locate the “Documents” directory:

cd ~/Documents

Running both the previous commands in the terminal gives the same output. However, tilde has replaced the directory location, i.e. /home/user, to provide the same result.

Example 2:

Let’s use the echo command with tilde to print the path of your home directory. Let’s run the following command to get the results:

echo ~

You can use the following command to get the information about the other users:

echo ~ <user>

It’s quite obvious, but if you want to know the name of the current working directory, you can use the following command:

echo ~+

Finally, we can only use tilde to get the information about the user and the directory.

Hence, it proves that tilde in Linux is an advanced substitute for the /home/user directory.

Conclusion

A tilde (~) in Linux is used as a replacement for the /home/user directory while changing the current working directory in the terminal. In this guide, we included every possible detail related to the tilde symbol in Linux. We also explained what tilde (~) is and how to use it in a Linux terminal. Tilde is a simple alternative that can save up your time while working on Linux. Hopefully, this guide helped you learn more about tilde in Linux.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.