Section 3.18. Moving to a Directory: cd


[Page 59 (continued)]

3.18. Moving to a Directory: cd

Although I could remain in my home directory and access the various versions of my lyric files by preceding them with the prefix "lyrics/", this would be rather inconvenient. For example, to edit the file "heart.ver1" with the Linux vim editor, I'd have to do the following:

$ vim lyrics/heart.ver1         ...invoke the vim editor. 


In general, it's a good idea to move your shell into a directory if you intend to do a lot of work there. To do this, use the cd command. cd isn't actually a Linux or GNU utility, but instead is an example of a shell built-in command. Your shell recognizes it as a special keyword and executes it directly. Notice that I write shell commands using italics, in adherence to the nomenclature that I described at the start of this book. Figure 3-21 shows how cd works:

Figure 3-21. Description of the cd shell command.

Shell Command: cd [ directoryName ]

The cd (change directory) shell command changes a shell's current working directory to be directoryName. If the directoryName argument is omitted, the shell is moved to its owner's home directory.



[Page 60]

The following example shows how I moved into the "lyrics" directory and confirmed my new location using pwd:

$ pwd              ...display where I am. /home/glass $ cd lyrics        ...move into the "lyrics" directory. $ pwd              ...display where I am now. /home/glass/lyrics $ _ 


Figure 3-22 illustrates the shell movement caused by the previous cd command:

Figure 3-22. cd moves a shell.


Since "." and ".." refer to your shell's current working directory and parent directory, respectively, you may move up one directory level by typing "cd ..". Here's an example:

$ pwd           ...display current position. /home/glass/lyrics $ cd ..         ...move up one level. $ pwd           ...display new current position. /home/glass $ _ 





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net