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?
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
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.
Recommended Reading: What is the expansion in Linux?
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.
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).
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.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.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.