and viewing file contents with cat"> and viewing file contents with cat">
Terminal: The Basics: General Information
Terminal: The Basics: General Information
Terminal: The Basics: General Information
The current page could have changed in the meantime. Learn more Tip: To quickly find your search term on this page, press Ctrl+F or -F (Mac) and use the find bar. Text-only version
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. :-)
Contents
Basic operations on directories Basic operations on files Documentation A few more basic commands [Top] [Terminal HOW-TO]
2 1 1 1 2
25 17 17 17 24
1 of 7
http://webcache.googleusercontent.com/search?q=cache:AldiaQw711wJ...
drwxr-xr-x $
2 user
student
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. How to force the output on a page-by-page (line-by-line) basis? 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]
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 $
Create a directory
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
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]
Rename a directory
2 of 7 http://webcache.googleusercontent.com/search?q=cache:AldiaQw711wJ...
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 $
Delete a directory
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 drwxr-xr-x 2 user student drwxr-xr-x 2 user student drwxr-xr-x 2 user student $ rmdir 02 $ ls -l total 0 drwxr-xr-x 2 user student drwxr-xr-x 2 user student drwxr-xr-x 2 user student $ cd .. $ ls labs $ rmdir labs rmdir: directory "labs": Directory $ rm -r labs $ ls -l total 0 $
96 96 96 96
26 26 26 26
not empty
3 of 7
http://webcache.googleusercontent.com/search?q=cache:AldiaQw711wJ...
25 17 17 17 24 26
25 17 17 17 26 24 26
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]
Copy a file
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]
Delete a file
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 $ rm empty2.txt $ ls empty.txt tmp $
tmp
Rename a file
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
4 of 7
http://webcache.googleusercontent.com/search?q=cache:AldiaQw711wJ...
$ ls am_i_empty.txt $
tmp
Move a file
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 $
2 1 1 1 1 2 3
25 17 17 17 26 24 26
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
Edit a file
You can use pico. The most important shortcuts that you have to remember for pico are:
Ctrl+O: save Ctrl+X: exit
a file
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]
Documentation
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
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
5 of 7
http://webcache.googleusercontent.com/search?q=cache:AldiaQw711wJ...
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]
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
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. $
6 of 7
http://webcache.googleusercontent.com/search?q=cache:AldiaQw711wJ...
7 of 7
http://webcache.googleusercontent.com/search?q=cache:AldiaQw711wJ...