CSC 325 Operating Systems with an Emphasis on UNIX
Assignment 2
In this assignment we explore basic Unix commands and the Linux file structure. Note: In your answers, be sure to answer the questions using complete sentences.
Welcome to a class that may change your world into one that is no longer entirely managed by Microsoft. Let's beginby reading a fairly detailed comarison of Linux to Windows that can be found at http://www.michaelhorowitz.com/Linux.vs.Windows.html.
In this course we will work with Linux. Linux's kernel was developed by Linus Torvalds at the University of Helsinki in Finland, so Linux is a contraction of "Linus' Unix". Because Linus is pronounced "Lynn-iss" in Swedish, this is a cute play on words. In this course we will use the term "Unix" or "Unix-like'' to describe systems intentionally similar the historic types of Unix. In particular, the term "Unix-like'' includes all major Unix variants and Linux distributions. Originally, the term "Unix'' meant a particular product developed by AT&T. Then for many years there were competing distributions of Unix. Today, the industry standards group known as "The Open Group" owns the Unix trademark and certifies and brands Unix implementations. So, some people now recognize this trademark and calls Linux distributions "Unix-like" systems rather than a "Unix" systems, but most people simply make no distinction and consider any Linux distribution a type of Unix regardless of whether or not it meets these standards. In fact this confusion lead to a famous lawsuit in 2003. For our purposes, we should call Linux Unix-like and be done with it, but our course title was chosen before 2003...
So, how are Unix-like systems different? Windows XP requires the GUI at all times. Yet, some applications, such as web servers and file servers, not only don't need a GUI, but also don't benefit by it. The Linux GUI, called X Windows, is totally optional, so you may choose to use or not. Additionally, you can start and stop the Linux GUI anytime you like without restarting or impacting any programs already running. Unfortunately, most people who have become computer users on a Windows machine never learn to let go of the GUI so never come to know the power of the command line. It is for these reasons, that I wish to first introduce you to Linux command lines.
Because I want you to record your experience, I recommend using either the emmulator mode or the terminal mode inside of X for this assignment. Note that both Linux and Linux ARE case sensitive, so be sure your capslock key is off.
Ideally, this assignment should be completed individually.
- In Linux it is a bad idea to log in as root unless you need root capabilities, so if you have not already done so, please use the "adduser" command to add yourself to your Linux system as a user. Then if you are still logged in as root "exit" and login as this new user. You may want to use the same login name as is used on campus so as to not get confused.
- Log into your user account at the command line. You should see a prompt that looks something like:
pearcej@topologilinux:~$
- Open a text editor in a separate window, so that you can answer questions as you work.
IF YOU ARE ALREADY FAMILIAR WITH SOME LINUX COMMANDS, FOR THE NEXT FEW MINUTES PRETEND THAT YOU ARE MEETING LINUX FOR THE FIRST TIME.
i.e. ACT AS A NAIVE FIRST TIME USER MIGHT.
- One natural thing we want to do is to change our password. Before reading ahead, make a few guesses at how to do this and try them. Describe briefly in your text file what you try and what happens.
- Unless you are already familiar with a Linux system, you may not yet found any of the comprehensive help files. Before reading ahead, make a few guesses at how to do this and try them. Describe briefly in your text file what you try and what happens.
- Okay, okay, I'll tell you one of the commands for help. It is man which stands for manual. Before reading ahead, try to use the manual to find help with changing your password. Make a few guesses at how to do this and try them. Describe briefly in your text file what you try and what happens.
- Unless you are already familiar with a Linux system, you have probably not yet found help on changing your password. Describe briefly in your text file what you think of the command line of the Linux user interface so far. Easy to use? Natural? Intuitive? Frustrating? Remember that the command line of the Linux interface is OLD. It was developed long before the graphical interface.
- The command for getting help with changing your password is man passwd. Try this command. Use the space key to page through the help. When you reach the end of the document, you will need to quit the mail daemon by typing q followed by return. (Hey, I don't make this stuff up - all the Unix-like man pages work this way!!) Describe in your text file what you learned from the manual is allowed for a password in terms of character length and types of characters. Be specific here. You may copy and paste if you like, but put it into your own words and do not put in extraneous information. If you need to execute any command (such as man passwd) again, you can use the up-arrow and down-arrows on your keyboard to scroll through the command history and to repeat a command (or to edit one.)
- Next try to list the files in your directory from the command line. Describe in your text file what you try.
- Okay, read man ls command to read about the command for listing the files in your home directory. To obtain more information about the files in your directory, read carefully about ls -l and ls -a. ls -l gives you the type of file, the permissions on the file, the number of hard links, the Owner, the Group, the size in bytes of the file, the date and time of last modification and the file name in that order. Try ls -a and explain what it does.
- When you typed ls -a, you will probably have seen some hidden files. Use cat filename to type the file contents of one of these files. Here cat stands for concatenate, so it is possible to list multiple files in this way. You are welcome to read man cat for more information.
- Next use the command pwd (which stands for print working directory) to find out what your current working directory is. Describe what you guess is the directory structure in Linux and explain where your working directory is in this structure.
- Try the command cd .. (including a space followed by the two periods). Try using ls -l and pwd. again. Explain in your text file the purpose of the cd command. (Feel free to use the man pages if you need to here.)
- Change back to your home directory.
- Use the command mkdir "directory name" to make a new directory there. Make a new directory named "homework" and then use ls -l again.
- Now use the command cd "directory name" to change your working directory to "homework". Use ls -l again. Describe briefly in your text file what you see.
- Staying in the homework directory, type ls -l so that you can see the longer version of your directory listing.
- Next we are going to explore an ancient version of the program vi and use it to create a small text file inside your "homework" directory. vi is an ancient line editor, and you may become quite frustrated while using it, but please try not to abuse your computer or any other students in the class!
Type vi username.txt where username is your own username. When the window comes up type i to get into insert mode, now you may type at least two lines of text and move around the window using the arrow keys. Type ESC to get out of insert mode and type :wq to write to the file and quit from vi. You could have just typed :w to write the file and then a i to continue editing. I recommend strongly that you learn how to use vi since it is one editor that EVERY Linux and Unix box have available, however, like
many things in UNIX-like environments, it is very powerful but not the most intuitive. In your text file, describe your initial reaction to vi. The vi editor is not the only editor available in UNIX-like environments. Most systems also have emacs and pico. Personally, I think that emacs is even less intuitive than vi-- (I know that seems impossible!) The pico editor is certainly easier to learn to use than vi, but it is not nearly as powerful and frankly people will make fun of you if you use it.
In fact, both vi and emacs have GUI versions with drop-down menus, but in some application environments, the command-line versions are better.
- Type ls -l so that you can see the longer version of your directory listing. Now that you have a file named username.txt in your homework directory, to see what is inside of it, type cat username.txt. You should see the contents of the file on your screen.
- Two preferable commands for looking inside of files are the more command and the less command. Read about both in the man pages and note the humor in the man page for less. If you have multiple screens of information in less, you can just hit the Space Bar to see one more screen of output or the Enter key to see the output one line at a time. You can also use the up and down arrow keys to more up and down in the file line by line.
- Next try the command who and explain what it does in your text file.
- Next try who > list.txt. The ">" character redirects the output. Try listing your files and see what has happened. Use less to see the contents of the new file.
- Next try the ps command. This command issues a report of all of the active processes. Try all of the following commands:
First, try ps, and then try ps -la. Finally, try ps -lA. Then use ps -lA | less in order that you can see the output in readable chunks. (Recall that we saw less above, but here we are using it in conjunction with another command!) The | character is called a "pipe", and you can use it to take the output of one command and feed it to the input of another.
Note that the root User ID or UID is always 0. In your Word file copy and paste the processes the root is currently running.
- Try the id command. Note that your User ID or UID is the same as was listed in the ps command. List your uid in your text file.
- Use the manual to learn more about the ps command. In your text file answer the following:
- What does it indicate ps does ?
- What does it indicate ps -la does? Hint: There are multiple options used here.
- What does it indicate that ps -lA does?
- Note that in the displayed ps table, S stands for Process Status or process State codes. List and explain all of the possible status codes listed in the manual.
- When you would like more information about processes, use the command top. Try it now and describe three differences between ps -la and top.
- The most interesting command that we will look at today is the screen command. Please read the man page on this command. Then use type screen at the command line to try each of the following:
| Key | Action | Notes |
| Ctrl+a c | new window | |
| Ctrl+a n | next window | |
| Ctrl+a p | previous window | |
| Ctrl+a S | split terminal horizontally into regions | Ctrl+a c to create new window there |
| Ctrl+a tab | Move to next region | |
| Ctrl+a X | remove region | Ctrl+a :remove is the same |
Try working with the above as well as with some of the commands that you learned earlier in order to get two working terminals in a multiplexing situation where the two windows show differing sets of commands.
Once you have played with this a bit, use ps in each window and explin what is going on with each of the PID's that are displayed. Are some the same? Are some different? Explain why in your text document.
- To logout of the Linux session you are in type exit. If you are unsing Topologilinux, you may also have to quit the coLinux terminal.
- Write a reflective paragraph in your text file on your first experience with Linux's command line. (If you were already familiar with Linux, then you can write about your actual first experience or about this pretend first experience.)
- Save your textfile as yourlastnameA2. This is due at the beginning of our next class.