CIRCA Unix Services

This handout can be found online at:
http://www.circa.ufl.edu/handouts/unix/unixcmd.html

Quick guide to Unix commands

August 23, 2005


Table of Contents

  1. Files, directories, and paths
  2. Entering Unix commands
  3. Informational commands
  4. Commands for files
  5. Directory commands
  6. File permissions

This handout is a brief reference to some common commands available on most Unix systems, including Grove, the CIRCA Unix computer. If you've never used Unix before, you might want to buy one of the many beginner's Unix books available at some bookstores.

Files, directories, and paths

Files are stored in directories. You have a home directory to store your files in, and you can create more directories in your home directory.

A pathname is a complete specification for a file with all its directories. An absolute pathname begins with a slash and specifies the full name of the directory, for example:

/elm/user/bob/prog.c

A relative pathname is based on the current working directory. For example, this pathname specifies a file named test in the subdirectory project1:

project1/test

These special symbols can be used in a path:

 symbol   meaning
 ------   -------------------------------
 ~        your home directory                 
 .        the current directory               
 ..       the directory above the current     
          directory                           

These examples show where Unix would look for the file abc based on the path you specify:

 abc                            in the current directory

 subs/abc                       in the subdirectory subs of the
                                current directory

 /staff/fred/abc                in the directory /staff/fred

 ../abc                         in the directory above the current 
                                directory

 ~/abc                          in your home directory

Entering Unix commands

In Unix, upper case and lower case letters are not equivalent. You must type commands in the correct case. Almost all Unix commands are in lowercase.

Many commands have optional flags. Flags are usually preceded by a "-" and are typed as a single letter. For example, the "a" and "l" flags on the ls command:

ls -al /etc

Some commands require a parameter, such as the name of a file. For example, to display the file emacs.txt:

cat emacs.txt

If a file name without a path is specified on a command, the file is assumed to be in the current directory. You always can specify the complete path for the file.

When a file name is used on command, you usually can use wild cards to specify a group of commands. A percent (%) in a file name means that any name with any character at that position will match. An asterisk (*) will match a group of characters.

Informational commands

These are some commands you can use to display information about your Unix system:

 command          what's displayed
 -----------      ------------------------------------------
 man command      online manual page for command                     
 whatis command   one line description of command                     
 apropos keyword  names of manual pages that are relevant to        
                  specified keyword           
 pwd              current directory pathname  
 who              who's logged in             
 date             date and time

Commands for files

These are some of the commands you can use to display or manipulate files on your computer:

 command   function
 -------   -----------------------------------             
 rm        remove (delete) named file or files                           
 mv        move (rename) a file to a new name                               
 cp        copy the first file to the second file                               
 cat       display file on screen                             
 more      display file, pause for each screen                             
 head      display first few lines of a file                             
 tail      display last few lines of a file                             

Here are some examples of these commands:

 rm test.f              delete the file test.f

 cp proj.c saveme       copy the file proj.c to the file
                        saveme

 more log.txt           displays the file log.txt, stopping
                        at each screen

Directory commands

The ls command displays the names of the files in a directory. Some ls command options are:

 option  meaning
 ------  ------------------------------------------------
 a       include files with names starting with a period                       
 l       list in long format with sizes and dates
 R       list files in subdirectories also   
 F       mark directories with /, executable files with *             

Here are some examples of the ls command:

 ls                     list names of files in current directory

 ls -al                 list all files in long format
 
 ls /etc/bin            list files in /etc/bin

These commands manipulate directories and require the name of a directory as a parameter.

 command     function
 -------     -----------------------------
 cd          change to specified directory    
 mkdir       make a new directory             
 rmdir       remove (delete) a directory      

File permissions

File permissions give other users the ability read, write, or execute a file. Permissions can be granted to another user in your group, or all others. Use the chmod command to change file permission for a file:

chmod who+/-permission file

 who     means         permission   means
 ---     ----------    ----------   -------
 u       you           r            read       
 g       your group    w            write      
 o       all others    x            execute    

Examples:

chmod go+rx xyz let all others read or execute the file xyz chmod go-rx xyz retract read/execute permission from group and others

You can change the default protection for new files with the umask command. This command has an obscure numeric parameter too complex to document here, but here are some common uses of the command:

umask                   show current umask

umask 77                set no access by group or other for new files

umask 22                set read or execute access by group or other for
                        new files


Center for Instructional and Research Computing Activities • E520 CSE • University of Florida, Gainesville, FL
Call the UF Computing Help Desk for Assistance • (352) 392-HELP • SUNCOM 622-HELP