Meaning of tilde expansion in Linux

Share this post to your friends !

Meaning of tilde expansion in Linux
5 (100%) 1 vote[s]

WriteBash - This article we will learn about the tilde expansion in Linux. There will be many times, you will encounter many examples using tilde in Linux commands.

So what is tilde expansion?

Tilde expansion

There will be times when you see commands like this.

# cd ~

Or like this.

# source ~/.bashrc

Have you ever wondered what that tilde is? What does it mean in the Linux command?

That extended tilde has a special meaning in Linux. In Linux commands, if it starts with a tilde, it has an extended meaning for the user’s home directory.

Going back to some examples, the simplest one is to try echo.

danie@linuxmint ~ $ echo ~
/home/danie

Here, my user is danie and my home directory is /home/danie. So, when I type echo ~ it will print my home directory.

What if the user does not have a name? This can be seen when switching from a normal user to a user root in Linux Mint.

The tilde will expand to the current user’s home directory, here is my normal user.

meaning-of-tilde-expansion-in-linux Meaning of tilde expansion in Linux
Tilde expansion in Linux.

You see in the image above, I have switched to user root. When echo ~ it prints the home directory of the current user (ie the user I use to login to the computer).

Conclusion

The article was quite clear example of tilde expansion. It is not difficult but if you do not understand its meaning, sometimes you will not understand commands from others’ instructions.

Continue reading the series«« Previous part: Example about pathname expansion in Linux
If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.


Share this post to your friends !
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

single post bottom banner
«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.