In the Linux operating system, every user has a designated home directory where individual files, configurations, and settings are stored. It serves as the user's private space on the system, and knowing how to access it is essential for various administrative tasks and general file management. This tutorial provides 2 methods how to get home directory on Linux.
Method 1 - HOME environment variable
On Linux, the $HOME
environment variable holds the path to the current user's home directory. The value of this variable can be printed as follows:
echo $HOME
Output example:
/home/john
Method 2 - tilde symbol (~)
The tilde symbol (~
) is a shell expansion symbol and represents the current user's home directory. It is indeed a convenient shorthand to represent the home directory and is widely used in various shell commands and scripts for this purpose.
echo ~
Leave a Comment
Cancel reply