LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   confused about when to use cd ~/whatever or cd /whatever (https://www.linuxquestions.org/questions/linux-newbie-8/confused-about-when-to-use-cd-%7E-whatever-or-cd-whatever-4175556735/)

l0r3n 10-20-2015 09:59 PM

confused about when to use cd ~/whatever or cd /whatever
 
Hi everyone!

I'm confused.

Sometimes in the terminal I have to type in cd ~/ to get to the directory i want, and sometimes cd /

for example, cd /boot or cd /bin works, but cd ~/bin or cd ~/boot does not

however

cd ~/Dropbox or cd ~/Documents works, but cd /Dropbox or cd /Documents doesn't.

can someone explain this to me?

Thanks for looking at my question,

Loren

syg00 10-20-2015 10:13 PM

Try this and see if it helps
Code:

echo ~

yancek 10-20-2015 10:20 PM

The symbol ~ means your user /home directory.

Quote:

for example, cd /boot or cd /bin works, but cd ~/bin or cd ~/boot does not
That's because there is no bin or boot directory in your /home/user directory.

Quote:

cd /Dropbox or cd /Documents doesn't.
If you are in your /home/user directory then using cd Documents will work. If you want to change to a directory which is in the directory you are using, for example /home/user which has a Documents directory, don't use the forward slash /.

It depends also on where you are starting from. If you have a directory named junk in your /home/user/Documents directory you can get to it by simply typing: cd junk IF you are in the /home/user/Documents directory. You can access anything by using the full path from anywhere in the system.

l0r3n 10-20-2015 10:34 PM

Thank you so much.

It is quite revealing when the curtain is pulled back just a bit, and I realize how much I don't know. I didn't realize that in my original post, when the cd paths I used worked, it was because i was typing in the exact correct path. See, what I thought was happening was something magical. like by typing cd /loren for example, that i would be magically transported there, regardless of my starting point. It would be nice, but what if there where two "loren" directories, in different places, right? how would that work? luck of the draw?

Anyway, thanks.

loren

frankbell 10-20-2015 10:37 PM

I've found pwd to be a useful command. It stands for print working directory and will tell you what directory you are currently in.

This page gives you a number of useful tricks for using the cd command. I am particularly fond of

Code:

cd .. 
cd -



All times are GMT -5. The time now is 03:28 AM.