Franske ITC-2480 Lab 4

From ITCwiki
Jump to navigation Jump to search

Introduction

Linux is a very text file-oriented operating system. As we've learned most of the settings for the operating system are held in text files in the /etc directory and most of the commands that are used to manipulate the system take text input or give text output. Beause of this it's very important to be able to edit and manipulate text on the system which will be a key focus of this lab. In addition, we'll practice creating compressed files, which is useful for backing up files, and creating links between locations on the system.

These same instructions apply if you are completing this lab using the VirtualBox virtual machine software or if you are connected to a machine running remotely on the VMware platform. If you are completing this on campus remember to switch your network connection to the SafeConnect-free ITCnet.

Lab Procedure

Prerequisites

  1. Open an SSH console to your Linux system using the PuTTY software, login with your standard user account

Text File Editing

  1. Change to the /var/www directory which is where the Apache webserver stores it's site files by default.
  2. Verify you can see an index.html file inside of this directory by listing the contents of the directory.
  3. Open up a web browser on your host computer and verify that you can browse to the IP address of your Linux system and still see the "It works" page that you saw in lab 2 after installing Apache.
  4. Before we start making any changes it's a good idea to save an unmodified copy of the file you'll be working on so make a copy of the index.html file and name the copy index.html.orig so that you can always copy it back if you make a mistake.
  5. There are many different text editors available for Linux but systems almost always include some version of "vi" or "nano" so those are the two we'll focus on. In your ssh window open the index.html file in nano by running "nano index.html"
    • NOTE: Because your user does not own this file you may need to edit the file as the superuser.
  6. The nano text editor is fairly simple to use and you should now see the contents of the index.html file on your screen. Try navigating around the file with your arrow keys and changing the "It works" text to "Welcome to My Linux Webserver"
  7. Basic instructions for using nano abound on the Internet. You can get a basic introduction here but it basically comes down to the menu lines at the bottom of the screen showing what your options are. The ^ character is commonly used to indicate the CTRL key so to exit the program (you will be prompted to save changes if you have made any) press CTRL-X or to save without exiting press CTRL-O and follow the prompts at the bottom of the screen.
  8. Save your file with the changed text and then reload the page in your browser on your host system to see if the changes have taken effect.
  9. Experiment with some of the nano menu options such as cutting and "un-cutting" lines of text and searching/replacing text. Once you are comfortable with the nano editor save your changes and exit.
  10. Make a note of which user and group owns your index.html file.
  11. Delete your index.html file and copy your index.html.orig file back to index.html
  12. Try loading the website again and see if it's back to the original text. If you encounter an error it's possible that your index.html file is not readbale by the webserver account so you should use the appropriate command to set the index.html file back to the owner and group of the original file.
  13. Now open the index.html file in vi using "vi index.html"
  14. The vi editor is probably considered more powerful than nano but is less user friendly without the menu at the bottom and a COMMAND mode as well as an INSERT mode. In the COMMAND mode you cannot directly change the text of the file by typing which can be frustrating to new users. Read through the vi tutorial here and try making some edits to your webpage. Once you are familiar with how the vi editor works save your file and exit.

Command Output Manipulation

  1. Change back to your home directory using ls ~.
  2. Run ls -al and notice the files in your home directory.
  3. Now, run ls -al but redirect the output to a file using > filename. So for example, you would run ls -al > listfiles.txt
  4. Notice how there is no command output. This is normal as you redirected the command output to the file listfiles.txt
  5. Use cat to verify the contents of listfiles.txt Notice how it contains the exact same output as running ls -al in the command line.
  6. Now, run ls -al /var/log. Notice how many files there are in the /var/log directory. Lets say we wanted to just know the information of the dmesg log files. For this, we would use a pipe and the grep command.
  7. So, now run ls -al /var/log | grep dmesg. Notice how the output is suppressed to all files that contain the string dmesg.
  8. Whats nice about pipes and redirects is that they can be used back to back in a command.
  9. So lets say we have a senario where we want to get a file that contains all of the information from all .gz files in /var/log.
  10. To do this, we would run ls -al /var/log | grep .gz > gzlogfiles.txt
  11. Now pipe the file into less using cat gzlogfiles.txt | less
  12. Notice how this command is the exact same as running less gzlogfiles.txt.
  13. Now remove the files gzlogfiles.txt and listfiles.txt that were created from this part of the lab.

Creating Archived/Compressed Files

Working With Filesystem Links