Find Your Way $HOME in Bash

• 1 min read

Today I learned a shorter way to navigate to my home directory while in a Bash terminal. According to this page, when the cd command doesn’t receive any parameters it defaults to $HOME. How convenient is that?! In fact, there are four ways to get to your home directory:

# These are equivalent

cd                  # Defaults to $HOME
cd ~                # Current user's home dir
cd ~$USER           # Given user's home dir
cd /home/$USER/     # Full path

Up until this time I have been using cd ~ exclusively, but now I can switch to cd and knock off two whole characters!

If you enjoyed this tutorial, please consider sponsoring my work on GitHub 🤗

Be the first to cheers

×

Recommended Posts ✍🏻

See All »
• 3 min read
🚅 Next Stop, Yaak
Read Post »
• 5 min read
🪴 Home-Grown Web Analytics
Read Post »
• 3 min read
⛰️ 2022 Recap: Getting Physical
Read Post »