Wednesday, May 27, 2009

UNIX Quick Reference Sheet

1 Log In Session

1.1 Log In

Enter username at login: prompt. Be carefull - Unix is case sensitive.
Enter password at
password: prompt.

1.2 Change Password

passwd

1.3 Log Out

logout or exit

2 File System

2.1 Create a File

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

2.2 Make a Directory

mkdir   directory-name

2.3 Display File Contents

cat   file    display contents of  file 
more  file    display contents of  file one screenfull at a  time.
view  file    a read only version of vi. 
less  file    similar to, but more powerfull than more. 
              See the man page for more infomation on  less.

2.4 Comparing Files

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

2.5 Changing Access Modes

chmod mode file1 file2 ...
chmod -R  mode dir (changes all files in  dir  )
    Mode Settings
 
 u  user (owner)
 g  group
 o  other
 
 +  add permission
 -  remove permission
 
 r  read
 w  write
 x  execute

Example: chmod go+rwx public.html adds read, write, and execute permissions for group and other on public.html.

2.6 List Files and Directories

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

2.7 Move (or Rename) Files and Directories

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

2.8 Copy Files

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

2.9 Remove File

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

2.10 Compressing files

compress file       encode file, replacing it with file.Z
zcat file.Z         display compressed file
uncompress file.Z   decode file.Z, replacing it with file

2.11 Find Name of Current Directory

pwd    display absolute path of working directory

2.12 Pathnames

simple:

One filename or directory name for accessing local file or directory.
Example:
foo.c

absolute:

List of directory names from root directory to desired file or directory name, each separated by /.
Example:
/src/shared

relative:

List of directory names from working directory to desired file or directory name, each separated by /.
Example:
Mail/inbox/23

2.13 Directory Abbreviations

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

2.14 Change Working Directory

cd /                           go to the root directory
cd                             go to your login (home) directory
cd ~username                   go to username's login (home) directory
                               not allowed in the Bourne shell
cd ~username/directory         go to username's indicated directory
cd ..                          go up one directory level from here
cd ../..                       go up two directory levels from here
cd /full/path/name/from/root   change directory to absolute path named 
                               note the leading slash
cd path/from/current/directory change directory to path relative to here. 
                               note there is no leading slash

3.0 Commands

3.1 Date

date    display date and time

3.2 Wild Cards

?    single character wild card
*    Arbitrary number of characters

3.3 Printing

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

3.4 Redirection

command > file         direct output of command to file instead of
                       to standard output (screen), replacing current 
                       contents of file

command > > file       as above, except output is appended to the current 
                       contents of file

command < file         command receives input from file instead of
                       from standard input (keyboard)

cmd1 | cmd2            "pipe" output of cmd1 to input of cmd2

script file            log everything displayed on the terminal to file; 
                       end with exit

4 Search Files

grep string filelist           show lines containing string in any file 
                               in filelist
grep -v string filelist        show lines not containing string
grep -i string filelist        show lines containing string, ignore case

5 Information on Users

finger user or
finger user@machine    get information on a user
finger @machine        list users on machine
who                    list current users

6 Timesavers

6.1 Aliases

alias string command     abbreviate command to string

6.2 History: Command Repetition

Commands may be recalled

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

7.0 Process and Job Control

7.1 Important Terms

pid            Process IDentification number.  See section 7.2.
job-id  Job identification number. See section 7.2.

7.2 Display Process and/or Job IDs

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

7.3 Stop (Suspend) a Job

ctrl-Z    NOTE:process still exists!

7.4 Run a Job in the Background

To start a job in  background add & to the end of the command. 
Example: xv foo.gif &


To force a running job into the background:

ctrl-Z    stop the job
bg        "push" the job  into the background

7.5 Bring a Job to the Foreground

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

7.6 Kill a Process or Job

ctrl-C                 kill foreground process
kill -KILL pid#        see 7.2 for 
kill -KILL %job-id#    displaying  pids & job-ids 

8.0 Mail Handler (MH)

MH commands are issued directly to the terminal.

inc        incorporate new mail
scan       show list of mail  messages
show       show  current message
next       show next message
prev       show previous message
repl       reply to current message
forw       forward current message
comp       compose a mail message
rmm        remove current mail message
cmd -help  print help on mh commmand cmd 

The file .mh_profile is used to enable/disable MH features. man mh-profile for more information.

9.0 On-line Assistance

On-line Documentation

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

 

No comments:

Post a Comment

Code Formater

Paste Here Your Source Code
Source Code Formatting Options
1) Convert Tab into Space :
2) Need Line Code Numbering :
3) Remove blank lines :
4) Embeded styles / Stylesheet :
5) Code Block Width :
6) Code Block Height :
7) Alternative Background :
Copy Formatted Source Code
 
Preview Of Formatted Code