Tilde expansion is a powerful tool for the command line that can save you time and typing. Learn how to use tilde expansion in this blog post.
The tilde
- Tilde
(~)
- May refer to your home directory
$ cat ~/.bash_profile
- May refer to another user’s home directory
$ ls -rahul/public_html
Tilde Expansion
The tilde (~)
expansion feature is borrowed from the C Shell and makes it easy to reference files and directories inside your or someone else’s home directory. The ~ character, called a tilde, expands to your own home directory, or, if followed by a user name, by that user’s home directory.
For example, the string ~/ .bash_profile
means “the .bash_profile
in my home directory”. An advantage is that you do not need to know sally’s home directory to reference a file within it, which is useful in environments where home directories exit in non-standard locations.