Lab 1: Basics of Unix1

advertisement
ESCI 7205
Laboratory 1: Basic Unix 1
1. Log In
Trying logging in using Common Desktop Environment and Java Desktop options.
2. Open a terminal window
Practice resizing, minimizing and moving windows.
3. Practice with wild cards and navigation
From a terminal window, determine your "working directory" (think of this as your location in
the Unix file structure) by typing pwd (print working directory) at the prompt. If you have just
logged on to your machine or have just opened a terminal application, this directory is your
"home directory". (Here it is assumed that your working directory is set to your home directory.)
The result of pwd may be a little long, but after the last slash character /, you should see your
username.
You will be doing quite a few exercises in this class, so it is useful to set up directories for
organizing them. Let's do this by creating a parent directory called "ESCI7205” and a
subdirectory called “lab01”. Eventually we will make one for each lab exercise.
Check that this was successful by typing ls (the list command). Try some of the variants of the ls
command:
ls * ; ls -l ; ls -la ; ls 7205 ; ls ESCI*/???1 ; ls ESCI????
Move to directory ESCI7205/lab1
Type ls. The directory should have no files in it, as this command will indicate.
Try moving back to directory ESCI7205 using
cd ESCI7205
Why does this fail?
Return to your home directory using cd and the "full path name". What other cd commands
could you have used?
Note that other users' home directories can be accessed with the ~ symbol. For example, the
instructor's account, called hdeshon, has a home directory of ~hdeshon, so try
cd ~hdeshon ; ls
Note that the tilde is an abbreviation for the full path to the home directory, so any path beginning
with tilde is actually an absolute path.
Finally, you should acquaint yourself with ways to move up the file hierarchy. Two periods, ..,
will move you up one level. Experiment with this; also try
cd ../.. ; cd ../../..
Run the following commands to create a file called howmuch.txt
cd ~/ESCI7205; du -k . > lab01/howmuch.txt
Spaces are important in Unix, so pay careful attention to the spaces and the dot here. If you make
a mistake, delete the file with the command rm lab01/howmuch.txt and try again.
What did the above command do?
There are several things to notice. First the command du with a flag -k is a Unix "disk usage"
utility that tells you what directories and subdirectories you have and what their sizes are in
kilobytes. We won't be using it very often in this course. The dot . for "current directory" tells the
du command to examine the directory tree descending from the current directory, which should
be your directory exercises. Try running just this first part of the command
du -k .
This time the command output is sent to the terminal window. Examine the contents of your
howmuch.txt file by running the commands
cd lab01 ; cat howmuch.txt
Can you see that the > ex01/lab01 took what would have gone to the screen and put it in the file
lab01 in the subdirectory ex01 instead? That is called output redirection.
4. Unix practice: cp, man, mv, grep
This exercise has to do with file manipulation. Use the cp command to copy the file file1 from
the ~hdeshon/ESCI7205/lab01 directory to the directory lab01 that you created above.
For more details on how to use the cp command (or other shell commands), type
man cp
Push the space-bar to scroll down the "man page". When you are done with man hit q to return to
your shell.
Do an ls to make sure the copy worked. Look at the file with the more, less, head, and tail
commands. (When done, typing q gets you back to your shell.) Also, look at it with the cat
command. What is in this file?
Move (mv) (i.e. rename) file1 to a more descriptive filename
Try out the grep command:
grep New Madrid file1
Did this work as expected? How could you fix it?
5. Practicing with pipes
Using pipes | send the ‘DESCRIPTION’ portion cp manual page to a new file called
lab01/CPdesciption.txt using a single command line.
6. Modifying your .cshrc file
I will show a demonstration in class on this part.
Download