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
Now look what you've done 🌋
Stop clicking and run for your life! 😱
Uh oh, I don't think the system can't handle it! 🔥
Stop it, you're too kind 😄
Thanks for the love! ❤️
Thanks, glad you enjoyed it! Care to share?
Hacker News Reddit

×

Recommended Posts ✍🏻

See All »
• 3 min read
✨ HTML Share Buttons
Read Post »
• 3 min read
🚅 Next Stop, Yaak
Read Post »
• 4 min read
💻 Wait for User to Stop Typing, in JavaScript
Read Post »