23 February 2006

System Commands

(This is a subheading of Unix-3)

The shells exist for system commands (and for some basic coding). While there are differences in the features that the different shells offer users, they all respond to a similar set of system commands. It is my experience that Unix users tend to find ways of constantly alluding to these commands in contexts quite remote from computers, and then being astonished when one doesn't know what they are saying.

Here is a list of some of the more important. I leaned very heavily on UNIX: the Complete Reference (full citation below), but of course that book has 40 pages of commands and extensions, plus the other 1235 pages of instructions on how to use them. Moreover, that book specifies instructions used only in Solaris, instructions not used in Linux, etc. This series of posts has nothing to do with Linux, and I hope I'll get a chance to write about that in the near future.

The boldface command names link to the relevant man pages.

Basic & General:
bash: opens Bourne-Again Shell

bg: resumes suspended job in background

cat (concatenate): entering this command returns the contents of the designated file. It does not return a header, filename, date, or other secondary information. You can also use it to output the contents to a specified file. This, of course, allows one to merge files into a new one. Recall cat is typically used in programs so it is used to organize the output from a program.

cd: change directory; same as MS-DOS

cf: copies file1 into file or directory target

csh: opens C Shell

date: returns current date & time

exit: terminates current user session

fg: resumes suspended job in foreground

find: finds files in path for expression. Technically, the search performed with find is "live"; the shell will examine the contents of the files at the time the command is launched, rather than search a directory map. So find takes longer than grep.
-print: prints current pathname during search

-name pattern: finds files matching pattern

-exec command: performs command on files that are found
history: returns previous command; many be reset to return any number of previous commands.

jobs: returns list of jobs running currently

kill pid: : terminates process pid permanently; also allows one to send a signal to a process

ksh: opens Korn Shell

ln file1 target: links file1 to target; one may link many files to one target

ls (list): returns directory content listing;

man command: returns manual pages for command

mkdir dir: creates directory dir;

more: displays selected parts of files, depending on extension:
filenames: returns filenames to be displayed

-c: clears screen and redraws, rather than scroll;

-d: displays errors rather than beeping;

-s: displays multiple blank lines as one blank line;

+linenumber: starts display at linenumber
mv file1 target: move file1 to target; one may move many files to one target

pwd: returns directory information;

resume %jobid: resumes suspended job jobid;

set: returns value of all variables of the current shell;

sh: opens Bourne Shell

spell file: returns list of incorrectly spelled words in file;
-b: Checks for British spelling
tabs: Sets tabs

zsh: opens Z Shell

who: returns info about users on system
Basic Communications:
mail: reads mail sent to user
-user: sends mail to user ID user

-F sysa!user: Forwards mail to user ID user on system sysa

mailx: interactive mail function
-f fname: reads mail from file fname instead of the normal mailbox

-H: Displays the message header summary only

ping host: Sends a request to respond to system host through internet connection.

talk username: Sets up conversation with user username on internet
System Administration:
at t: Directs system to run command at time t; the command follows on the next line.
-f file: specifies file file with multiple commands to run

batch: Allows execution of commands to later time. The command "batch" implies that one doesn't care exactly when the command runs; typically this is understood to be whenever load permits (as on a client-server network).

cron: Begins a daemon processs to run routinely scheduled jobs

crontab file: Pulls entries from file into crontab directory
-e: Edits/creates empty file

-l: Displays all of the user's crontab entries

-r: Removes selected entries from crontab directory

df: Shows number of free disk blocks and files on the system

du: Shows number of disk blocks usage on the system

fsck: (I was surprised to learn this is a real word!) Runs file system check and repairs errors.

limit: Limits, among other things, file size

passwd name: changes the user's password; extensions allow one to set limits on the duration of the password, etc.

ps: Shows status of running processes
-a: Displays information about the most frequently requested processes

-e: Displays information about all currently running processes

-f: Displays a full listing of all currently running processes

sar: Reports on activities within a system
-o file: sends the report to file in binary format;

-i sec: Sets sampling rate for activities to sec seconds

-A: Reports all levels of process and device activity

shutdown: Shuts down the system (or launches some other system state)
-g grace: Specifies a grace period grace other than 60 seconds before shutdown;

-i state: Specifies new state state that the system is to enter

-y: Runs the shutdown process without any user intervention

tar files: Copies files to and extracts files named files from magnetic tape
-c: Creates new tape

-x: Extracts files form the mounted tape

useradd: Adds a new user login ID to the system
-D: Returns default values for user ID parameters

-d dir: Specifies alternative home directory dir for relevant user

-e date: Specifies date date as termination date for relevant user ID

-g group: Specifies the group ID group for this user

-o: Allows the user ID to be duplicated for other users on the system

-u UID: Specifies the user ID as UID for the relevant user

Text Formatting:
checkdoc file: Checks file for formatting errors

dpost file: Creates PostScript-formatted file from troff output file.

Tools & Utilities:
bc: Performs interactive arithmetic processing and displays results
-l: Allows use of functions contained in the /usr/bin/lib.b library

file: Specifies that interactive mathematical operations are to be performed on values listed in file:

cmp file1file2: compares the contents of two files byte for byte; returns nothing if the files are identical, returns the first line where a difference occurs

comm file1file2: sorts the contents of two files and compares them line for line;

cut file: Cut file; works similar to [control]-X in MS Windows, except one must enter file name, rather than selct with a mouse;

grep: the primary search function. You type in a search string, and grep returns the line with the string it finds. It allows you to search for one target with regular expression elements. Grep may also be used to search for the expression among files in a designated directory. Variants: fgrep (doesn't allow regular expressions, but allows multiple targets), egrep ("extended grep"—takes a richer set of expressions and allows multiple targets), pgrep (searches running processes for the search string). The egrep & fgrep variants have since been mostly rolled into the modern grep.

look "string" file: Searches for occurrence of "string" in file. Returns lines that begin with the string. (Note: the grep ^^string does exactly the same thing. Redundancy is not a vice in Unixworld.)

paste file1file2: Combines text of file1 with file2. Not at all like [control]-V in MS Windows; for one thing, paste command does not recall text captured in prior use of cut command

sed ("stream editor"): filters text files. It is analogous to the search-replace feature found in many Windows or Macintosh programs, but can be used from a program itself to modify output.
My purpose in listing the commands above was to illustrate some of the power imbedded in the Unix shell. I have not written about any of the GUI's, such as Solaris, X Windows, and Mac OS X, since those represent different topics. It's true that a lot of Unix users now tend to use Unix commands like these through GUI "shells" instead, and this has blurred much of the distinction between Unix and competing development environments. On the other hand, my purpose was to illustrate some of the tools that were developed, and are now taken for granted by computer users.
daemon: short for user daemon (pron. DAME-on) A user daemon is simply a background process that does useful work for a specific user. Typically daemons are used for operations that do not require execution at a specific time, like permanently deleting older files from a full wastebasket.

file: recall Unix treats everything as a file, including other terminals, other running processes, and so on. So, for example, outputing something to a designated file is a rather powerful instruction.

regular expression (regex): here, an expression using a standardized search syntax; for example, the command % grep \ban returns all the lines containing "an" at the beginning of a word (i.e., after a word break, hence the expression \b). Another example of a regex are the wildcards $ and *, which are used as substitutes for any unspecified character or character string, respectively.
RESOURCES: The Art of Unix Programming, Eric Raymond: esp. "Taxonomy of Unix IPC Methods" and "Application Protocol Design"; Wikipedia, cat, cmp, comm, grep, list of Unix programs, regular expression, sed; "Mac OS X Unix Tutorial | page 2 of 2," Inside Mac Media

ONLINE TUTORIALS: Unix tutorial, Stanford University School of Earth Sciences, USA; "Unix for Web developers," eXtropia tutorials; "UNIX Tutorial for Beginners," University of Surrey, Guildford, UK; "Unix System Administration Independent Learning," USAIL;

BOOKS: UNIX: the Complete Reference, by Kenneth Rosen, Douglas Host, James Farber, & Richard Rosinski—Tata McGraw-Hill edition 2002

Labels: , , , ,


Post a Comment

<< Home