Sei sulla pagina 1di 4

Quick Unix Reference

http://sunsite.utk.edu/UNIX-help/quickref.html

Unix Help UNIX Quick Reference Sheet


This a summary of some common Unix commands. Some of these commands may not be on your Unix Systems and some commands may not work exactly as show. - The Management

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 vi file Enter text and end with ctrl-D Edit file using the vi editor

2.2 Make a Directory


mkdir directory-name

2.3 Display File Contents


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

2.4 Comparing Files


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

2.5 Changing Access Modes


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

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 ls -a ls -l list contents of directory include files with "." (dot files) list contents in long format (show modes)

2.7 Move (or Rename) Files and Directories


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

1 of 4

4/3/2012 7:35 PM

Quick Unix Reference

http://sunsite.utk.edu/UNIX-help/quickref.html

2.8 Copy Files


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

2.9 Remove File


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

2.10 Compressing files


compress file zcat file.Z uncompress file.Z encode file, replacing it with file.Z display compressed file 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


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

2.14 Change Working Directory


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

cd path/from/current/directory

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

3.4 Redirection

2 of 4

4/3/2012 7:35 PM

Quick Unix Reference

http://sunsite.utk.edu/UNIX-help/quickref.html

command > file

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

command > > file

command < file cmd1 | cmd2 script file

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

5 Information on Users
finger user or finger user@machine finger @machine who get information on a user list users on machine 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 !num !str !! !$ show command history repeat command with history number num 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 job-id Process IDentification number. See section 7.2. Job identification number. See section 7.2.

7.2 Display Process and/or Job IDs


ps ps gx jobs report processes and pid numbers as above, but include "hidden" processes 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 bg stop the job "push" the job into the background

7.5 Bring a Job to the Foreground


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

7.6 Kill a Process or Job


ctrl-C kill foreground process

3 of 4

4/3/2012 7:35 PM

Quick Unix Reference

http://sunsite.utk.edu/UNIX-help/quickref.html

kill -KILL pid# kill -KILL %job-id#

see 7.2 for displaying pids & job-ids

8.0 Mail Handler (MH)


MH commands are issued directly to the terminal.
inc scan show next prev repl forw comp rmm cmd -help incorporate new mail show list of mail messages show current message show next message show previous message reply to current message forward current message compose a mail message remove current mail message 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 man -k string display on-line manual pages list one-line summaries of manual pages containing string

4 of 4

4/3/2012 7:35 PM

Potrebbero piacerti anche