Meaning of tilde expansion in Linux

by Daniel Pham
Published: Updated:

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.

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.

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.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating
Series Navigation«« Previous part: Example about pathname expansion in Linux

You may also like

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.

SUPPORT US

FOLLOW US

Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 DevOpsLite.com – All rights reserved.

Please write sources “DevOpsLite.com” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

0
Would love your thoughts, please comment.x
()
x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.