You can find the home directory of the logged-in user in a Linux (or Unix) shell in the following ways:
- By Navigating to the Home Directory and Listing It;
- By Outputting the Value of the
$HOME
Environment Variable.
Navigate to the Home Directory and List the Current Directory
You can navigate to the logged-in user's home directory by using any of the following commands:
cd
cd ~
cd $HOME
Once you're in the home directory, you can simply use the pwd
(Print Working Directory) command to list the current working directory:
pwd
Output the Value of the $HOME
Environment Variable
You can simply print the value of the $HOME
shell environment variable to output the name of the logged-in user's home directory, for example, like so:
echo $HOME
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.