A Few UNIX Concepts

Table of Contents

  • command shell
  • environment
  • file and directory names
  • file and directory permissions
  • redirection
  • pipes
  • processes
  • wildcard characters

  • command shell
    Briefly, the program which presents you with the UNIX prompt and interprets whatever commands you enter. The type of shell used at the CS Server is called bash, the Bourne Again SHell. Use man bash to learn more. You can modify it's behavior by editing the file called .bash_profile in your home directory using an editor such as vi or vim.
    environment
    Briefly, the environment is mainly values which are usually set during the login procedure which are retained in memory during the entire session and are used by various UNIX processes (programs) to know various important things. You can display the current environment with the set and env commands.
    file and directory names
    file and directory permissions
    With UNIX every file and directory in the filesystem can be set for who can read the file, who can write (or edit) the file and who can execute (or run) the file.

    This is signified by an r (for read), w (for write), and a x (for execute).

    You can see these permissions using the ls -al command.

    These permissions going from left to right...

    rwxrwxrwx
    ...are divided into three groups of rwx...

    rwxrwxrwx are the permissions granted for the owner or user,
    rwxrwxrwx are the permissions for the group (e.g. users),
    rwxrwxrwx are the permissions granted for the world (everyone else).

    To the left of the rwxrwxrwx are two names, like smith and then users.
    The first name is the owner of the file(s), and is the username of who owns the file. The second name is the group that the user belongs to. There is no listing for world since that is simply everyone else.

    You, the owner or user, have complete control over who can see your file(s), who can write to your file(s), and who can execute your file(s). The same is true of directories. This is very similar to the attrib command of MS-DOS, except that the only person who can modify these files is the owner.

    Of particular note is that all .html files must be readable by the world, the group and of course yourself, the owner. The command to effect that is chmod +r *.html.

    For more information see chmod or use the man command during a telnet session for a more through (and somewhat confusing) explanation.

    redirection
    Redirection can be used when the user wishes for the output of a command to go to a file rather than to the screen or the input to a command to come from a file rather than entered by the user at the keyboard. Redirection is achieved through the use of the < and > (and variations of these) characters.
    command > filename
    command >> filename
    The output from the UNIX command, command, is saved into the file, filename. Use > to create a new file and write the the output to it. If a file with the name filename already exists, a warning is displayed and the output is not saved (if the environment variable noclobber is not set, the old file will be overwritten by the new output without any warning). Use >> to append the output to an already-existing file.
    command < filename
    The UNIX command command will read its input from the contents of the file filename instead of reading user-entered lines from the keyboard.
    To send to output of a command to another command rather than to a file, see pipes.
    pipes
    The vertical bar, |, is the special pipe character which may be used to cause the output of one UNIX command to be the input to a second UNIX command. The | is typed in-between the two commands on one command line.

    | pipes stdout to the second command.
    |& pipes stdout and stderr to the second command.

    Examples:
    ls -a | wc -l
    ls creates a list of all the files in the current directory and sends this list into wc which displays the number of lines (i.e. filenames) in the list.
    To send the output of a command to a file rather than another command, see redirection.
    processes
    Briefly, every UNIX command (program) is actually runs on the machine as a process. Many commands create more than one process which run simultaneously. To display of listing of the processes currently running, use the ps command.
    wildcard characters
    The characters * and ? may be used in filenames when entering UNIX commands to avoid entering multiple filenames or long filenames. * matches zero or more occurrences of any character. ? matches exactly one occurrence of any character.
    For example,
    ls r*
    will display the names of all the files in the current directory with names beginning with r.
    mv ??? /tmp
    will move all the files with names exactly three characters long to the /tmp directory.
    cd /u/j/jt*/pub*/html*/
    will change directory to /u/j/jtpolk/public_html/htmlcorner
    grep include *.?
    will look for the word include in all files with names that end with a period followed by a single character (e.g. main.c, constants.h, report.1).
    The * and ? are actually a part of the regular expression syntax that can be used in filename reference.
    ^
    This symbol matches the start of a line in a file. e.g. grep ^smith file1 shows any lines which start with the letters 'smith' in file1.
    $
    This symbol matches the end of a line in a file. e.g. grep zzz$ * shows any lines which end with 'zzz' in all the files in your current directory.