General Information
The following examples are based on the default login account for students at icarus.uic.edu. I also assume that the username
for the user is user.
Remember: Do NOT use the mouse
to view previous commands, or output. :-)
[Top]
[Terminal HOW-TO]
The most fundamental operations that you need in order to do something with the directories are the following:
[Contents]
This is done with the command pwd (which comes from the words print
working directory) and the absolute path of the directory is printed on screen.
$ pwd
/homes/home12/user
$
[Basic operations on directories] [Contents]
This is done with the command ls (which comes from the word list).
Simply type ls and press the return (Enter) key and you 'll see the contents of
the directory where you are at the moment in your terminal.
If you want to have a more thorough view on those files you can try ls -l
(read: ls minus L not ls minus ONE).
Note that some of the entries listed are directories while others are files. When using the ls -l
version, you can say which entries are directories, since at the beginning of the respective lines you can
read a d instead of a - (dash) which is used for files.
$ ls -l
total 8
drwx--x--x 2 user student 96 Jan 25 01:11 bin
-rw-r--r-- 1 user student 124 Jan 17 18:19 local.cshrc
-rw-r--r-- 1 user student 607 Jan 17 18:19 local.login
-rw-r--r-- 1 user student 582 Jan 17 18:19 local.profile
drwx------ 2 user student 1024 Jan 24 23:52 mail
drwxr-xr-x 2 user student 96 Jan 26 09:50 mcs260
$
Moreover, note that some files (or directories) are hidden and therefore are not shown by default.
By convention, the names of the hidden files start with a . (dot). If you want to list those
files as well, give the command ls -a. Note that this version of the command, is just like simple
ls but this time files and directories that start with a dot are presented as well.
In addition to that, you can combine parameters and give the command ls -la which combines
the detailed output of ls -l with the extended version of ls provided by
ls -a. The order in which you type the arguments of ls is not important.
Hence, ls -la will give you identical output as ls -al on the same directory.
A common problem that arises in practice, especially with the use of ls -la is that one can't view
the entire contents of a directory in a single page in the terminal. The way that you can bypass this hurdle is
with pipelining and the command more. Basically, with pipelining one can lead the output of
one command as input for another command. This is done with the vertical bar |.
Hence, ls -la | more presents the contents of ls -la but waits until you are ready for
more information. If you press the spacebar you will see one more page, while if you press the
return (Enter) key, you will see one more line. If at any point you don't need further output, you
can terminate the process by pressing the key q (from the word quit).
[Basic operations on directories] [Contents]
This is done with the command cd (change directory).
Hence, if you want to change your working directory to one named mcs260 you can do so
with the command cd mcs260 (relative path).
$ pwd
/homes/home12/user
$ cd mcs260
$ pwd
/homes/home12/user/mcs260
$
Of course, you can change your working directory by also
giving the absolute path of the directory; i.e. if your home directory is
/homes/home12/user and mcs260 is a subdirectory of your home directory you
can give cd /homes/home12/user/mcs260.
Shorthands
A useful way of giving absolute paths under your
home directory is the use of ~ (tilde) which indicates your home directory. Hence, you
could achieve the same thing with cd ~/mcs260 since ~ is a shorthand for
/homes/home12/user.
There are two special names for directories: . (dot) and .. (dot-dot).
The former is a shorthand for your current working directory, while the latter is a shorthand for the
parent directory of the one you are working now.
Finally, by simply giving the command cd you move to your home directory.
$ pwd
/homes/home12/user/mcs260
$ cd ../..
$ pwd
/homes/home12
$ cd
$ pwd
/homes/home12/user
$
[Basic operations on directories] [Contents]
This is accomplished with the command mkdir (make directory).
Hence, if you want to create a directory named labs you can do so by giving the command
mkdir lab. Note that this directory will be created under your current working
directory.
$ cd ~/mcs260
$ mkdir lab
$ ls -l
total 0
drwxr-xr-x 2 user student 96 Jan 26 12:25 lab
$
Note: You can create several directories in a single line by separating their names with a
space. Refer to the example below on deleting a directory.
[Basic operations on directories] [Contents]
This can be done with the command mv (move). Hence, if you want to rename
the directory lab to labs you can do so with the command mv lab
labs.
$ mv lab labs
$
[Basic operations on directories] [Contents]
This can be achieved with the command rmdir (remove directory).
Therefore, rmdir labs deletes the directory labs assuming that it is empty.
Note:
If the directory labs is not empty, and you are sure that you want to delete the
directory with all its subdirectories and files that it may contain, you can do so with the command
rm -r labs. Of course you have to be very careful with the use of this
command so that you don't erase by mistake important things. rm is described later on
operations on files.
$ pwd
/homes/home12/user/mcs260/labs
$ mkdir 01
$ mkdir 02 03 "This has space"
$ ls -l
total 0
drwxr-xr-x 2 user student 96 Jan 26 12:33 01
drwxr-xr-x 2 user student 96 Jan 26 12:33 02
drwxr-xr-x 2 user student 96 Jan 26 12:33 03
drwxr-xr-x 2 user student 96 Jan 26 12:33 This has space
$ rmdir 02
$ ls -l
total 0
drwxr-xr-x 2 user student 96 Jan 26 12:33 01
drwxr-xr-x 2 user student 96 Jan 26 12:33 03
drwxr-xr-x 2 user student 96 Jan 26 12:33 This has space
$ cd ..
$ ls
labs
$ rmdir labs
rmdir: directory "labs": Directory not empty
$ rm -r labs
$ ls -l
total 0
$
[Basic operations on directories] [Contents]
Some things are really important in everyday work and more or less are trivial when using a windowed environment.
The most important operations that I can think of are:
[Contents]
For this purpose you can use the touch command.
$ pwd
/homes/home12/user/mcs260
$ ls
$ touch empty.txt
$ ls
empty.txt
$
[Basic operations on files] [Contents]
In some cases we want to store the output of some commands or programs in a file.
A simple way of doing so, is by redirecting the output of the commands or programs into a
file. This is achieved with the greater sign >. Here is an example:
$ cd
$ ls -l
total 8
drwx--x--x 2 user student 96 Jan 25 01:11 bin
-rw-r--r-- 1 user student 124 Jan 17 18:19 local.cshrc
-rw-r--r-- 1 user student 607 Jan 17 18:19 local.login
-rw-r--r-- 1 user student 582 Jan 17 18:19 local.profile
drwx------ 2 user student 1024 Jan 24 23:52 mail
drwxr-xr-x 3 user student 96 Jan 26 14:06 mcs260
$ ls -l > ls.out
$ ls -l
total 10
drwx--x--x 2 user student 96 Jan 25 01:11 bin
-rw-r--r-- 1 user student 124 Jan 17 18:19 local.cshrc
-rw-r--r-- 1 user student 607 Jan 17 18:19 local.login
-rw-r--r-- 1 user student 582 Jan 17 18:19 local.profile
-rw-r--r-- 1 user student 447 Jan 26 14:19 ls.out
drwx------ 2 user student 1024 Jan 24 23:52 mail
drwxr-xr-x 3 user student 96 Jan 26 14:06 mcs260
$
With the last ls -l command you can see that a file name ls.out of size
447 bytes was created. That file contains the output of the first ls -l. If you want to
display the contents of the file ls.out, you have to use the command cat.
[Basic operations on files] [Contents]
You can copy a file with the cp (copy) command.
The following are examples on the usage of the cp command.
$ cd ~/mcs260
$ cp empty.txt empty2.txt
$ mkdir tmp
$ cp empty.txt tmp/
$ ls -R
.:
empty.txt empty2.txt tmp
./tmp:
empty.txt
$
With the first command we create a duplicate of the file empty.txt in the same
directory, while with the latter we create a copy of the file under the directory tmp.
Note: ls -R recursively lists the contents of the current directory and all its
subdirectories.
[Basic operations on files] [Contents]
This can be done with the command rm (remove). Hence, if you want to
delete the duplicate empty2.txt that we created above, you can do so with the command
rm empty2.txt.
$ ls
empty.txt empty2.txt tmp
$ rm empty2.txt
$ ls
empty.txt tmp
$
[Basic operations on files] [Contents]
This is done with the command mv. In the following example empty.txt file
gets the name am_i_empty.txt.
$ ls
empty.txt tmp
$ mv empty.txt am_i_empty.txt
$ ls
am_i_empty.txt tmp
$
[Basic operations on files] [Contents]
This is done again with mv (move). The case above was just a special case
on the use of mv. In reality you move a file from one place to somewhere else and you
are also allowed to change the name of the file.
$ mv am_i_empty.txt tmp/who_knows_if_i_am_empty.txt
$ ls
tmp
$ ls tmp
empty.txt who_knows_if_i_am_empty.txt
$
[Basic operations on files] [Contents]
This can be done with the command cat (catenate). Let's try to print the
contents of the file ls.out that we created earlier with redirection.
$ cd
$ cat ls.out
total 8
drwx--x--x 2 user student 96 Jan 25 01:11 bin
-rw-r--r-- 1 user student 124 Jan 17 18:19 local.cshrc
-rw-r--r-- 1 user student 607 Jan 17 18:19 local.login
-rw-r--r-- 1 user student 582 Jan 17 18:19 local.profile
-rw-r--r-- 1 user student 0 Jan 26 14:27 ls.out
drwx------ 2 user student 1024 Jan 24 23:52 mail
drwxr-xr-x 3 user student 96 Jan 26 14:06 mcs260
$
Reminder: If the file is too big, obviously you can not view its contents in a single page on
the terminal. For this reason you can use pipelining with more just as it was
suggested earlier:
$ cat file_with_many_lines | more
[Basic operations on files] [Contents]
You can use pico. The most important shortcuts that you have to remember for pico are:
- Ctrl+O: save a file
- Ctrl+X: exit
You can find more information in the manual :-) or look up online for a
brief tutorial.
A simple search by google returned this page.
Note, that the tutorial found there is also available in pdf format.
A direct link for the 2-page pdf document is here.
[Basic operations on files] [Contents]
One very good thing with Unix/Linux is that it is very well documented. The commands that are
built-in into the terminal are documented in the manual.
The manual of a specific built-in command can be accessed with the use of the man
command. For example, you can access the manual for the pwd command as follows:
$ man pwd
Similarly with more you can use spacebar to
procceed to the next page,
return (Enter) to procceed on a line-by-line basis, and
q to quit.
Note: man is a built-in command! Therefore, it has its own manual page. You can
access it with the cumbersome (but logical) syntax:
$ man man
Creating a document for future reference
Sometimes you might want to create a file with the documentation on the manual so that you can print
it and have the manual available offline. As you already know, you can redirect the output and
create a file. Hence, the following command is a good guess towards this direction:
$ man pwd > pwd_man.txt
$
However, on some terminals, the use of man command indicates that some words should be
written in bold, or others in italics, or even with colors.
Unfortunately though, in a text
file that you create with redirection you can not write down something in italics, or
bold. Hence, you have to invoke another command before you redirect the output. Namely, you
have to use the ul command, which will remove all highlighting as follows:
$ man pwd | ul -t dumb > pwd_man.txt
$
Then, at icarus you will create this file.
SEE ALSO ...
Near the end of the manual for each built-in command there is a paragraph named SEE
ALSO .... Under this paragraph, you can find other commands that are suggested for reading
and are closely related to the command that you are reading at the moment. :)
For example, the man page of the pwd command at
icarus suggests among other things the
command cd, because obviously these two commands are closely related.
[Documentation] [Contents]
This first approach to the terminal ends with three basic commands for the various sessions.
Clear Screen
At some point while you work you might feel the need to clear the contents of the screen in front of you.
This can be accomplished with the command clear.
$ clear
Display current date and time
Working in front of a computer is usually time-consuming apart from fun. At any given time you can ask about the
current date and time with the command date.
$ date
Sun Jan 27 02:09:40 CST 2008
$
Terminate session
You can terminate your session at any given time with the command exit or the universal Unix
shortcut Ctrl+D (^D).
$ ^D
Connection to icarus.uic.edu closed.
$
[A few more basic commands] [Contents]
Back to Terminal's homepage
Back to Dimitri's homepage
Last Update: Sunday, January 27, 2008.