Thursday, 28th August 2008
In Linux, we get from directory to directory as follows:
So "cd public_html" will get you into your public_html directory, which holds your website.
If we now use the "pwd" command we can see we are one directory lower:
You can then use "ls" along with its different options in this new directory to list all your files. You can then "cd" into these new directories. What if you want to get back to your home directory?
Without a directory name, "cd" on its own will return you to your home directory. As "~" is a shortcut for your home directory, you can also type:
Final thing of interest with the "cd" command is how to move up one directory.
defaultuser@frink:~/public_html$ ls -a
. cgi-bin compsoc mozilla
.. projects index.php
Here we use a slight variation of the "ls -A" command which lists hidden files. Here we use "ls -a" which lists hidden files and also these wierd dots. So what do "." and ".." mean? They are simply shortcuts. "." stands for the current directory and ".." means the the parent directory (the directory one level higher then the current). They are always present in any directory.
Here we see that "cd .." brings us up one directory.
Here we moved up two directories. You'll probably never need to move up more than two directories at a time, as you have the "~" shortcut to get back to your home directory.
Here we see that "cd ." keeps us in the current directory. What use is that? Well sometimes you need the current directory shortcut for running your own programs. Lets say your wrote a quick program called "printdate" in your myprograms directory. Lets try and run it:
roryd@frink:~/public_html/myprograms$ ls
printdate
roryd@frink:~/public_html/myprograms$ printdate
bash: printdate: command not found
We are getting an error as Linux only looks in the main system directories for commands you type in (dark places like /usr/bin/), not your personal ones. This is to protect you from running a command accidentally. So how do we run it? Simply tell Linux the command is in your current directory using the "." shortcut:
roryd@frink:~/public_html/myprograms$ ./printdate
Today is Tuesday August 19th 2003
We'll find out later how to set some preferences and have Linux search these directories by default.
As a final note, you can use "." and ".." as part of a path name in virtually any command in Linux. Ok lets copy some files.