Tilde in Linux

In this article, we cover Tilde in Linux. Most of us would access our Home directory through an absolute pathname that resembles:

/home/$USER/

But, does it stay the same for all users? Even if the default configuration supports that. It can be changed later. Yes, we can change our Home directory.

So, if someone has changed their Home directory then the absolute pathname like the one we described above won’t work. And, that is where Tilde notation becomes quite useful.

Tilde in Linux

Through Tilde (~), we get the notation for the user’s home directory. That ensures, irrespective of the Home directory location, Tilde would get us the desired result. We can use the echo command-line utility to see the directory where it points to:

echo ~

Unless you have made changes to your default Home directory configuration, it should point to:

/home/$USER

Understand it through the following examples.

Example I. To access our own Home directory, we can use:

cd ~

If we wish to access Downloads in the Home directory, then:

cd ~/Downloads

Example II. Similarly, we can also access other users’ home directories as well provided we have the required permissions to do so. If we wish to list the contents of John’s Home directory then:

ls -l ~john

To access their subdirectories like Documents:

ls -l ~john/Documents

In case we wish to know about other users’ Home directories, then the echo command-line utility can get the desired data.

echo ~john

In conclusion, we don’t remember where our or other users’ Home directory is located. All we have to do is use Tilde notation. But, we should have the required permissions to access other users’ Home directories. Otherwise, it won’t work.

Similar Posts