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.
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:
On the other side, we can also execute the following command by only using tilde (~) along the slash (/) to locate the “Documents” directory:
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.
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:
You can use the following command to get the information about the other users:
It’s quite obvious, but if you want to know the name of the current working directory, you can use the following command:
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.
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.