Dalmango
Posts: 46
Joined: Sat Aug 05, 2017 5:21 pm

cd Documents Should Not Work?

Sat Aug 05, 2017 5:29 pm

Has anyone noticed entering in the Terminal:

Code: Select all

cd Documents
Will move you into the Documents directory. This should not work; it should be

Code: Select all

cd /Documents
When referencing code backward from directories it will not work like this and you must reference correctly with the /.
I can only assume that there is a built in command that enters the / for your and does not display it in the terminal?

User avatar
ukscone
Forum Moderator
Forum Moderator
Posts: 4152
Joined: Fri Jul 29, 2011 2:51 pm
Contact: Website

Re: cd Documents Should Not Work?

Sat Aug 05, 2017 6:51 pm

no cd Documents is correct as the Documents directory is in your home directory and when you open a terminal or login you are in your home directory

cd /Documents would be a Directory called Documents under the root directory

klricks
Posts: 6592
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: cd Documents Should Not Work?

Sat Aug 05, 2017 7:06 pm

When you are in your home folder the path is suppressed and replaced by ~ character.
pi@raspberrypi:~ $ is the same as pi@raspberrypi:/home/pi $

Type ls at pi@raspberrypi:~ $ and you will see the Documents folder listed.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

W. H. Heydt
Posts: 10886
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: cd Documents Should Not Work?

Sun Aug 06, 2017 6:07 am

(I'm just going to cover the same ground, but phrased differently.)

The path to a file or directory can be an absolute path, such as /Documents, or it can be a relative path, such as Documents. A relative path starts from your current working directory (use the command pwd to see what it is). The default is to start from your home directory, e.g. /home/pi (and note that that is an absolute path, since it starts with a /). So if I have a music directory within my home directory, I would play a track using mplayer music/album/trackN.wav. But if I want to play a track that is on a USB stick named "music", I would use mplayer /media/pi/music/album/trackN.wav. See the difference? (I've omitted any other mplayer parameters or flags for clarity.)

Dalmango
Posts: 46
Joined: Sat Aug 05, 2017 5:21 pm

Re: cd Documents Should Not Work?

Tue Aug 08, 2017 6:55 pm

Thanks for the input guys, I thought whenever you type in the terminal all references are relative to what directory you are currently in.

This is the case in Terminal on the Macintosh and I thought (and think it is the case in Linux). If you wanted to type

Code: Select all

cd Documents
you would need to be in the home directory. If you wanted to access the bin from the home directory from the home directory you would need to type

Code: Select all

cd ../../bin
Thus all paths written in the Terminal are relative - no?

Thanks again, so glad I bought this Pi.

itimpi
Posts: 1089
Joined: Sun Sep 25, 2011 11:44 am
Location: Potters Bar, United Kingdom
Contact: Website

Re: cd Documents Should Not Work?

Tue Aug 08, 2017 8:00 pm

Linux and the Mac handle paths identically. Paths that start with / are always absolute, while those that do not are relative.

drgeoff
Posts: 9808
Joined: Wed Jan 25, 2012 6:39 pm

Re: cd Documents Should Not Work?

Tue Aug 08, 2017 8:01 pm

Dalmango wrote:
Tue Aug 08, 2017 6:55 pm
Thanks for the input guys, I thought whenever you type in the terminal all references are relative to what directory you are currently in.

This is the case in Terminal on the Macintosh and I thought (and think it is the case in Linux). If you wanted to type

Code: Select all

cd Documents
you would need to be in the home directory. If you wanted to access the bin from the home directory from the home directory you would need to type

Code: Select all

cd ../../bin
Thus all paths written in the Terminal are relative - no?

Thanks again, so glad I bought this Pi.
A path is relative if it does not start with a '/'. It is absolute if it does.

And Terminal has no bearing on the matter.

Dalmango
Posts: 46
Joined: Sat Aug 05, 2017 5:21 pm

Re: cd Documents Should Not Work?

Tue Aug 08, 2017 8:19 pm

Thanks drgeoff, I thought Terminal had the same sort of set-up as Linux and was more or less Linux so thanks for clearing that up.

W. H. Heydt
Posts: 10886
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: cd Documents Should Not Work?

Tue Aug 08, 2017 9:11 pm

Dalmango wrote:
Tue Aug 08, 2017 8:19 pm
Thanks drgeoff, I thought Terminal had the same sort of set-up as Linux and was more or less Linux so thanks for clearing that up.
Linux (and unix, for which Linux is a "workalike") are identical in this regard. MacOS was, at least at one time, based on BSD unix. I don't know how far it has diverged since it's inception. When you open a terminal window, you are running a command line shell. The default in most modern distributions of Linux is bash. If you don't like bash, you can change it. You can even change the default on an account-by-account basis by editing /etc/passwd.

Dalmango
Posts: 46
Joined: Sat Aug 05, 2017 5:21 pm

Re: cd Documents Should Not Work?

Mon Aug 28, 2017 12:54 pm

Thanks guys, I get it completely now; paths that start with / are absolute. It's taken me years to grasph this; I'm amazed this isn't clearer on tutorials out there.

jahboater
Posts: 4685
Joined: Wed Feb 04, 2015 6:38 pm

Re: cd Documents Should Not Work?

Mon Aug 28, 2017 1:36 pm

Dalmango wrote:
Mon Aug 28, 2017 12:54 pm
Thanks guys, I get it completely now; paths that start with / are absolute. It's taken me years to grasph this; I'm amazed this isn't clearer on tutorials out there.
Its probably worth spending time wandering round the file system to get used to it all. Some useful commands ...

"pwd" (short for Print Working Directory) can tell you where you are, that is, give you the absolute path to your current directory.

"~" is shorthand for your home directory "ls ~/Documents" lists the files in your own Documents folder regardless of where you currently are. Its the same as $HOME.

"cd" on its own with no argument will take you home.

"tree | more" will give a (long) semi graphical map of your directories

"cd /" takes you to the top of the tree

"find ." lists all your files and directories

"find . -type d" lists all your directories

Return to “Beginners”