In this lab, you will learn how to use UNIX commands to navigate through the file system of a remote Unix computer and create files there.
dante
pico
editorYou will be using the web to publish parts of your completed assignments (homeworks,
labs, and projects) throughout the quarter. Therefore, you
must know how to upload files to your web directory on dante
.
This will be a useful skill throughout your college career here, so
take the time to learn how to do it now.
UNIX is an operating system like Microsoft Windows, Mac OSX and Linux.
An operating system allows you to run programs on a computer. Unix is often
used for server systems like dante
, and so it is useful to have some
knowledge about how to navigate through the file system and create simple
text files.
UNIX, operating system, remote login,
SSH, shell, bash
, pwd
, ls
,
cd
, home directory, /
,
.
, ..
, parent directory,
mkdir
, pico
,
more
, cp
, mv
,
rm
, rmdir
,
chmod
, exit
.
You should have completed the objectives in the previous labs before
doing this lab. If you have trouble with logging on to the remote system
dante
, go back and review the previous labs
(Lab 01 and
Lab 02).
To upload and download your files to/from a remote computer,
you must log in to the remote computer. For this lab, you will use a program
named SSH Secure Shell to login to dante
.
SSH stands for Secure SHell and is both a program and a standardized method (protocol) for communicating between computers in a secure/encrypted manner. The SSH client (the application that runs on your desktop machine) is installed in the UW labs. It is also available for installation on your own machine as part of the UWICK kit available from the UW (on CD at the bookstore or online).
dante.u.washington.edu
and for the user name, enter
your UW NetID. If your UW NetID was smith
, you would enter the
following:
Enter your password in the next pop-up window to finish connecting to
dante
.
dante
.
S
to start a shell in which you can use UNIX
commands.A shell is a program in which you type commands to tell a computer
what to do. In Windows, the MS-DOS or Command Prompt is Microsoft's version of a
shell. In Mac OSX, the Terminal provides the shell (which is in fact a Unix shell
similar to the one on dante
).
To do anything in a shell, you must use commands. This section explains how to use UNIX commands in a UNIX shell to make a computer do things for you.
There are several different shells that can be used in UNIX. When you first
logged in to dante
, a shell named psh
(pronounced:
p-shell) displayed the welcome menu. When you pressed on S
, you
started a shell named csh
(pronounced: c-shell).
bash
(pronounced:
bash), since bash
has certain default features that make it
easier for you to navigate through directories. Type the command bash
and press the enter key. The prompt will now change
from dantexx%
to bash-2.01$
. See the example below.
(Bold text indicates what you type, followed by the enter key.) dante04% bash bash-2.01$
A prompt, or command prompt, is a short line of text that a shell displays
when it is ready for you to enter a command. Some example prompts are
dante04%
, bash-2.01$
, and
C:\WINDOWS>
.
bash
will complain
with command not found
and give you the prompt again so that you
can type another command. Try the following:
bash-2.01$ BASH bash: BASH: command not found bash-2.01$
All UNIX commands are case sensitive. This means that typing
bash
is not the same as typing Bash
,
BASH
, or baSH
.
pwd
shows you your present work
directory, that is, the directory you are currently located in. The
command ls
will list the contents of your
present work directory (or other directories that are specified after
ls
). The command cd
(change
directory) will change the present work directory to the one you
specifiy. Typing cd
by itself will change you back to your
home directory. Try using the same commands as the user
smith
(you will see your UW NetID instead of smith
and the actual contents of your files and directories may differ): bash-2.01$ pwd /···/smith bash-2.01$ ls public_html bash-2.01$ cd public_html bash-2.01$ pwd /···/smith/public_html bash-2.01$ ls fit100 index.html bash-2.01$ cd fit100 bash-2.01$ pwd /···/smith/public_html/fit100 bash-2.01$ ls lab1 bash-2.01$
Note that Unix uses /
(forward slash)
to separate the directories in a pathname. Windows uses the
\
(back slash) instead , e.g., C:\WINNT\Temp
.
You must use a /
(with no spaces before or after the
slash) to separate the name of a directory from its subdirectory (and
subsubdirectory, etc).
bash-2.01$ cd public_html/fit100 bash-2.01$ pwd /···/smith/public_html/fit100 bash-2.01$ ls lab1 bash-2.01$
The command cd public_html/fit100
means to change
the present work directory to fit100
, which is a subdirectory of
public_html
(fit100
is located in/under
public_html
).
.
(dot) and ..
(dot dot). However, all
file names and directory names beginning with a dot are hidden. You can see
hidden files and directories by adding the flag -a
(for
"all") to the ls
command. To see more information
about each file and directory, you can use the -l
flag (lowercase L for "long") with
ls
. You can specify the switches separately or one right after the other.
Try the following:
bash-2.01$ ls -a . .. lab1 bash-2.01$ ls -l total 8 drwxr-sr-x 2 smith www 512 Oct 5 11:44 lab1 bash-2.01$ ls -a -l total 24 drwxr-sr-x 3 smith www 512 Oct 5 11:44 . drwxr-s--- 6 smith www 512 Oct 5 11:44 .. drwxr-sr-x 2 smith www 512 Oct 5 11:44 lab1 bash-2.01$ ls -al total 24 drwxr-sr-x 3 smith www 512 Oct 5 11:44 . drwxr-s--- 6 smith www 512 Oct 5 11:44 .. drwxr-sr-x 2 smith www 512 Oct 5 11:44 lab1 bash-2.01$
The directory names .
(dot)
..
(dot dot) always exist in a directory. The
.
refers to the directory itself and
..
to its parent directory.
mkdir
(make directory). Make a
directory named lab3
in your fit100
directory
and then change/go to the tmp
directory. An example follows:
bash-2.01$ mkdir lab3 bash-2.01$ mkdir tmp bash-2.01$ ls lab1 lab2 lab3 tmp bash-2.01$ cd lab3 bash-2.01$ pwd /···/smith/public_html/fit100/lab3 bash-2.01$ ls bash-2.01$ ls -al total 16 drwxr-sr-x 2 smith www 512 Oct 5 11:48 . drwxr-sr-x 4 smith www 512 Oct 5 11:48 .. bash-2.01$
cd
and the ..
directory name: bash-2.01$ pwd /···/smith/public_html/fit100/lab2 bash-2.01$ cd .. bash-2.01$ pwd /···/smith/public_html/fit100 bash-2.01$
cd
by
itself.bash-2.01$ cd bash-2.01$ pwd /···/smith bash-2.01$
pico
To create and edit text files on a UNIX computer, you can use the
text editing program named pico
. Examples of other text
editing programs for UNIX computers are emacs
and vi
.
Examples of text editing programs for Windows are Notepad
jEdit and Emacs.
pico
functions sort of like the compose window in Pine. (Pine was
covered in Lab 01.) Unfortunately, the commands
are not exactly the same, so you have to pay careful attention to the list
at the bottom of the screen.
pico
by typing its name. If you include another
word after its name (e.g., notes.txt
), pico
will try
to open a file with that name. If the file does not exist, an empty file will
be opened with the words New file
at the bottom of the
pico
window.
bash-2.01$ pwd /···/smith/ bash-2.01$ cd public_html/fit100/lab3 /···/smith/ bash-2.01$ pwd /···/smith/public_html/fit100/lab3 bash-2.01$ pico notes.txt
If your SSH window is narrower than 78 columns wide,
pico
may not display properly. Increase the window width to at
least 78 or 80 columns by dragging on the lower right corner of the window. A
typical normal window size is 80x25.
pico
window.pico
. You activate a command by pressing its shortcut, which is
the Ctrl
key followed by a single letter. For example,
^O
means to press Ctrl
and the letter O
to WriteOut (aka: save to a file).
Save what you just wrote in a file named notes.txt
.
Enter the file name, if it is not already shown, and press the
Enter
key. pico
responds by telling you the number
of rows you saved to the file, e.g., Wrote 6 lines
(the sixth
line in the example is an empty line at the end of the file, that the cursor
is located on).
pico
and check to see if your newly created file exists.
You can see the contents of a file by using the more
command followed by the name of the file you would like to view. bash-2.01$ ls notes.txt bash-2.01$ more notes.txt Mary had a little lamb, little lamb, little lamb. Mary had a little lamb. Its fleece was white as snow. bash-2.01$
cp
(copy)
command. To use this command, you write cp
followed by the name
of what you would like to copy (the source) followed by a new name (the
destination), i.e., cp source destination
.
bash-2.01$ ls notes.txt bash-2.01$ cp notes.txt notes2.txt bash-2.01$ ls notes.txt notes2.txt
mv
(move) command.
To use this command, you write mv
followed by the name
of the existing file (the source) followed by the new name (the
destination), i.e., mv source destination
.
bash-2.01$ ls notes.txt notes2.txt bash-2.01$ mv notes2.txt sample.txt bash-2.01$ ls notes.txt sample.txt
mv
(move) command.
To do this, you write mv
followed by the name
of the existing file (the source) followed by the name of
the directory to move it to (the
destination), i.e., mv source destination
.
bash-2.01$ ls notes.txt sample.txt bash-2.01$ mv sample.txt ../tmp bash-2.01$ ls notes.txt bash-2.01$ ls ../tmp sample.txt
rm
(remove) command.
Note that you can not remove the two special dot directories: .
and ..
.
rm
is
permanently removed and can not be recovered!
rmdir
(remove directory) command. You can only remove empty
directories, that is, directories that contain no files or subdirectories
(except for the two special dot directories: .
and
..
). Note that you can not remove a directory that is
your present work directory.
rmdir
is
permanently removed and can not be recovered!
fit100
directory, e.g.,
http://students.washington.edu/smith/fit100/
. You should see your
lab2
directory. Select it. Now you should be able to see all of
your files.
If you are unable to see any files/directories in your fit100
directory or it it says Forbidden, then you need to change your access
permissions. Use the shell to go to your fit100
directory and run
the chmod
(change mode) command. Note that the
chmod
command below uses a capital R in the flag and a capital X
followed by a single dot.
bash-2.01$ cd bash-2.01$ cd public_html/fit100/ bash-2.01$ chmod -R a+rx . bash-2.01$
If you are interested in knowing how chmod
works, read its
manual by running man chmod
. This command will be discussed in
more detail later.
exit
. bash-2.01$ exit exit dante04% exit (select 'L' from the menu to logout of your remote login shell)
The first exit
is for exiting bash
. The next
exit
is for exiting csh
. The last L
is
for exiting psh
.
______ | I understand the keywords for this lab and can give examples of what they mean. |
______ | I can remotely login to and use a UNIX shell on
dante . |
______ | I know how to use the UNIX commands bash ,
pwd , ls , cd , mkdir ,
pico , more , cp ,
mv , chmod , and exit . |
______ | I know what the . and ..
directories are. |
______ | I can create and edit files with pico . |
Write a couple paragraphs about your experiences during this lab. What did you find hard? What was easy? What surprised you? At the top of this document, be sure to add your name, student number, lab section, and date, so you will get credit! This document can be either a Word document or a .txt document.
Upload your reflection paper to the Catalyst Collect-It Turn-in Area on the Course Calendar and select this lab number.