Back to CFM home             Brown University

Introduction to Unix

After reading this introduction, please go on to Unixhelp for a more comprehensive Unix lesson.

  1. Logging on
  2. To log on, type your computer account name at the "login:" prompt, then hit return. Then type you password at the "password:" prompt, and hit return again:
    	login: myname
    	password:(not echoed)
    In Unix, once you have logged on you will be running a program called a "shell". The shell is your interface to the operating system. A shell prints a prompt (below, the prompt is "%") when it is ready for a command. All commands are terminated by a carriage return. More about the shell later.

    Changing your password: yppasswd

    After you log on to your Unix account for the first time, you will probably want to change your login password to something you can remember. Do this by typing the following at the prompt:
         % yppasswd
    yppasswd will prompt you for your old password, and then ask you to enter your new one twice (to forestall mistakes). For your own security, you should try and choose a password that is not easily guessable. Here's some helpful guidelines:

    Here's some additional things that you should not do with your password:

  3. Directories
  4. Directories are where you store your files. They are organized more or less as a tree: each directory can contain files as well as subdirectories, and each subdirectory can contain more files, as well as more subdirectories...

    Moving around in the directory structure: cd

    In order to find and use your files, you need to be able to move around in directories. There are two ways to do this:

    Finding out where you are: pwd

    If you've forgotten where exactly you are in the directory structure, just type "pwd":
    	% cd /var/spool
    	% cd ..
    	% pwd

    Looking at a directory: ls

    To view the contents of a directory, type "ls":
    	% cd /var/spool
    	% ls
    	calendar        lpd             mqueue          secretmail
    	cron            lpd.lock        printers        uucp
    	locks           mail            rwho            uucppublic
    To display more information about the files in the directory, type "ls -l" instead:
    	% ls -l
    	total 31
    	drwxrwsrwt  2 daemon       6656 Sep  2 04:04 calendar
    	drwxr-sr-x  4 root          512 Aug 16 10:00 cron
    	drwxr-sr-x  2 uucp          512 Jul 26 12:13 locks
    	drwxrwsr-x  2 daemon        512 Jul 26  1995 lpd
    	-rw-r--r--  1 root            4 Aug 16 10:00 lpd.lock
    	drwxrwsrwt  2 root         4608 Sep  2 16:39 mail
    	drwxr-s---  2 root         9728 Sep  2 16:39 mqueue
    	lrwxrwxrwx  1 root           22 Jul 26  1995 printers -> /export/spool/printers
    	drwxr-sr-x  2 root          512 Oct 14  1994 rwho
    	drwxrwsrwx  2 bin           512 Oct 14  1994 secretmail
    	drwxr-sr-x 10 uucp          512 Aug 16 10:00 uucp
    	drwxrwsrwt  2 uucp          512 Oct 14  1994 uucppublic

    Creating a directory: mkdir

    Yes, you too can create your very own custom directories. Here's an example which creates a new directory called "games" in your home directory:
    	% cd 
    	% mkdir games

    Removing directories: rmdir

    Similarly, you can also remove directories, so long as they are empty. (If a directory you wish to delete is not empty, first remove all files contained in the directory, and then remove the emptied directory). Here's an example:
    	% cd $HOME/games
    	% rm *
    	% cd ..
    	% rmdir games
    Note that if you are using the (t)csh shell, the tilde character ~ is a shortcut for $HOME, your home directory. Hence the following are equivalent:
    	% cd
    	% cd ~/
    	% cd $HOME
    Similarly the following are equivalent:
    	% cd ~/bin
    	% cd $HOME/bin

  5. File Management
  6. Unix is very permissive about the names of its files. Any character can be part of the name, and the names can be as long as desired.

    Copying files: cp

    The syntax for the cp command is:
    	cp source_file destination
    Some examples:
    	% cp /etc/holidays myfile   	
    	% cp myfile myfile-old
    The first example copies the file holidays in the directory /etc into the file myfile in the current directory.

    Moving or renaming files: mv

    The syntax for the mv command is:
    	mv source destination
    You can use this to move a file, or to rename it:
    	% mv myfile-old myfile.old    
    	% mv myfile.old backups/myfile.old   
    The first example renames myfile-old so it is now named myfile.old. The second example moves myfile.old into the backups/ directory.

    Removing files: rm

    	rm file_to_be_removed
    Use this command to delete files you don't want:
    	% rm random.file

  7. Viewing Files
  8. You can always look at a (text) file by loading it into a text editor, such as Emacs. However, you can also view a file from the shell:

    Listing the contents of file(s): cat

    	% cat myfile      (displays contents of myfile)

    A nicer way to view files: more

    	% more myfile
    "More" allows you to read a file page by page. While viewing the file, the basic commands are space to see the next page, q to quit, return to see one more line, and b to go back a page.

  9. Executing Files
  10. Executable programs are just like any other file in Unix. You can mv, cp, or even cat them. To execute them, just use their name as a command:
    	% cp /bin/ls myls
    	% myls
    Sometimes you may run into a program that will not quit, or is stuck in an endless loop, and is tying up the shell. To abort the program, just type Ctrl-C while in the shell that is executing the program. This should cause the program to terminate.

    If for some reason when trying to run some program you get:

    	% programbin
    	programbin: Permission denied.
    you can correct the problem by changing the file permissions to execute:
    	% chmod u+x programbin

  11. Getting Help
  12. If you are unsure what a Unix command does, you can always refer to the online manual pages to help you out.

    Finding online help: man

    	man command
    	man -k keyword
    	apropos keyword
    man gives you information about specific commands. man -k tells you what commands relate to a given keyword.
    	% man -k sqrt
    	cbrt            sqrt (3m)       - square root, cube root
    	sqrt            sqrt (3m)       - square root, cube root
    	sqrt            cplxexp (3)     - functions in the C++ complex number math library
    The number in parentheses refers to the chapter of the manual in which the command is listed.
    	% man BattleTris
    If you are working on a X-Windows environment (ie. you are logged on from a workstation or an X-terminal, you can also try xman for a graphical interface to the man pages:
    	% xman &
    The "&" at the end of the previous line is used to run the "xman" process in the background and give you back control over your shell.

  13. Unix on the CFM systems
  14. CFM systems use the following variations of Unix:

  15. Other sources for Unix info
  16. Here's some other places you can look if you're interested in learning more about Unix: