UNIX Quick Reference

Log In Session

Log In

login:                  Enter your username here
password:               Enter your password here

Change Password

UNIX> passwd

Log Out

UNIX> logout          logs you out of the system
               --or--
UNIX> exit            logs you out of the system

File System

Create a File

UNIX> cat > file      Enter text and end with ctrl-D
UNIX> vi file         Edit file using the vi editor 

Make a Directory

UNIX> mkdir     directory-name

Display File Contents

UNIX> cat file        display contents of file 
UNIX> more file       page through contents of file

Comparing Files

UNIX> diff file1 file2   line by line comparison
UNIX> cmp file1 file2    byte by byte comparison

Changing Access Modes

UNIX> chmod mode file1 file2    changes modes of file1 and file2
UNIX> chmod -R mode dir         changes modes of all files in dir

Mode Settings

u user (owner)
g group
o other (world)

+ add permission
remove permission

r read
w write
x execute

As an example, chmod go-rwx foo.c removes read, write, and execute permissions for group and other on foo.c.

List Files and Directories

UNIX> ls        list contents of directory
UNIX> ls -a     include files with "." (dot files)
UNIX> ls -l     list contents in long format (show modes)

Move (or Rename) Files and Directories

UNIX> mv src-file dest-file    rename src-file to  dest-file
UNIX> mv src-file dest-dir     move a file into a directory
UNIX> mv src-dir dest-dir      rename src-dir, or move to dest-dir
UNIX> mv -i src dest          copy & prompt before overwriting

Copy Files

UNIX> cp src-file dest-file    copy src-file to  dest-file
UNIX> cp src-file dest-dir     copy a file into a directory
UNIX> cp -R src-dir dest-dir   copy one directory into another
UNIX> cp -i src dest          copy & prompt before overwriting

Remove File

UNIX> rm file      remove (delete) a file
UNIX> rmdir dir    remove an empty directory
UNIX> rm -r dir    remove a directory and its contents
UNIX> rm -i file   remove file, but prompt before deleting

Compressing files

UNIX> gzip file           compress a file, replacing it with file.gz
UNIX> gunzip file.gz      uncompress file.gz, replacing it with file

Change Working Directory

UNIX> cd        return to your login (home) directory
UNIX> cd dir    change to directory dir

Find Name of Current Directory

UNIX> pwd    display absolute path of working directory

Pathnames

foo.c                      if you currently are in the same directory as foo.c, you can access it like this
pgms/foo.c                 if foo.c is located in /home/jruser/pgms/foo.c and your current directory is /home/jruser
                            then you can give a relative path to the file 
/home/jruser/pgms/foo.c    the full path to foo.c

Directory Abbreviations

~                 Your home (login) directory
~username         Another user's home directory
.                 Working (current)  directory
..                Parent of working directory
../..             Parent of parent directory

Commands

Date

UNIX> date              display date and time

Wild Cards

?                   single character wild card
Example: 
   UNIX> fo?.c      would match foa.c, fob.c, foc.c, fo1.c, fo2.c, etc...

*                   Arbitrary number of characters
Example:
   UNIX> foo.*      would match foo.txt, foo.exe, foo.png, foo.jpeg, etc...

Printing

UNIX> lpr file              print file on default printer
UNIX> lpr -Pprinter file    print file on printer
UNIX> lpr -c# file          print # copies of file
UNIX> lpr -d file           interpret file as a dvi file
UNIX> lpq                   show print queue (-Pprinter also valid)
UNIX> lprm -#               remove print request # (listed with lpq)

Redirection

UNIX> command > file        direct output of command to file instead of standard output (screen), 
                            replacing current contents of file
UNIX> command >> file       as above, except output is appended to the current contents of file
UNIX> command < file        command receives input from file instead of standard input (keyboard)
UNIX> cmd1 | cmd2           "pipe" output of cmd1 to input of cmd2
UNIX> script file	    log everything displayed on the terminal to file; end with exit

Search Files

UNIX> grep hello file                show lines comtaining string "hello" in file
UNIX> grep hello file1 file2 ...     show lines containing string "hello" in any file in filelist
UNIX> grep hello *                   show lines containing string "hello" in any file in the directory
UNIX> grep -v hello *                show lines not containing string "hello"
UNIX> grep -i hello *                show lines containing string "hello", ignoring the case

Information on Users

UNIX> finger user            
 or
UNIX> finger user@machine    get information on a user 

UNIX> finger @machine        list users on a machine
UNIX> who                    list current users on the computer you are currently on

Timesavers

Aliases

UNIX> alias runvim /usr/local/bin/vim     will run /usr/local/bin/vim whenever you type in runvim

History: Command Repetition

Previously typed commands can be recalled

UNIX> history       show command history
UNIX> !num          repeat command with history number num
UNIX> !str          repeat last command beginning with string str
UNIX> !!            repeat entire last command line
UNIX> !$            repeat last word of last command line

Process and Job Control

Important Terms

pid→Process IDentification number. See this section

job-id→Job identification number. See this section

Display Process and/or Job IDs

UNIX> ps          report processes and pid numbers
UNIX> ps gx       as above, but include "hidden" processes
UNIX> jobs        report current jobs and job id numbers

Stop (Suspend) a Job

UNIX>           press ctrl and z to suspend a process. Note that the process still exists

Run a Job in the Background

UNIX> mozilla &          starts mozilla running in the background. Note that the browser window
                         will still come up

UNIX> mozilla
UNIX>  CRTL-Z
  [1]+  Stopped
UNIX> bg                 starts mozilla, then suspends it, then starts it running in the background

Bring a Job to the Foreground

UNIX> fg                       bring a job to foreground
UNIX> fg %job-id               foreground by job-id (see 7.2)

Kill a Process or Job

UNIX> CTRL-C                  press ctrl and c to kill a foreground process
UNIX> kill -KILL 12345        kill process with process-id 12345        

On-line Assistance

On-line Documentation

UNIX> man command-name      display on-line manual pages
UNIX> man -k string         list one-line summaries of manual pages containing string

 
  /blue/homes/labstaff/dokuwiki/data/accounts/architecture/unix/quickref.txt · Last modified: 2005/05/13 09:11 by 160.36.250.196 (britt)