Working Directory
Linux Commands - Shells

The Working Directory is the location of the directory that you are currently in.  For example if you log into the system, it is designed so that you will begin in your home directory.  For example, if your username  was tom then your home directory by default would be /home/tom.  When tom logs into the system it places him in the /home/tom directory, which is the current working directory.  So if tom issues the command ls, then it will list the contents of /home/tom.  If tom moves to the /usr directory by using the command cd /usr (which means change directories to /usr) then the current working directory is /usr Current working directory is the current directory that a command will interact with.  Now, that does not mean that you have to be located in a directory to issue a command in the shell.  Regardless of your current working directory you can use a command that interacts with any directory by using a path.  For example, if you were located in the /home/tom directory you could list the contents of the /usr/share directory by using the path of that directory so the command would look like this:
ls /usr/share

Lesson 13 / Lesson 15

One command that will verify your working directory is the command pwd, which stands for print working directory.

Moving Around in Directories
The cd command is the basic way to move around in the directory system.  Cd followed by the directory location will move the users current working directory.  For example,
cd /home

This command moves a user to the /home directory where all user directories are located.  If the user fred wanted to move to their /home directory they would use:
cd /home/fred

There is a shortcut to moving to your home directory.  The ~ is equivalent to the home directory.  As a result fred can move to his home directory with this command:
cd ~

If you want to return to the previous directory you were in you can use this command:
cd -

This makes it easier than typing the full path.
   


The cd command works with absolute paths and with relative paths as well.  If you want to move to the /var/spool/cron you can do that with the absolute path:

cd /var/spool/cron

If you changed the command to the  absolute path:

cd /var

Then you can access the cron directory with a relative path:

cd spool/cron

Note the relative path does not include the beginning “/” as it is relative to your current location on the server, which you can ascertain with:

pwd

This stands for present working directory.

If you wanted to move up into the directory system you could use cd ..

For example if you were located in /usr/share you can move into the /usr directory with cd ..

 


Copyright CyberMontana Inc. and BeginLinux.com
All rights reserved. Cannot be reproduced without written permission. Box 1262 Trout Creek, MT 59874