Homework: Get Acquained With Unix
Before doing the lab exercises on the fourth day of class, you should be prepared to be able to login to one of the systems and be familiar with some basics. You can do these exercises in your spare time from your office or home, so that you can easily start the lab exercises and focus on learning Perl.
- If you do not have an account on eos, visit the Howto Guide for instructions.
- Login to eos. (For additional details
check here.) So, for example, if you are using ssh
and your login name is mylogin, you would type:
Once you've entered your password, you will be logged into eos.
- Print your working directory:
which should output your home directory. On eos, that would be /g/home/mylogin.
- List the contents of your home directory:
which should output a list of files, such as README.
- Get a detailed listing:
Now, you'll see detailed information on each file, including permissions, ownership, file size, and modification date.
- List "hidden" files:
The list includes the "hidden" files, which are just the files which start with a period (dot files). These are usually the startup files, like .bashrc or .profile.
- View the README file:
The less program shows you the contents of a file, page by page. Each time you hit the spacebar, it will scroll down one page. You can also use the arrow keys, the Page Up and Page Down keys, etc.. To quit, just hit the "q" key. For help on other key commands, hit "h".
- Change your working directory:
This will change to your scratch directory. Confirm this by using the pwd command. You can list the files there as well. There should be a directory called tmp there, along with any other files you created.
- Create a new directory:
List the contents again with ls -l to see this new subdirectory.
- Change your working directory again:
This will change to the directory you just created. Notice that without any slashes ("/") to start the name of the directory xyz123, the cd command starts looking in the current working directory. This is called a relative path. So, from your scratch directory, "xyz123" is the same as "/scratch/mylogin/xyz123". The first form is a relative path and the second is an absolute path (sometimes referred to as a full path).
- Now that you're in the xyz123 subdirectory,
create a file called simple.txt. First, pick
which editor you will use. (For details on text editor, see
check here.) Assuming you are on eos
and you want to use nano, you would
Your terminal screen will now be cleared and the top line will indicate "File: simple.txt". At the bottom of the window, it will have a list of the key commands you can use. For example: "^X Exit" means that by holding the "Control" key and hitting "x", you will exit the editor.
- Type a few sentences and then save the file using the "^O" key command (write out). Then, use the "^X" key command (exit) to go back to your normal terminal prompt.
- List the directory:
You should see a line for the new file, simple.txt, which shows who owns it (you), the group owner (users), the number of bytes in the file, the the date it was last changed.
- View your file:
Since it's a short file, there are not multiple pages to go through, just the one. To quit, just hit the spacebar or "q" key.
- View your file with cat:
This simply outputs the file without pausing. If you use cat on a large file, like README, the hundreds of lines will scroll past very quickly.
- Rename your file from simple.txt to
mv simple.txt other.txt
List your directory to see that the name has changed. If you try to use less or cat on simple.txt, you'll get an error.
- Make a copy of other.txt, called
cp other.txt something.txt
List your directory to see that you now have two files.
- Edit something.txt:
Add a few new lines to it. Save and quit. List the files again to verify that the size has changed.
- View both files:
less other.txt something.txt
Hit the spacebar to go from one file to the next, or use the "q" key to quit.
- Remove other.txt:
rm -i other.txt
The -i option is for "interactive", which means you will be asked to confirm the deletion. It is good practice to use this option to avoid accidentally deleting files. List your directory again to see there is only one file remaining.
- Remove something.txt:
rm -i something.txt
Now your subdirectory xyz123 should be empty.
- Change back to the directory above:
Confirm that you are in /scratch/mylogin with the pwd command.
- Remove the xyz123 directory:
If you have any files or subdirectories in xyz123, you can't remove it. In this case, you should have no problems.
- Logout of eos:
You can also use "^D" (control-d).
These simple exercises should be enough for you to be able to do the laboratory exercises. To learn more about basic Unix commands, go to the New User Information page, and look under the Getting Started section for links to additional information. Read the Introduction to Unix and Basic Unix Commands pages. Experiment with the commands while you are logged into the system.