Basic Unix

    For a more concise guide, check out Penn's Social Science Computing  UNIX HELP pages.




 The UNIX system is an operating system that allows several users to access one computer from several different terminals. The file system is hierarchied- its directories and files are distributed like the root/branch system of a tree. A directory can contain both directories and files, so  that once a directory has been created one can  create, open, save, or delete  files within it. Typically all files and directories within a unix system  are contained within one directory- the Root directory. A generic diagram  might look like this:
 

Root
|
Home Directory
|
              --------------------------------------
               |                          |               |                  |                               |                 |
       Directory       Directory     file      Directory(Meal)*      file     Directory
                |                        |                                   |                                                 |
                 --------          file          ---------------                  ---------
                     |                      |                          |                             |             |                  |                         |
                           file                  file              Directory(Fruit)*    file         file             file             Directory
                                                       |                                                                   |                                                                      --------                                                       file
|                      |
                                         file                file(Apple)*
 
*The parinthesis signify example names for the directory and the file.

 Directories and files can be referred to according to their relative position.  For example, the Fruit directory is in the Meal directory, which in turn is in the Home directory. One can also say that the Fruit directory is one down of the Meal directory or the Meal directory is one up of the Fruit. The "path" of a file is its position within the file system. To reach a file this path must be followed.  The first command that is needed is the present working directory command. This command lets the user know what the current directory is. To use this command type "pwd" and the current path is listed. For example, if one is in the Fruit directory and one types "pwd" one receives the message "% /meal/fruit".  The root directory is not specified since it is always assumed  to be in the path. The next command lets the user continue down the path.

 To access lower directories us the change directory command, "cd" followed by path name. It is important to note that every step down the tree is represented by the forward slash (/).  So for example, if one is in the Meal directory and wishes to access the Fruit, one would type "cd /Fruit" This would then place the user in the Fruit directory. One can move down more than than one directory at a time by simply adding to the path.  So if one were in the root directory and wished to access the Fruit one would type "cd /Meal/Fruit"

 Finally, to move up the tree one uses the "cd.." command.  This moves the user up one step on the tree.  So if one is in the Fruit directory and types "cd.." then the user is sent to the Meal directory.

This is an example of the prompt when one is trying to access a path to the fruit directory.

roman:jbrown 1  %  cd Meal/Fruit
    (a)                (b)               (c)      (d)        (e)               (f)
 
 

(a) the terminal "host" being used.
(b) the current operating directory. At the moment, it is the home
 directory, which is the log-in name of the user.
(c) number of commands that have been entered in this xterm session
(d) command prompt
(e)     command
(f)     path

*****
NOTE - In some cases, the setup may appear more like this

jbrown:roman:~>

user:terminal:directory>

this will not change any of the processes. (the tilda, (~),
refers to the home directory)
*****
 


Creating Directories and Files

Directories
  To create a directory, after prompt (%) or (>), mkdir (filename)

for example,
roman:jbrown 1 % mkdir Meal

this will create a directory called Meal
(note - UNIX is case-sensitive, so there is a difference between "meal" and "Meal" - the capitals create different files)

One can make sure that the file has been created using the list command  "ls", which lists all directories and files within the current directory.

roman:jbrown 2 % ls Meal 

To move to the directory Meal,
roman:jbrown 3 % cd Meal
roman:Meal 4 %

Now you are in the 'Meal' directory, where you can create more files and subsequent (sub)directories
 

Files

 At the prompt, type emacs (filename)

roman:Meal 4 % emacs light.supper

-this will open an emacs window buffer called "light.supper"  in which you can create and edit documents. During a session,
<cntrl-s> to save,
<cntrl-x> <cntrl-c> to save and exit.
[A save prompt should appear,  "y" and there may also be a prompt asking if a  "newline" should be added - again, "yes"]
 

(If a file name has more than one word, they should be linked together. For instance, with a period, "light.supper", or underscore, "light_supper".
If this is not done, and you try to create the file,
%emacs light supper
Two files, file "light" and file "supper" will be created.
Underscores and periods are fine, but generally avoid other symbols, (*, $, !, etc.)  since a particular symbol may be a unix command function and have a unexpected, probably inconvenient,  result.)

 
After exiting, return to prompt, and list (ls) -

roman:Meal 5 % ls  light.supper

Further directories and files can be created - in this scenario, in  the "Meal" directory. "breakfast" and "lunch".
 



Commands
 

( command prompt '%' or '>' )
 

% mkdir dirname
 -make directory- creates new directory called (directoryname)
 

% cd dirname
 -change current working directory

% cd..
 -go to upper-level (parent) directory

% cd
 -return to home directory

% ls
 -lists the files and directory contents

% ls -l
 -lists the files and directory contents, as well as their  condition

       eg.  drwxrwxr-x   2  jbrown     1512 Jan 29 14:44 Help
                               (a)                           (b)                           (c)           (d)                     (e)
 
- (a) permissions , (indicates if it is a directory or file,  who can read, run, and/or edit it,)
- (b) the owner of the file ,
- (c) the  size of the file in bytes ,
- (d) the last date and time it was worked  on,
- (e)  and the name of the file .

% more filename
 -display the contents of a file by screen without  opening an emacs session - read only, cannot edit
 

% (command) &
 the (&) returns a prompt while the command process run

 For instance,
% emacs whist &
- means open emacs editor buffer of file "whist" and provide another prompt , %.
 



Copying Files
 

% cp  afile newfile
 file called newfile created,  which is identical to afile - (note, if there is an  already existing file in the same directory with the "newfile"  name, it will be replaced )

% cp  afile   otherdir
 -a new copy named afile is created in the directory otherdir

% cp afile afile2    otherdir
        -a copy of afile and afile2 are made in otherdir

% cp -r adir newdir
 -a copy of the directory is placed in newdir. The -r flag  signifies that all files within adir are also copied.

% cp -r*  .     / newdir
 -copy all files in this directory and in it's subdirectories
 
 



Removing, Renaming, and Moving Files and Directories
 

% rmdir dirname
 -remove directory- will not do so if the directory is not empty, so the subdirectories must be specified

% rm filename
 -remove file

% mv oldname newname
 -renames file from oldname to newname

% mv oldfile dirname
 -move file to another directory.

% cat file1 file2 > newfile
 -combine two files, create file called newfile
 
 These are some of the most useful commands for creating and maneuvering directories and files in unix. 


Other Useful Commands

% lpr  filename
 -prints file

% head filename
 -shows the first few lines of file named

% tail filename
 -shows the last few lines of file named
 
grep
 -command used to search through files for a particular word or  wordstring in a specific file  or files-
 ie. searching for word "porch" in the file called "tomcat"

 % grep "porch" tomcat

   An old lady is rocking away the last of her days on her front porch,
          Just then the old woman's cat walks across the porch in
   front of them
 
 Two lines in the file are found which contain the seached-for word string in the file named tomcat.

 The grep command has several options, including
 % grep -n filename
  (Precede each line by its line number  in  the file (first line is 1).
 
 % grep -i
  (Ignore upper/lower  case  distinction  during comparisons.)

 % grep -h
 
  (Prevents the name of the file containing  the matching  line  from  being  appended to that line.  Used when searching multiple files.)


Reference

 For further, more detailed descriptions of commands, one can query the "manual page", a document containing in-depth, somewhat cryptic explanations of all the unix commands. there is a manpage book icon on your screen, however to access from an xterm, enter

% man (command)
 
eg
roman:jbrown 1 % man cd

 The manpage delivers detail explanations of the commands asked about, and it may help clarify and further any questions and further applications and arrangements of specific commands. If the specific command cannot be remembered, use the command "apropos "

roman:jbrown 1 % apropos cd

This will return a list of all commands in the manpage that contain "cd" in the one line command explanation.



*******
Misc.
*******

Passwords

 to change your password, type

 %passwd

 you will be prompted for the old password, then for the new password twice.
 i) at least six characters
 ii) contain at least one numeric or special character
 ii) must be different from login name
 iv) new passwords must differ from the old by at least three
     characters
 

Changing Colors 

 To change the background and border colors of the icons and windows

Border color

If you want to change the color of your borders, look in your .twmrc file in your home directory

  % emacs .twmrc

In the section  beneath the line
# Color settings,
one can chage the color in quotes to one reflecting a more personal color preference.
After the color has been changed in the file, save the changes, then on the greybackground of your screen,  middle mouse key to get the "Window Ops" menu. Drag down to highlight "source .twmrc" - the changes you made will now be evident.
 

Change the background color of your clock...

  % emacs .xsession
 

xclock -update 1 -padding 1 -geometry 60x60+68+0 -bg "blue" &

for no colors at all, (ie white screen), delete the current color entry

xclock -update 1 -padding 1 -geometry 60x60+68+0 &
xterm -C -title "Console" -n "console" -geometry 85x30+0-0 &
 

Just for fun -
at the prompt, type

% xeyes