Tardis Beginner Tutorials/7
Tutorial 7: Using the network filesystem to make your homepage
This tutorial will show you how to combine browsing the filesystem with editing files like you learnt in the previous tutorial, and will also demonstrate simple manipulation of files.
First let's browse to our homepages directory. You should already have a publicly accessable directory in your name. Try using your browser to look at http://www.tardis.ed.ac.uk/~[username]. It's an old convention on multiuser linux systems to have users' homepages hosted in a directory prefixed by a tilde ("~"), for instance http://www.tardis.ed.ac.uk/~rain. You should be presented with an empty index page. If you get a "not found" error, don't worry - your "pages" directory has probably not been created yet. First let's browse to your web user directory. Type cd /var/autofs/www/users/[username]/ where [username] is obviously your username. If you successfully completed the last tutorial, you should be able to type ll to see if there is a "pages" directory - if that doesn't work, simply type ls -al. If there is a "pages" directory there, simply cd pages - otherwise you'll have to mkdir pages first.
You are now in your web root. This is where you will eventually put your homepage. For now let's just write a simple message in an index file:
Writing html is far beyond the scope of this document. If you feel you can already make a proper html document, feel free to let rip. However, for now we're simply going to create a plain text file, as it will be shown just fine in your browser anyway. Simply type in something along the lines of "Hooray, i just made my first website on tardis! I feel so special." and press ^O. This will save the file, you don't have to quit the editor yet. Now simply open http://www.tardis.ed.ac.uk/~[USERNAME] in your browser again, and refresh if you need to. You should see the text you just wrote, and so will anyone who goes to that page.
Feel free to write your own html here. If you have code you want to paste from the windows clipboard, you can paste into putty simply by right-clicking in the terminal. All you need to do to copy text from the terminal to the clipboard is to select it with your mouse and it's copied automatically. Although a lot of people use programs to generate html (the most dire of which is frontpage), real men write their html by hand ;) If you want to learn html, i recommend the tutorials at http://www.w3schools.com/html/. If you're already proficient at the basics, that site also has tutorials on xml, cascading stylesheets, etc etc.
For now we're just going to practice manipulating files in our web directory though. Exit nano with ^X and do ls. You should see your newly created index file. Let's make a new directory in the current one called "test":
mkdir test cd test ls
Now let's copy our index over to a new file here:
cp ../index.html ./ ls
Simple enough... let's just cat index.html to check the contents are the same? Now let's modify it (nano index.html to say something different, such as "new directory test", using delete or backspace to remove what we've already written. You can cut out entire lines by pressing ^K. When you're finished ^O and ^X as usual. Now point your browser at http://www.tardis.ed.ac.uk/~[USERNAME]/test/ and you should see your new file.
Now we've copied a file, let's try moving and deleting. Renaming is just a way of moving, so let's rename "index.html" to "test2.html":
mv index.html test2.html ls
Simple huh? Now let's delete our new file.
If you completed the previous tutorial you should be prompted as to whether you wish to delete the file. Pressing anything other than "y" will cancel the operation. So press "y"! Deleting directories is different - there is another level of protection. You cannot delete directories like normal files - you have to use the -r flag to make the deletion recursive. First let's backtrack to our pages directory:
cd .. rm -r test
And it's gone. If you aliased your rm to include -i in the last tutorial, you might find it useful to use the -f flag to force deletion without prompting, for removing large numbers of files. Of course this operation is irreversable, and you should be very careful, especially if you ever combine the r and f flags!
Congratulations, you have just created your first webpage. If you have an existing website with content you wish to upload to tardis, i will walk you through this in a few tutorials. First though you need to understand how programs run under the linux environment, and how you can control their threads in the next tutorial.
Next: Process Control