Page 1 of 1

cd Documents Should Not Work?

Posted: Sat Aug 05, 2017 5:29 pm
by Dalmango
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?

Re: cd Documents Should Not Work?

Posted: Sat Aug 05, 2017 6:51 pm
by ukscone
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

Re: cd Documents Should Not Work?

Posted: Sat Aug 05, 2017 7:06 pm
by klricks
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.

Re: cd Documents Should Not Work?

Posted: Sun Aug 06, 2017 6:07 am
by W. H. Heydt
(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.)

Re: cd Documents Should Not Work?

Posted: Tue Aug 08, 2017 6:55 pm
by Dalmango
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.

Re: cd Documents Should Not Work?

Posted: Tue Aug 08, 2017 8:00 pm
by itimpi
Linux and the Mac handle paths identically. Paths that start with / are always absolute, while those that do not are relative.

Re: cd Documents Should Not Work?

Posted: Tue Aug 08, 2017 8:01 pm
by drgeoff
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.

Re: cd Documents Should Not Work?

Posted: Tue Aug 08, 2017 8:19 pm
by Dalmango
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.

Re: cd Documents Should Not Work?

Posted: Tue Aug 08, 2017 9:11 pm
by W. H. Heydt
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.

Re: cd Documents Should Not Work?

Posted: Mon Aug 28, 2017 12:54 pm
by Dalmango
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.

Re: cd Documents Should Not Work?

Posted: Mon Aug 28, 2017 1:36 pm
by jahboater
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