The LDS logo Go to the Home Page Read about the company Read about our products Get some assistance Drop us a line

Jump to: Support | Shell | Using Bash


This article provides a basic introduction to the Linux shell, including creating, moving, copying and deleting files.

A linux shell often looks like this:

username@shell:~$

What you're seeing is a program, called a shell, running (this particular shell program is called 'Bash', hence the name of this article). The job of this program is to wait for commands, interpret them, execute any other programs if necessary, then go back to waiting for more commands. The text you see (the username@shell:~$) is called a prompt.

Shells can perform a huge variety of tasks, and a enormous number of programs are available on our shell server, so this article will not attempt to be in-depth. Rather, you should read this article, try out the examples, then have a look at some of the more comprehensive articles available on the internet, such as:

So, let's have a look at some of the basic commands you can run. First up, try typing the command labhelp and pressing enter. You should see some information appear on the screen.

This is a custom program we have written to help you remember common linux commands. You can see all sorts of different programs you can run and a brief explanation on what they do - to run a program just type its name and press enter. These are only some of the programs available.

Your files are stored in a special folder, called your home directory. This is similar to the 'Desktop' or 'My Documents' folders on Microsoft Windows. The '~' character in your prompt means you are currently in your home directory.

The ls command lists the files and directories located in the current directory. We will execute it to see what files exist in our home directory. Type the command ls and press enter:

username@shell:~$ ls
www
username@shell:~$

As you can see, you have one item in your home directory - the folder www, where you store files that you would like to be publicly accessible over the internet. This will likely be coloured blue to indicate that it is a folder. You can navigate to this folder using the cd (short for Change Directory) command:

username@shell:~$ cd www
username@shell:~/www$ ls
cgi-bin htdocs
username@shell:~/www$

As you can see, the cd command changed the directory we were located in, and our prompt changed to reflect that. It now tells us that we are located in the directory www, which is located in our home directory. We then executed the ls command to view the contents of the www directory.

As we saw earlier, the ~/www/htdocs directory is where you can place web pages. These web pages will then appear if you type the address http://username.labyrinthdata.net.au (where username is your username) into your browser. Let's try changing to the htdocs directory then creating a file so we can view it in our browser. Type the command cd htdocs and press enter, then type nano index.html and press enter:

username@shell:~/www$ cd htdocs
username@shell:~/www/htdocs$ nano index.html

You should be presented with a black screen with no prompt and some writing down the bottom. This is a text editor called nano. There are a number of text editors available, but nano is one of the simplest. Type the following text:

<html><body>
Hello World!
</body></html>

Press Ctl+X to quit nano. nano will tell you that there are unsaved changes; press Y to agree then Enter to agree to the filename.

You can now visit http://username.labyrinthdata.net.au/index.html (where username is your username) in your web browser and see the file you just made.

Back in the shell, lets try renaming the file. The command mv moves files from one location to another, and also renames files. Type mv index.html anotherfile.html:

username@shell:~/www/htdocs$ mv index.html anotherfile.html
username@shell:~/www/htdocs$

The prompt reappears immediately; this tells you that the mv program has completed. Run ls to verify:

username@shell:~/www/htdocs$ ls
anotherfile.html
username@shell:~/www/htdocs$

You can visit http://username.labyrinthdata.net.au/anotherfile.html (where username is your username) in your web browser and confirm the rename worked. http://username.labyrinthdata.net.au/index.html should no longer work, because you renamed the file rather than copying it.

There is also a file copy command - cp. Lets create a another file the same as anotherfile.html:

username@shell:~/www/htdocs$ cp anotherfile.html file3.html
username@shell:~/www/htdocs$ ls
anotherfile.html file3.html
username@shell:~/www/htdocs$

You should be able to visit both files in your browser. Finally, let's remove both these files. This is accomplished by the rm command:

username@shell:~/www/htdocs$ ls
anotherfile.html file3.html
username@shell:~/www/htdocs$ rm anotherfile.html
username@shell:~/www/htdocs$ ls
file3.html
username@shell:~/www/htdocs$ rm file3.html
username@shell:~/www/htdocs$ ls
username@shell:~/www/htdocs$

Both files have been removed. Take care when using the rm command - files removed with it cannot be recovered!

That concludes this article on the Linux Shell. There are many many more things you can do with it, but these are covered in many other places on the internet. A google search for linux shell tutorial will bring up several useful results. Additionally, feel free to try the commands listed by labhelp - you can do no damage by experimenting.

If you have any problems, contact support.

Have fun!


Jump to: Support | Shell | Using Bash

Site design and content © 2010 Labyrinth Data Services Pty Ltd
ABN 33 142 059 701 Get Firefox