ch00_13.htm:(who wrote Section 28.5 and Section 30.8 in the early 1980s, by the way) led the first ch01_01.htm:Window System (Section 1.22), and ch01_02.htm:enough, saving them for later execution in a file (Section 1.8), alias (Section 29.2), or ch01_02.htm:function (Section 29.11). Gradually, if the user has the right ch01_02.htm:(Section 28.9) to apply the same editing script to a ch01_03.htm:worked with a Unix box that doesn't have vi (Section 21.7) installed. ch01_03.htm:(Section 1.16) or getting additional help with ch01_03.htm:man (Section 2.1). ch01_03.htm:utility such as make (Section 40.3) and another installation has a GNU version of ch01_04.htm:the shell (Section 27.1). A shell is a command ch01_04.htm:(Section 2.7). ch01_04.htm:kernel (Section 1.10). Usually, only ch01_04.htm:

??? Section 1.13

ch01_04.htm:filenames, makes a complete list of them, and calls the cat (Section 12.2) command to ch01_04.htm:

Why is this important? First of all, you can choose between several different shells (Section 1.6), each of which may have different rules for ch01_04.htm:For example, if you are calling grep (Section 13.1), a program for searching through files for a ch01_04.htm:single argument. The shell lets you do this by quoting (Section 27.12) ch01_04.htm:cases, especially when dealing with wildcards (Section 1.13), like ch01_04.htm:commands (Section 1.9) that run directly ch01_05.htm:file (Section 43.1). ch01_05.htm:together in this way. An interactive program like the Emacs editor (Section 19.1) ch01_05.htm:independently of the shell (Section 1.4), ch01_05.htm:are even exceptions to this exception. A program like less (Section 12.3) can read ch01_05.htm:keyboard. It does that by reading directly from your tty (Section 2.7). ch01_06.htm:Bourne shell (Section 3.3) (named after its creator, Steve Bourne) came ch01_06.htm:programming (Section 1.8). But many Unix ch01_06.htm:(Section 23.1) and history (Section 30.2). ch01_06.htm:history editing (Section 30.14), often called command-line ch01_07.htm:

If your shell has superuser (Section 1.18) privileges, though, the prompt typically ends ch01_08.htm:the Unix tr (Section 21.11) command can convert every occurrence of one ch01_08.htm:directory (Section 7.4): ch01_08.htm:with chmod (Section 50.5): ch01_08.htm:

for Section 35.21, $x Section 35.9

ch01_08.htm:variable substitution (Section 35.9, Section 35.3).[1] ch01_08.htm:wanted to repeat. Section 35.2 has more about ch01_08.htm:a filter (Section 1.5) by adding four or five more lines of code: a ch01_08.htm:case (Section 35.10) or ch01_08.htm:if (Section 35.13) statement that ch01_09.htm:(Section 27.2) a new subprocess (Section 24.3); ch01_09.htm:(Section 1.16) beginning with /, like ch01_09.htm:check for aliases (Section 29.2) or shell ch01_09.htm:functions (Section 29.11), which may have ch01_09.htm:file (Section 3.3) that was read when the ch01_09.htm:external commands (Section 27.6); this saves a long hunt down the search path. ch01_09.htm:System (Section 1.22) are stored in ch01_09.htm:variable (Section 35.3) called PATH (Section 35.6). A typical ch01_10.htm:the ps x (Section 24.5) ch01_10.htm:output!) The user logged into his Linux system on virtual console (Section 23.12) ch01_10.htm:including the X Window System (Section 1.22) (which actually runs itself as another ch01_11.htm:files (Section 1.19).) The names are words ch01_11.htm:extensions (Section 1.12). Extensions are ch01_11.htm:match (Section 1.13) them unless you ch01_11.htm:(ls -a (Section 8.9)). Special configuration files are often ch01_11.htm:weird names (Section 14.11), though, in ch01_11.htm:version. There are some revision control programs (Section 39.4) that implement their own notion of a version, ch01_11.htm:on Unix to save your previous versions -- you can program this (Section 35.16, ch01_11.htm:Section 18.14) though, if you want to; the GNU Emacs ch01_11.htm:editor also makes backups (Section 19.4). ch01_11.htm:forever (Section 14.3). You ch01_12.htm:(Section 15.6) ch01_12.htm:

Compressed file Section 15.6) ch01_12.htm:

Online manual (Section 2.1) source file ch01_12.htm:

Emacs editor backup file (Section 19.4) ch01_12.htm:(Section 39.2) ch01_12.htm:

gzip ped (Section 15.6) tar archive (Section 39.2) ch01_12.htm:

Bourne shell script (Section 1.8) ch01_13.htm:directory (Section 1.16). You could delete ch01_13.htm:root (Section 1.14) and the character used ch01_13.htm:to separate directory names in a path (Section 1.16). The only ch01_13.htm:files unless you ask (Section 8.9) for them. If a file's name ch01_13.htm:files (Section 28.3) -- though many ch01_13.htm:braces ({}) for doing that. Section 33.3 explains how wildcards are handled, and ch01_13.htm:Section 33.2 has more about wildcards, ch01_14.htm:Section 10.2). A directory can contain any ch01_14.htm:paths (Section 1.16). ch01_15.htm:filesystems (Section 1.14), much like ch01_15.htm:very own, to store your files (especially the shell setup files (Section 3.3) and rc files ch01_15.htm:(Section 3.20) that you use to customize the rest of ch01_15.htm:(Section 1.16) to your home, type ch01_16.htm:pathname (Section 1.14) (starting from the ch01_16.htm:first log in, your current directory is your home directory (Section 1.15), ch01_16.htm:the home directory of the user name. See Section 31.11. ch01_16.htm:

Section 10.2 explains where ch01_17.htm:unique account with a unique login name and a unique UID (Section 24.3) (user ID ch01_17.htm:(Section 22.3)) defines his "primary ch01_17.htm:group membership." The /etc/group (Section 49.6) file ch01_17.htm:use a command like newgrp (Section 48.6) to change the group to which you currently ch01_17.htm:(Section 15.11), I can also use the ch01_17.htm:quotas, see Section 50.15.) For example, to ch01_18.htm:

In general, a process (Section 24.1) is a program that's running: ch01_18.htm:process (Section 24.12), change its priority (Section 26.5), or manipulate it in any other way, you have ch01_18.htm:queue (Section 45.1), you must be the user ch01_18.htm:root or use the su (Section 49.9) command. In ch01_19.htm:pipes (FIFOs) (Section 43.11) and processes are ch01_19.htm:files (Section 24.9). Like waves and ch01_21.htm:X Window System (Section 1.22) programs whose display opens on your local ch01_21.htm:system. Section 6.10 has examples -- as ch01_21.htm:(Section 1.22) connections, as well as other types of ch01_22.htm:still a simple terminal emulator (xterm (Section 5.9)). ch02_01.htm:man command may understand the MANPATH (Section 3.21) environment variable, a list of where ch02_01.htm:

Your system may also have a different manual page system: info (Section 2.9). ch02_02.htm:-k (Section 2.1), but it requires a ch02_02.htm:cat (Section 12.2) ch02_03.htm:(Section 12.2) from the system, or my PATH (Section 35.6) ch02_04.htm:(Section 2.1) files. You'll ch02_04.htm:usually be able to narrow your search to one or two manual page sections (Section 2.1); here, you know that user commands are in ch02_04.htm:find (Section 9.4) ch02_04.htm:(Section 9.18), try searching for ch02_04.htm:

Your manpage files may be compressed (Section 15.6). In ch02_04.htm:that case, use grep (Section 13.2) with the -Z option, ch02_04.htm:unformatted (shown in Section 3.22) and ch02_04.htm:loop (Section 28.9) applies a series of ch02_04.htm:

* Section 1.13

ch02_04.htm:(Section 12.3)) to see the output a screenful at a ch02_06.htm:own bin directory (Section 7.4)). ch02_06.htm:Which command you'll get depends on your PATH (Section 35.6) ch02_06.htm:which command is usually external (Section 1.9), so it ch02_07.htm:login session has its own tty (Section 24.6) -- a ch02_07.htm:to write or talk (Section 1.21) to you, ch02_07.htm:telnet, etc. (Section 1.21). A system file like ch02_07.htm:test in my .logout file (Section 4.17) that ch02_07.htm:

` ` Section 28.14

ch02_08.htm:tty (Section 2.7) ch02_08.htm:number, the login time, and, if the user is coming in via a network (Section 1.21), ch02_08.htm:(Section 13.1) -- especially on systems with a lot ch02_08.htm:

-v Section 13.3

ch03_01.htm:interactive (Section 3.4), you may well be denied a command line. This ch03_03.htm:a nonlogin shell (Section 3.4). There are different setup files for nonlogin ch03_03.htm:you. The login program sets a special flag (Section 3.19) ch03_03.htm:an xterm window (Section 24.20); ch03_03.htm:starts a nonlogin shell. And a subshell (Section 24.4) is ch03_03.htm:want a login shell that sets things like the terminal type (Section 5.2, ch03_03.htm:Section 5.3). Other shells on the same terminal ch03_03.htm:operators (Section 43.7) ch03_03.htm:( Section 35.3) like HOME, PATH, SHELL, TERM, MAIL, and ch03_03.htm:process to child process (Section 35.4), ch03_03.htm:shell) on startup of a shell. On Mac OS X, when you use Terminal (Section 3.2), your ch03_03.htm:variable (Section 35.3) (but only for ch03_03.htm:subshell (Section 43.7), though. Subshells are set up through ch03_03.htm:(Section 35.3) that were set when you first logged in ch03_03.htm:time you start a shell. For instance, shell variables like cdpath (Section 31.5) and ch03_03.htm:(Section 29.2) should, ch03_03.htm:(Section 35.3) (which Unix will pass to subshells ch03_03.htm:automatically). Run commands like tset (Section 5.3) and ch03_03.htm:stty (Section 5.7, ch03_03.htm:Section 5.8) that set up your terminal. Finally, ch03_03.htm:for mail and news (Section 1.21), running fortune, checking ch03_03.htm:Section 3.8 has tips for reading ch03_03.htm:shell. A login Korn shell (Section 3.4) will read the ch03_03.htm:present. The .profile can set the ENV (Section 35.5) ch03_03.htm:set a trap (Section 4.18) to handle nonlogin shells. ch03_04.htm:a login shell. (Section 3.4) A login shell is typcally the top-level shell ch03_04.htm:starts with the init (Section 24.2) process. Many characteristics of processes ch03_04.htm:"tree" -- especially environment variables (Section 35.3), such as the search ch03_04.htm:path (Section 35.6). The changes you make ch03_04.htm:top-level shell starts -- including any subshells (Section 24.4). ch03_04.htm:(Section 3.19) when it's a login ch03_04.htm:shell -- and, if it is, the shell reads special setup files (Section 3.3) for ch03_04.htm:by your window system (Section 24.20), or ch03_04.htm:at (Section 25.5), ch03_04.htm:rsh (Section 1.21), ch03_04.htm:manual page for details. Section 4.12 shows ch03_04.htm:that's only read by login shells (Section 3.3). The line sets a shell ch03_04.htm:variable (Section 35.9) named ch03_04.htm:

if Section 35.13

ch03_04.htm:script (Section 35.2). In this case, the shell ch03_05.htm:

Setup files for login shells ( Section 3.4) -- such as ch03_05.htm:(Section 27.6) if the system default path ch03_05.htm:(Section 5.3) and make various ch03_05.htm:terminal settings (Section 5.7, Section 5.8) if the system might not know your terminal ch03_05.htm:(Section 35.3) that might ch03_05.htm:who (Section 2.8) ch03_05.htm:or uptime (Section 26.4) or w (a combination of the ch03_05.htm:want aliases (Section 28.2) available in every interactive shell you ch03_05.htm:

Coordinating custom setup files on different machines (Section 3.18). ch03_05.htm:you're using (Section 3.10 ch03_06.htm:setup file (Section 3.3) or your password, it can be tough to log in ch03_06.htm:(Section 1.21) to log in to your host again from the ch03_07.htm:shell setup files (Section 3.3) is lines like these: ch03_07.htm:

$$ Section 27.17, `...` Section ch03_07.htm:

What's wrong with those lines? Both use relative pathnames (Section 1.16) for the files (.aliases, ch03_07.htm:subshell (Section 24.4) from somewhere besides your home directory ch03_07.htm:ever use the source or . commands (Section 35.29) ch03_07.htm:

Use absolute pathnames instead. As Section 31.11 explains, the pathname of your ch03_08.htm:particular times (Section 3.3). Only ch03_08.htm:shells (Section 3.4) will read the ch03_08.htm:systems (like xterm (Section 24.20)), remote shells (like ch03_08.htm:rsh (Section 1.21) ch03_08.htm:because all subshells (Section 24.4) read it . . . you definitely ch03_08.htm:don't want to run terminal-setting commands like tset (Section 5.3) during ch03_08.htm:variable (Section 35.3) as a flag. ch03_08.htm:exit command (Section 35.12) to log ch03_08.htm:

case Section ch03_08.htm:35.10, / Section 36.25, ch03_08.htm:function Section 29.11, ch03_08.htm:. Section 35.29

ch03_08.htm:

The builtin exit (Section 27.9) ch03_08.htm:(Section 27.10) instead. This isn't ch03_08.htm:shell (Section 3.6) and be ready to ch03_08.htm:kill (Section 24.12) ch03_09.htm:command (Section 2.6) set the prompt variable ch03_09.htm:environment variable (Section 35.3). The variable will be copied into all ch03_09.htm:(Section 24.4) (like the one that which ch03_09.htm:(Section 25.5) that runs jobs from interactive ch03_09.htm:at (Section 29.1) ch03_09.htm:

( ) Section 43.7, \at Section 29.8

ch03_10.htm:(Section 5.8) to set the correct ch03_10.htm: Bourne-type shells use case (Section 35.10) and ch03_10.htm:if (Section 35.13). ch03_10.htm:TERM environment variable (Section 3.11). Testing other ch03_10.htm:environment variables (Section 3.14) can ch03_10.htm:

Test the output of who am i (Section 3.12) to ch03_10.htm:type (Section 3.15) in a table like ch03_10.htm:/etc/inittab (in some other variants). Testing the port name (Section 3.13) may also work. ch03_10.htm:

In the X Window System, you can test the window size (Section 3.16) and make various settings based on that. ch03_10.htm:Naming windows (Section 3.17) lets you identify a particular window by ch03_10.htm:obscure tset (Section 5.3) program ch03_10.htm:that sets the terminal type is qterm (Section 5.4). ch03_10.htm:.cshrc. Section 3.3 can ch03_11.htm:statement (Section 35.10) in your .profile ch03_12.htm:other hosts (Section 1.21) or from hosts ch03_12.htm:running the X Window System (Section 24.20), the who am i[8] command will probably show a ch03_12.htm:

case Section 35.10

ch03_12.htm:Section 34.11

ch03_12.htm:sed (Section 34.1) ch03_13.htm:and ssh (Section 1.21), ch03_13.htm:

tty Section 2.7

ch03_14.htm:variable (Section 35.5). If ch03_14.htm:ssh (Section 1.21), ch03_14.htm:or printenv command (Section 35.3) to look ch03_14.htm:

Your shell setup file (Section 3.3) makes decisions based on the environment ch03_14.htm:

[ ] Section 35.26

ch03_15.htm:file that lists the type of each terminal port (tty (Section 24.6)).[9] Here are lines from /etc/ttys on a ch03_15.htm:network, the type used by xterm (Section 24.20), ch03_15.htm:telnet (Section 1.21), etc. ch03_15.htm:match the first column of that file to the output of the tty (Section 2.7) command, ch03_15.htm:

awk Section 20.10

ch03_15.htm:

Then you can test the value with case (Section 35.10) or ch03_15.htm:if (Section 35.13). ch03_15.htm::t string modifier (Section 28.5) and test its value with ch03_16.htm:excerpt from my X setup file (Section 3.20) that opens the windows: ch03_16.htm:

-e Section 5.22

ch03_16.htm:less (Section 12.3) ch03_16.htm:(Section 35.25) command puts the number of rows into ch03_16.htm:easier.) Then a series of if (Section 35.13)/then (Section 35.26) tests handle different window sizes: ch03_17.htm:windows. Here's an excerpt from my X setup file (Section 3.20): ch03_17.htm:

-fSection 11.10, { }Section 28.4

ch03_17.htm:(Section 23.2) to watch log files. On the work ch03_18.htm:

setenv Section 35.3

ch03_18.htm:

~ Section 31.11

ch03_18.htm:(Section 2.5) bosco, and I have ch03_18.htm:can source (Section 35.29) it to customize my environment for that one ch03_18.htm:
Search path (Section 27.6)
ch03_18.htm:/opt. The same goes for cdpath (Section 31.5). ch03_18.htm:
Terminal settings (Section 5.8)
ch03_18.htm:
Other shell variables (Section 35.9) and environment variables (Section 35.3)
ch03_19.htm:shell
. When a shell is a login shell, it acts differently (Section 3.4). ch03_19.htm:ps (Section 24.5) ch03_19.htm:

A more general solution is to make a link (Section 10.4) to the ch03_19.htm:

bin Section 7.4, ./- Section 14.13

ch03_20.htm:

One way to set defaults for your applications is with environment variables (Section 35.3) that the applications might read. This can ch03_20.htm:files (Section 3.3). Most of these ch03_20.htm:hidden (Section 8.9) in your home directory; ch03_20.htm:It's one of those acronyms, like spool (Section 45.2), ch03_20.htm:For the Emacs editor. See Section 19.3.

ch03_20.htm:editor. See Section 17.5. ch03_20.htm:For the mail (Section 1.21) program and others like it. This can be handy ch03_20.htm:ftp and some other programs. Should have file access mode (Section 50.2) 600 or 400 for security, but this may not be ch03_20.htm:For news readers (Section 1.21). (Some newer news readers have more complex ch03_20.htm:and rlogin (Section 1.21). Remote ch03_20.htm:mode (Section 50.2) 600 or 400. We suggest ch03_20.htm:A resource file (Section 6.5) for the X Window System. Sometimes also ch03_20.htm:A shell script (Section 35.2) that runs as you log in to an X Window System ch03_20.htm:

$Id Section ch03_20.htm:39.5, exec > Section ch03_20.htm:36.5, -v Section 35.25, uname -n Section 2.5 ch03_20.htm:, ${..:=..} Section ch03_20.htm:36.7, export Section ch03_20.htm:35.3, xrdb Section ch03_20.htm:Section 24.21, exec Section 36.5

ch03_20.htm:script (Section 35.2), but it can be any ch03_20.htm:shell scripts (Section 35.2). If you know a little about shell ch03_21.htm:use the nroff -man macros (Section 3.22) if you ch03_21.htm:

The man (Section 2.1) command is essentially the same as this: ch03_21.htm:

-s Section 11.7

ch03_21.htm:

~ Section 31.11

ch03_21.htm:systems have a MANPATH environment variable (Section 35.3), a colon-separated list of directories where ch03_21.htm:following C shell alias (Section 29.3): ch03_21.htm:

less Section 12.3

ch03_21.htm:

or shell function (Section 29.11): ch03_21.htm:want to save space in your filesystem, you can use the gzip (Section 15.6) utility on ch03_22.htm:we discussed in Section 3.21, ch03_22.htm:

1 Section 2.1

ch03_22.htm:

Section heading; one for each section.

ch04_01.htm:variable (Section 35.9) called ch04_01.htm:

There are two or three ways to set a prompt. One is a static prompt (Section 4.2) ch04_01.htm:(Section 4.3) string that is interpreted by the ch04_01.htm:simulate a dynamic prompt (Section 4.4) by changing the prompt string ch04_01.htm:prompt on the command line, store it in the correct shell setup file (Section 3.3): use the file that's read by ch04_01.htm:pointless -- and it can even cause problems (Section 4.5).) ch04_02.htm:

As Section 4.1 explains, the simplest ch04_02.htm:

Notice the single quotes (Section 11.3) ch04_02.htm:double quotes (Section 12.3) around the values, which lets the shell ch04_02.htm:runs the command substitution (Section 28.14) that gives the hostname -- once, ch04_03.htm:printed. As Section 4.1 explains, ch04_03.htm:don't have these special sequences. Section 4.4 has a technique that should work for you.) ch04_03.htm:(Section 27.1) as the prompt is stored. For example, ch04_03.htm:Section 4.14 shows, makes it easy to use ch04_03.htm:history (Section 30.8) to repeat or modify a previous command. You ch04_04.htm:shown in Section 4.3. If you still want a ch04_04.htm:prompt_subst (Section 28.14) in your ch04_04.htm:.zshrc file (Section 3.3).) ch04_04.htm:a multiline prompt (Section 4.7). Or you could write a simple shell function (Section 29.11) ch04_04.htm:writing a shell alias (Section 29.2) named something like setprompt (Section 4.14) that resets the ch04_04.htm:see Section 4.15 for a similar trick.) ch04_05.htm:already set (Section 4.1), many older versions of ch04_05.htm:(Section 1.13) and the tilde (~) (Section 31.11). ch04_06.htm:external (Section 1.9). Built-in commands ch04_06.htm:

Section 4.3 has examples of some shells' ch04_06.htm:way an external command in backquotes (Section 28.14), ch04_06.htm:basename (Section 36.13) or sed ch04_06.htm:(Section 34.1) with the current directory from ch04_06.htm:following code listing, and probably in an alias like setprompt (Section 4.7) to ch04_06.htm:

{} Section 35.9

ch04_06.htm:(Section 28.5) like :t; the Korn Shell, ch04_06.htm:(Section 28.5). ch04_06.htm:

If your prompt gets complex, you can use a shell function (Section 29.11) ch04_06.htm:

${+} Section 36.7, $(...) Section 28.14

ch04_06.htm:variable named SCRIPT while the script (Section 37.7) program ch04_06.htm:visualize, Section 24.3 and Section 35.3 have some background.) ch04_06.htm:is a case statement (Section 35.11) that ch04_06.htm:tests $TTY, the name of the tty (Section 2.7) ch04_06.htm:consoles (Section 23.12). In that case, I ch04_06.htm:(Section 31.7)). The second line has the ch04_06.htm:prompt string is inside double quotes (Section 27.12) ch04_06.htm:

As another example, Section 4.14 shows more ch04_07.htm:quoting (Section 27.13) is ch04_07.htm:

uname -n Section 2.5, {..} Section 35.9

ch04_07.htm:newline; Section 27.12 explains. ch04_08.htm:Bourne-type shells with a shell function and case (Section 35.10) statement; ch04_08.htm:

:h Section ch04_08.htm:28.5, && Section 35.14

ch04_08.htm:

(Section 5.15 has more about how this works ch04_08.htm:set until after the alias has been read. There are workarounds (Section 3.8). ch04_08.htm:(Section 1.21), ch04_08.htm:subshells (Section 24.4), etc. These might make a new status line or ch04_09.htm:

Next, a multiline prompt (Section 4.7) for the C shell .cshrc ch04_10.htm:later. (The GNU dircolors (Section 8.6) ch04_10.htm:

uname -n Section 2.5

ch04_10.htm:it's very handy.) Section 4.6 and Section 27.12 have more ch04_10.htm:shell variables (Section 35.9). ch04_12.htm:escape (Section 17.21) or any subshell (Section 24.4), you ch04_12.htm:shell history (Section 30.1) might get confused, shell variables (Section 35.9) ch04_12.htm:environment variable (Section 35.3) that lets you track how many subshells deep ch04_12.htm:bit of arithmetic in the ENV (Section 35.5) file or the .cshrc file, ch04_12.htm:consoles (Section 23.12)) and that the ch04_12.htm:check who (Section 2.8).) You may need to adapt this. The trick is to ch04_12.htm:

Getting this to work right in every situation (rsh (Section 1.21), ssh, su, ch04_12.htm:shell escapes (Section 17.21) -- both interactive ch04_12.htm:and noninteractive (Section 3.4) -- subshells, window systems, at jobs ch04_12.htm:(Section 25.5), and so on) can ch04_12.htm:be a challenge (Section 3.8)! It takes a ch04_12.htm:printenv command (Section 35.3).) Then ch04_13.htm:editing (Section 30.14) that modern Unix ch04_13.htm:

If you want some information in your prompt, too, make a multiline prompt (Section 4.7) with four spaces in the last line. ch04_14.htm:popd (Section 30.7) ch04_14.htm:.tcshrc to make a multiline prompt (Section 4.7) that shows the directory stack: ch04_14.htm:

uname -n Section 2.5, expr Section 36.21

ch04_14.htm:built-in prompt operators (Section 4.3) like \u, the ch04_14.htm:

$(...) Section 28.14

ch04_14.htm:string editing (Section 28.5). ch04_15.htm:trap (Section 35.17) ch04_15.htm:will run one or more commands when the shell gets a signal (Section 24.10) ch04_15.htm:instance, the shell could reread a configuration file; Section 24.13 shows that. Or it could set a new ch04_15.htm:cron job (Section 25.2)) sends the ch04_15.htm:(Section 23.2) job springs this trap once a minute. ch04_15.htm:(possibly with some editing, probably with sed (Section 34.1) or ch04_15.htm:expr (Section 36.21)): count the number of users, show the ch04_15.htm:load average (Section 26.4), whatever. Newer shells, like ch04_15.htm:backquotes (Section 28.14) each time the ch04_15.htm:prompt is displayed -- Section 4.10 has an ch04_15.htm:

: Section 36.6

ch04_15.htm:

The prompt format is up to you. This example makes a two-line prompt (Section 3.7) ch04_15.htm:

This setup starts a while loop (Section 35.15) in the ch04_15.htm:(Section 24.3) of the background shell. Before you log out, ch04_15.htm:you should kill (Section 24.12) the loop. You can type the command: ch04_15.htm:

at a prompt or put it in a file that's executed when you log out (Section 4.18). ch04_16.htm:prompt comes next. (Section 4.15 shows how to ch04_16.htm:use history substitution (Section 30.8) inside the alias or function. ch04_16.htm:article (Section 4.8). The ch04_16.htm:uptime (Section 26.4) every ch04_16.htm:file (Section 3.3) ch04_16.htm:file (Section 3.3): ch04_16.htm:

IFS Section ch04_16.htm:36.23, set Section 35.25, shift ch04_16.htm:$# Section 36.10

ch04_16.htm:

(It was even more useless than psychoanalyze-pinhead (Section 19.13), but it was fun while it lasted.) Seriously ch04_17.htm:.logout (Section 3.3) in your home directory and put the commands ch04_17.htm:your logout-type file, too. Section 3.18 ch04_17.htm:shows a fix for the Bourne and Korn shells; Section 3.8 and Section 3.4 have ch04_17.htm:command sleep 2 (Section 25.9) at the end of the file. That makes the ch04_18.htm:

Section 4.17 ch04_18.htm:

trap Section 35.17, . Section 35.29

ch04_18.htm:

ifSection ch04_18.htm:35.13, [ -f Section 35.26

ch04_19.htm:your Bourne shell exits (Section 4.18). Save your ch04_19.htm:tty (Section 2.7) ch04_19.htm:(Section 35.3), too -- you'll ch04_19.htm:

trap Section 35.17

ch04_19.htm:

exec < Section 36.15, ch04_19.htm:case Section 35.11, ch04_19.htm:exec Section 24.2, ch04_19.htm:-sh Section 3.19

ch04_19.htm:

The last line uses some trickery to start a new login shell (Section 3.19). ch04_19.htm:The shell closes your tty (Section 36.15) before reading your ch05_01.htm:files (Section 3.3). ch05_02.htm:cat (Section 12.2) ch05_02.htm:or who (Section 2.8) that use the terminal screen as a sort of ch05_02.htm:the late 1970s, Bill Joy created the vi (Section 17.2) text editor ch05_02.htm:and emacs (Section 19.1), which ch05_02.htm:(Section 5.3), ul, and ch05_03.htm:file (Section 3.3) -- like ch05_03.htm:variable (Section 35.3): ch05_03.htm:/etc/ttytype (Section 3.15). But if, like many Unix users, you might log ch05_03.htm:set up various tests (Section 3.10) in your shell setup files to do this. ch05_03.htm:

If no arguments (Section 1.4) are specified and TERM ch05_03.htm:the value determined for the terminal type to standard output (Section 43.1). ch05_03.htm:terminal (Section 5.3), but keeps the ch05_03.htm:(Section 28.14) surrounding ch05_03.htm:eval (Section 27.8) ch05_03.htm:also allow you to set the TERMCAP variable (Section 35.5). (You ch05_04.htm:

tset (Section 5.3) ch05_04.htm:

'...' Section 28.14

ch05_04.htm:as ... is sent to standard error (Section 43.1); ch05_04.htm:only the terminal type itself is sent to standard output (Section 43.1). So if you use the following command line: ch05_04.htm:currently using an xterm (Section 24.20) window, but qterm thinks ch05_05.htm:with the shell commands source or . (Section 35.29), or ch05_05.htm:(Section 27.8). For example, after resizing a window, ch05_05.htm:

`...` Section 28.14

ch05_06.htm:

Have another user look at your shell's setup files (Section 3.3). ch05_06.htm:won't see them as you log in. (If you have superuser access (Section 1.18), you also can use it to rename the ch05_06.htm:(Section 27.15) on the stuck account's setup ch05_06.htm:You might use ls -l (Section 50.2) to check. ch05_06.htm:file (Section 22.3) ch05_06.htm:(by NFS) (Section 1.21)? ch05_06.htm:(Section 23.1); if the job is stopped, restart it. ch05_06.htm:or ssh (Section 1.21), the ch05_06.htm:

Enter the command kill PID (Section 24.12), where ch05_06.htm:

The ps (Section 24.5) command, which lists some or all of the ch05_08.htm:xmodmap (Section 5.1) command. Newer shells, like ch05_08.htm:(Section 30.14). Check your shell's ch05_08.htm:stty (Section 5.7) ch05_08.htm:character so the shell won't treat it as a wildcard (Section 1.13): ch05_08.htm:

Section 5.8

ch05_08.htm:

Section 5.8

ch05_08.htm:

Section 5.8

ch05_08.htm:

Section 24.11

ch05_08.htm:

Section 24.11

ch05_08.htm:

Section 23.3

ch05_08.htm:

Section 28.2

ch05_08.htm:everything (Section 41.3) will tell you ch05_08.htm:which. Section 5.7 shows how to change ch05_08.htm:shell prompt (Section 4.1)) and in other places where the terminal is ch05_08.htm:also fools around (Section 5.3) with key settings. Therefore, in your ch05_08.htm:shell setup files (Section 3.3), put stty after ch05_09.htm:

Specifying and using a scrollbar (Section 5.11). ch05_09.htm:

Copying and pasting text selections (Section 5.13). ch05_09.htm:

Modifying text-selection behavior (Section 5.14). ch05_09.htm:titlebar (Section 5.15). ch05_09.htm:

Dynamically changing fonts and other features (Section 5.17, Section 5.18). ch05_09.htm:xmodmap (Section 6.1) lets ch05_10.htm:login shell (Section 3.4), give it the ch05_10.htm:(Section 6.5): ch05_11.htm:resource (Section 6.5) to true: ch05_11.htm:Options menu (Section 5.17) by holding ch05_12.htm:use the scrollbar in xterm (Section 5.11), ch05_14.htm:(Section 5.13) in an xterm, and ch05_14.htm:you've probably discovered that double-clicking Section 5.13 ch05_14.htm:charClass resource variable (Section 6.3). The value this resource accepts is a ch05_15.htm:unobtrusive. I do this by adding a few lines to my shell setup file (Section 3.3). Section 4.8 ch05_16.htm:shell aliases (Section 29.1). Also note that terminals should use ch05_16.htm:variable (Section 6.3): ch05_17.htm:Section 5.18 for information on using the ch05_17.htm:a resource file (Section 6.5). See the xterm manpage for ch05_17.htm:

Note that a Release 5 patch (Section 20.9) has ch05_18.htm:prefer, including the display font. I use the very large 10×20-pixel font (Section 5.16) for all my xterm windows ch05_18.htm:variable (Section 6.3): ch05_18.htm:

The xterm VT Fonts menu (Section 5.17) ch05_18.htm:selection (Section 5.13). However, ch05_18.htm:alias (Section 5.16), but you could use a ch05_19.htm:multiple text selections (Section 5.13) and copy them to other windows. Text you copy ch05_19.htm:selection. You set this up to happen by specifying a few translations (Section 6.4) ch05_19.htm:horizontally, vertically, or both), scrollbars (Section 5.11) will ch05_21.htm:usually a text editor (like vi, with its keymaps for pasting text (Section 18.5)). ch05_21.htm:vi filter-through (Section 17.18): ch05_21.htm:

${1+"$@"} Section 36.7

ch05_21.htm:output is piped to fmt (Section 21.2) to make the lines neat. (Without ch05_21.htm:whitespace, then emails (Section 1.21) the text to ali. ch05_22.htm:other command-line options (Section 5.15)). ch05_22.htm:file (Section 1.21), ch05_22.htm:

tail -f Section 12.10 ch05_22.htm:

Section 24.21 has more about how this works.

ch06_02.htm:(Section 6.1). When you start up ch06_02.htm:-pk (Section 5.1), you should see a line ch06_03.htm:function (Section 29.1), for instance) to ch06_04.htm:control actions of things like mouse clicks. Section 6.3 introduces X resources and shows their syntax. ch06_04.htm:Section 6.5 through Section 6.9 explain how to set and check ch06_05.htm:server by the xrdb (Section 56.8) client, which is normally run from your ch06_05.htm:

Section 6.6 takes a look at the use of the ch06_05.htm:Section 6.7 covers -name. ch06_05.htm:Section 6.8 discusses various ways you can ch06_05.htm:load resources using the xrdb program. Section 6.9 shows how to list the resources for a ch06_06.htm:any specification that you would otherwise put into a resources file (Section 6.5). ch06_10.htm:(Section 1.21), its X ch06_10.htm:are using the wrong rsh command. Use the which ( Section 1.6) or whereis (Section 1.3) command ch06_10.htm:file (Section 3.3) on the remote system. ch06_10.htm:setup file (Section 3.3) on the remote ch06_10.htm:Section 35.8 for more information on setting ch07_01.htm:

When you look at a new computer user's home directory (Section 31.11) ch07_01.htm:we'll show some scripts that use the find (Section 8.3) and ch07_01.htm:grep (Section 9.21) ch07_03.htm:(Section 50.2) for ch07_03.htm:

The SUID bit (Section 50.4) is meaningless for directories, but the ch07_05.htm:created a private directory, you should set its file access mode ( Section 50.2) to 700; this means that ch07_05.htm:(Section 49.9) and read any files he wants. So a private ch08_01.htm:excluding the find (Section 9.1) utility itself because it's ch08_03.htm:Section 8.2.) ch08_03.htm:

In this example, I'll show you my bin (Section 7.4) directory ch08_03.htm:file-time comparisons in a script (Section 8.15). ch08_04.htm:might want to pipe the output to a pager program such as less (Section 12.3). The ch08_06.htm:described later in this section. You may also want to look at Section 8.6.4 for another ch08_06.htm:(Section 12.4) command ch08_06.htm:termcap or terminfo entry (Section 5.2) (which should define the sequences) and the ch08_06.htm:at Section 8.6.4 for another way to configure color ch08_06.htm:dircolors command -- typically in a shell setup file (Section 3.3): ch08_06.htm:

eval Section ch08_06.htm:27.8'...' Section 28.14 ch08_06.htm:type (Section 5.3) names that understand ch08_06.htm:in (Section 3.10).) The second section has ch08_06.htm:users need to make an alias (Section 29.2, Section 29.4) for ch08_07.htm:as its info page (Section 2.9) says, "Because ch08_07.htm:file (Section 19.4) has a name ending in ch08_07.htm:expand it first -- you need to quote (Section 27.12) the ch08_07.htm:sort -n (Section 22.5) and sort on the size field, then strip off ch08_08.htm:option (Section 8.3) to ch08_08.htm:keep it from being interpreted when we set the alias.) head (Section 12.12) shows just ch08_09.htm:entries (Section 10.2). ch08_10.htm:or -A option (Section 8.9) ch08_10.htm:

The file is a symbolic linkSection 10.4). ch08_10.htm:Section 43.11). ch08_10.htm:prints this extra information, but also supports color (Section 8.6) and ch08_11.htm:

-v Section ch08_11.htm:12.4, -t -e Section 1125 ch08_11.htm:default ls -q (Section 8.12) option (on many Unix versions) shows them as ch08_11.htm:

The quotes (Section 27.12) tell the shell to include the space as part ch08_12.htm:Section 14.3 for the rest of the gruesome ch08_12.htm:(Section 12.4) to ch08_13.htm:

I use awk (Section 20.10) a lot. One ch08_13.htm:file (Section 12.6) ch08_13.htm:

xargs Section 28.17

ch08_14.htm:

xargs Section 28.17

ch08_15.htm:

-d Section 8.5

ch08_15.htm:

If your system doesn't have a head ( Section 12.12) command, use sed 1q ch08_15.htm:substitution (Section 28.14) to handle this ch08_16.htm:(Section 10.6). The link and the file itself are ch08_16.htm:automatically), you can use the output of the script in backquotes (Section 28.14). For ch08_17.htm:number (Section 24.3), available in the ch08_17.htm:

Use a + parameter and backquotes (``) (Section 28.14) to get a temp file named for the current date ch09_02.htm:(Section 38.3), du, and ch09_02.htm:diff do this. Some versions of chmod (Section 50.5), ch09_04.htm:can look for particular files by using an expression with wildcards (Section 28.3) as an ch09_04.htm:

Section 9.27 shows a way to match directories ch09_05.htm:

Section 8.2 has more information about these ch09_05.htm:three times, and Section 9.7 explains how ch09_07.htm:with touch Section 9.8). ch09_09.htm:something, like grep (Section 13.2) for a text string. To do this, use the ch09_09.htm:the output of find to xargs (Section 28.17). However, ch09_09.htm:

The C shell (Section 29.1) uses ch09_09.htm:

Section 9.12 and Section 9.27 have more examples of ch09_12.htm:

As we said in Section 9.6, ch09_15.htm:Section 1.17 is good background reading. ch09_18.htm:your own private locate database, or see Section 9.20.) ch09_18.htm:limit searches. Section 9.19 explains this in ch09_19.htm:(Section 1.13) (* , ch09_20.htm:

The script starts from your home directory, then uses sed (Section 13.9) to strip ch09_20.htm:

Set up cron (Section 25.3) or at to ch09_20.htm:to search the database. If you use egrep (Section 13.4), you can ch09_21.htm:

That trick is also good when you use a wildcard (Section 28.3) and ch09_25.htm:

Section 9.27 shows handy aliases that use ch09_27.htm:Section 9.18. ch09_27.htm:expressions in other articles, especially Section 9.6 and Section 9.12. ch10_01.htm:even on different filesystems, that point to the same file. Section 10.3 explores the reasons why you want to do ch10_01.htm:that; Section 10.4 discusses the difference ch10_01.htm:"soft" links; Section 10.5 demonstrates how to create links; and other ch10_01.htm:another. Section 10.12 and Section 10.13 demonstrate two techniques you can use to ch10_03.htm:hard links (Section 10.1) and symbolic links in a number of places, but ch10_03.htm:

.. Section 1.16

ch10_04.htm:(Section 44.9)). You can make a symbolic link to a ch10_04.htm:names that can access it. Section 10.5 shows ch10_04.htm:point to this inode. Section 9.24 shows how ch10_04.htm:optionSection 50.2) and, probably, the ch10_04.htm:-a option Section 8.9) for listing "dot ch10_04.htm:i-numberSection 14.2) for each entry in the directory; see ch10_04.htm:. and .. in pathnames Section 1.16); ch10_04.htm:what's in a directorySection 10.2). The . entry is a link ch10_04.htm:

-d Section 8.5

ch10_05.htm:ln command creates both hard and soft (symbolic) links Section 10.4). If by some strange chance ch10_05.htm:

.. Section 1.16

ch10_05.htm:

. Section 1.16

ch10_05.htm:

You can replace this list of files with a wildcard expression Section 33.2), as in: ch10_05.htm:

Note that symbolic links can get out-of-date Section 10.6). ch10_05.htm:find the linksSection 9.24) to each file. ch10_06.htm:( Section 10.5) have one problem. Like good bread, they ch10_06.htm:relative pathnames Section 1.16) when appropriate. For instance, using ch10_06.htm:Section 10.13) the ch10_06.htm:pathnames Section 31.2). ch10_07.htm:(Section 10.5) (a.k.a. ch10_07.htm:

-F Section 8.3

ch10_09.htm:

-d Section ch10_09.htm:8.5, \(..\)..\1 Section 34.11

ch10_09.htm:them to a shell (Section 3.4). The quotes help make ch10_09.htm:sure that special characters Section 27.17) aren't touched by the ch10_09.htm:versions have the -i options Section 14.15). Using sh ch10_09.htm:-v Section 27.15) ch10_10.htm:

Section 10.9 shows how to rename a set of files, e.g., ch10_10.htm:

&& Section 34.10, $ Section 32.5

ch10_11.htm:script (Section 1.8) that takes a list of filenames (perhaps ch10_12.htm:-r option. But it also has an rcp (Section 1.21) command that does have ch10_12.htm:directory (.) (Section 1.16): ch10_12.htm:

[..]* Section 33.2

ch10_12.htm:brace operators (Section 28.4): ch10_12.htm:

Symbolic and hard links (Section 10.4) are ch10_12.htm:syntax; scp uses SSH (Section 46.6) to do its ch10_13.htm:(Section 39.2) command isn't just ch10_13.htm:if your computer has cp -r (Section 10.12), there are advantages to using ch10_13.htm:different current directory (Section 24.3, ch10_13.htm:Section 24.4) (the place where you want the copy ch10_13.htm:writing-tar in a subshell (Section 43.7), or if ch10_13.htm:directories or files. Just be sure to use relative pathnames (Section 31.2) that don't start with a ch10_13.htm:&& operator (Section 35.14) tells the shell to start tar xvf ch10_13.htm:

Be aware that symbolic links (Section 10.4) will be copied exactly. If they point to ch10_13.htm:(Section 10.6). You can search for these symbolic ch10_13.htm:(Section 1.21) or ssh, you can run either ch11_01.htm:redirect standard output (Section 43.1) to capture this script in a file.) ch11_01.htm:standard input of ed (Section 20.6) or ex; add a w command (Section 20.4) at ch11_01.htm:is used by both RCS and CVS (Section 39.4) to manage multiple revisions of source code ch11_02.htm:files. Here are three sample files, repeated from Section 11.1: ch11_02.htm:notation (Section 11.1), the differences ch11_03.htm:Section 11.1 and Section 11.2 show compact formats with just the differences ch11_03.htm:revisions in an RCS (Section 39.5) file (and will only be available if you have ch11_03.htm:Incidentally, these examples would also work with cvs diff (Section 39.7), if you ch11_03.htm:aren't just nice for reading. The patch (Section 20.9) program ch11_03.htm:diff over the formats in Section 11.1 and Section 11.2 is that ch11_04.htm:compares two files that contain the output of who (Section 2.8) at ch11_04.htm:

Section 11.5 explains a very useful feature ch11_05.htm:might be tempted to tackle with diff3 (Section 11.2) is ch11_05.htm:effective way to do this would be to use sdiff (Section 11.4). (Of ch11_05.htm:place, by using RCS or CVS (Section 39.4).) ch11_06.htm:(Section 11.1) utility adds extra characters ch11_07.htm:(Section 11.1); it tells ch11_07.htm:(Section 35.12) that ch11_08.htm:(and must be sorted (Section 22.1)). For the sake of illustration, assume each ch11_09.htm:

Section 11.8 didn't show one ch11_09.htm:who (Section 2.8) ch11_10.htm:formatting options (Section 45.13) need to ch11_10.htm:(Section 8.2) ch11_10.htm:generated by processing an unformatted file with nroff Section 45.12). ch11_10.htm:

lp Section 45.2

ch11_10.htm:file is more recent. After all the components are made, the lp (Section 45.2) command is ch11_11.htm:NIS (Section 1.21) (formerly called YP, or ch12_01.htm:approach provided by cat (Section 12.2), but there's more to it than ch12_01.htm:

Pagers such as more and less (Section 12.3) that give you more control when looking ch12_01.htm:(Section 12.6). ch12_01.htm:

Looking at just the beginning or end of a file (Section 12.8 through Section 12.12). ch12_01.htm:

Numbering lines (Section 12.13).

ch12_02.htm:they illustrate the shell's output redirection (Section 43.1) mechanism. ch12_02.htm:(Section 12.3).[43] ch12_02.htm:pipe Section 1.5).

ch12_02.htm:Section 12.4, Section 12.7, ch12_02.htm:and Section 12.13 give some more useful tips about ch12_03.htm:less is reading from pipes Section 1.5), it can ch12_03.htm:favorite setup options in the LESS environment variable (Section 35.3). See the less manpage for ch12_03.htm:more, vi (Section 17.2), or emacs ch12_03.htm:(Section 19.1) file-browsing commands. Incidentally, ch12_03.htm:characters (Section 12.4). ch12_04.htm:to follow along on one of those systems, try a compressed file (Section 15.6) ch12_04.htm:visible form without those options. See Section 12.5. ch12_04.htm:(Section 13.15) program finds printable strings of characters ch12_05.htm:option (Section 12.4) shows an ch12_06.htm:2650 is an nroff (Section 45.12) file and ch12_06.htm:0001,v is an RCS (Section 39.5) archive, ch12_07.htm:(Section 2.1) show all the blank lines between ch12_07.htm:( Many versions of less (Section 12.3) and ch12_07.htm:

In vi (Section 18.6) ch12_08.htm:lines, look at Section 12.9. ch12_10.htm:

& Section 23.3

ch12_10.htm:loop, you have to enter CTRL-c (or whatever your interrupt key (Section 24.11) ch12_10.htm:

Section 12.11 shows a useful feature of GNU ch12_11.htm:(Section 12.10) is perfect for me. ch12_11.htm:(Section 25.2) job to rotate log files (rename the files, ch12_11.htm:file descriptor (Section 36.15) number, which it constantly watches for ch12_11.htm:

{ } Section 28.4

ch12_12.htm:

Like tail (Section 12.9), ch12_13.htm:the leading spaces with something like cut (Section 21.14). ch12_13.htm:and footer (Section 45.6) it normally uses ch13_01.htm:Great for searching with regular expressions (Section 13.2). ch13_01.htm:(Section 13.4). ch13_01.htm:interesting ability to search for multiple strings (Section 13.5). ch13_01.htm:agrep is introduced in Section 13.6. ch13_01.htm:Searches through RCS files (Section 39.5) (Section 13.7). ch13_01.htm:several lines (Section 13.9) and other ch13_01.htm:programs (Section 41.12), which show you a few lines before and after ch13_02.htm:

".." Section 27.12

ch13_02.htm:

grep is also often used as a filter (Section 1.5), to ch13_02.htm:( Section 24.5) and ch13_02.htm:option (Section 13.3) reverses the normal ch13_03.htm:thousands of separate files under RCS (Section 39.5), and I ch13_03.htm:version of the find. alias described in Section 9.26, with -user tim ch13_03.htm:using egrep (Section 13.4), which supports the plus ch13_04.htm:egrep command is yet another version of grep (Section 13.2), one that ch13_04.htm:option (Section 13.5). ch13_05.htm:

egrep (Section 13.4) lets you look ch13_05.htm:

(To be more accurate, we used rcsegrep (Section 13.7), since ch13_05.htm:(Section 39.5), but you get the idea.) ch13_06.htm:

outputs all mail messages (Section 1.21) (delimited by a line beginning with ch13_07.htm:RCS (Section 39.5) ch13_07.htm:(Section 13.4), and fgrep on all ch13_07.htm:(rcsgrep uses rcsrevs (Section 39.6) to ch13_07.htm:process: a gawk (Section 20.11) script. Instead of using the RCS ch13_09.htm:across two lines. agrep (Section 13.6) can do multiline searches. One advantage of ch13_09.htm:

It may surprise you to learn that a fairly decent context grep (Section 13.8) ch13_10.htm:using the egrep (Section 13.4) | metacharacter: ch13_10.htm:patterns matching one consecutive string of text. Well, agrep (Section 13.6) is one ch13_10.htm:(Section 27.17) to ch13_11.htm:mechanism (Section 30.2) and ch13_11.htm:understand shell quoting (Section 27.12) and sed regular ch13_11.htm:

[Yes, you can do the exact same thing with multiple grep -v (Section 13.3) commands, ch13_13.htm:following simple awk (Section 20.10) command: ch13_14.htm:problems: it works only on files that have been sorted (Section 22.1). If you ch13_14.htm:word; see Section 16.3. If you ch13_15.htm:cat -v (Section 12.4), you'll see a lot of ch13_15.htm:too. But what the heck? -- pipe the output to a pager (Section 12.3) or ch13_15.htm:grep (Section 13.2), ch13_15.htm:RCS (Section 39.5) -- you can see the version number, the ch13_16.htm:

The less (Section 12.3) pager ch14_02.htm:(Section 9.24, Section 10.3) to a file. But you do care about the ch14_02.htm:

The file's access mode (Section 1.17, Section 50.2)
ch14_02.htm:
The file's timestamps (Section 8.2)
ch14_02.htm:(Section 1.19) as a file ch14_02.htm:ls -l (Section 50.2) ch14_02.htm:-i option (Section 10.4) shows a ch14_03.htm:is removed. If there are no more links (Section 10.3) to the ch14_03.htm:file (i.e., if the file only had one name), its inode (Section 14.2) is added ch14_03.htm:(Section 1.18) to modify it. (A mistake in its own ch14_03.htm:of reasons for making regular backups (Section 38.3).) By ch14_04.htm:

Use rm -i, possibly as an alias (Section 14.8). ch14_04.htm:

Make rm -i less painful (Section 14.7). ch14_04.htm:directory (Section 14.9). ch14_04.htm:

Use revision control (Section 39.4). ch14_04.htm:explained in Section 38.3. ch14_04.htm:unwritable (Section 50.2). ch14_04.htm:-f (Section 14.10). ch14_05.htm:prompts. If a command opens your terminal (/dev/tty (Section 36.15)) ch14_05.htm:won't work. Try expect (Section 28.18) instead. ch14_06.htm:the wildcards (Section 1.13) would be too painful to type with a plain ch14_08.htm:

Using noclobber (Section 43.6) and ch14_08.htm:

./- Section 14.13

ch14_08.htm:inodes (Section 14.2). It might be better to make one ch14_08.htm:-i file in your home directory and hard link (Section 15.4) ch14_08.htm:

~ Section 30.11

ch14_09.htm:via a cron (Section 25.2) entry like ch14_09.htm:

&& Section 35.14, ch14_09.htm:-r Section 14.16 ch14_10.htm:directory access permissions (Section 50.2).) ch14_10.htm:

Normally, rm's exit status (Section 35.12) is 0 if ch14_11.htm:

Deleting files with random control characters in their names (Section 14.12). ch14_11.htm:

Deleting files whose names start with a dash (Section 14.13). ch14_11.htm:filenames (Section 14.14). ch14_11.htm:

Deleting files by using the inode number (Section 14.15). ch14_11.htm:

Deleting directories and problems that can arise as a result (Section 14.16). ch14_11.htm:

Deleting unused (or rarely used) files (Section 14.17). ch14_11.htm:

Deleting all the files in a directory, except for one or two (Section 14.18). ch14_12.htm:several ways (Section 14.11) to handle this problem. One is with wildcards (Section 33.2). Type ch14_12.htm:screen before I could see what the filename was! Section 8.12 explains how, depending on your version of ch14_13.htm:directory" (Section 1.16). So here's how to remove the ch14_14.htm:The ls -q (Section 8.12) ch14_14.htm:* (Section 14.12) skip right over the file. ch14_14.htm:You can see exactly what the filename is by using ls -b (Section 8.12): ch14_14.htm:-c (Section 12.4) to dump the current ch14_14.htm:(dot) (Section 1.16), character by ch14_14.htm:rm -rf (Section 14.16, Section 14.10). Moving files ch14_15.htm:don't work (Section 14.12) ch14_15.htm:(Section 13.2). Then use find's -inum operator (Section 9.9) to remove the file. ch14_15.htm:option (Section 8.12) on most versions) ch14_15.htm:( Section 9.25) for ch14_16.htm:(Section 8.9):[45] ch14_16.htm:.. (Section 8.9), which you can ch14_16.htm:output (Section 8.11) (like a blank line). ch14_17.htm:write find (Section 9.1) commands that will automatically clean these ch14_17.htm:find commands to your crontab file (Section 25.2). ch14_17.htm:command that locates files based on their last access time (-atime (Section 9.5)) and use ch14_17.htm:-ok or -exec (Section 9.9) to delete them. Such a command might look ch14_17.htm:

! Section ch14_17.htm:9.6, -perm Section 9.15 ch14_17.htm:

if Section 35.13, && Section 35.14

ch14_17.htm:

That is, this alias deletes all of my Emacs (Section 19.1) backup ch14_18.htm:wildcard expression (Section 33.2) that does what you want -- but sometimes ch14_18.htm:( Section 28.14) ch14_18.htm:(Section 13.3) command, and then use backquotes to give the ch14_18.htm:Using ls -d (Section 8.5) makes sure that ls ch14_18.htm:

Another solution is the nom (Section 33.8) script. ch14_19.htm:

2>&1 Section 36.16

ch14_19.htm:Section 9.5). Doing it all with one ch15_02.htm:new file will have your default permissions and ownership (Section 50.3). ch15_02.htm:entry (Section 10.2) uses). ch15_02.htm:The find -newer (Section 9.8) command can compare other files to a ch15_02.htm:(Section 43.12), on top of the file: ch15_02.htm:

tail Section 12.8

ch15_03.htm:/dev/null (Section 43.12): ch15_03.htm:crontab (Section 25.2) to truncate and replace the log file. These ch15_03.htm:getting mail (Section 1.21) that you want to throw away? You may be able ch15_04.htm:central copy and put its directory in your search path (Section 27.6). ch15_04.htm:ln. There are lots of advantages to links (Section 10.3). One big ch15_05.htm:file (Section 3.3), but can also be done ch15_05.htm:and cron jobs might not read the shell setup file (Section 3.3) that sets your limit. One way to fix this is ch15_05.htm:

; Section 28.16

ch15_05.htm:

If you've written a daemon (Section 1.10) in C ch15_05.htm:

chmod Section 50.5

ch15_05.htm:

If all else fails, try making a symbolic link to /dev/null (Section 43.12). ch15_06.htm:Section 15.7.) ch15_06.htm:output to the less (Section 12.3) command. When you use ch15_07.htm:(Section 39.2) command can read lots of little files ch15_07.htm:

Okay, then why am I writing this article? Because the gzip (Section 15.6) utility ch15_07.htm:bzip2 (Section 15.6) ch15_07.htm:

.. Section ch15_07.htm:1.16, -r Section 14.16

ch15_07.htm:other hard links (Section 10.4). If a lot of your files have other links, ch15_07.htm:

less Section 12.3

ch15_08.htm:(i.e., NFS (Section 1.21)) filesystems. Under Linux or BSD Unix, the ch15_08.htm:only the superuser (Section 1.18) can use this reserved space, and that usually ch15_08.htm:"the current directory" (Section 1.16)). ch15_09.htm:a quick little command that will compress (Section 15.6) files ch15_09.htm:in the current directory and below. It uses find (Section 9.2) to ch15_09.htm:

-sizeSection ch15_09.htm:9.14, xargs Section 28.17 ch15_09.htm:month or so by at (Section 25.5) or cron ch15_09.htm:(Section 25.2). ch15_10.htm:

-s Section 9.14

ch15_10.htm:ld directly -- say, in a makefile (Section 11.10) -- use the -s option ch15_10.htm:bin directory (Section 7.4) and strips them. It's a ch15_10.htm:

xargs Section 28.17

ch15_10.htm:

The find (Section 9.2) finds all executable files that ch15_10.htm:aren't setuid or setgid and runs file (Section 12.6) to get a ch16_01.htm:redirect the output to a file, use grep (Section 13.1) to locate ch16_01.htm:but realistically, this is too tedious for most users. (The ispell (Section 16.2) program ch16_01.htm:systems, your word-list file must be sorted (Section 22.1). ch16_01.htm:spell works (Section 15.4), you may be less surprised by some of these ch16_01.htm:(Section 16.2). Or you can download and install the ch16_02.htm:

The original Unix spell-checking program, spell (Section 15.1), is fine ch16_02.htm:environment variable (Section 35.3) ch16_02.htm:pathname (Section 1.14), or ch16_03.htm:

If you're using ispell ( Section 16.2) or the newer aspell, you ch16_03.htm:with look (Section 13.14). With just one argument, ch16_04.htm:you have ispell (Section 16.2), there's not a whole lot of ch16_04.htm:and sort -u ( Section 22.6) to remove ch16_04.htm:Section 16.1.) ch16_04.htm:spell, the output is appended through tee (Section 43.8) into ch16_04.htm:you might use the sort and uniq -c (Section 21.20) ch16_04.htm:local spelling dictionary (Section 16.1). Even better, use ispell; ch16_04.htm:update the word lists it uses (Section 16.5). ch16_05.htm:

ispell (Section 16.2) ch16_05.htm:environment variable (Section 35.3).) This file is simply a list of words, one ch16_05.htm:ispell -a (Section 16.3) option. ch16_06.htm:option (Section 8.9) makes ch16_06.htm:ls command is aliased (Section 29.2) to ch16_06.htm:(Section 43.2).

ch16_06.htm:

See the extra spaces? Understanding how the shell handles quoting (Section 27.12) will ch16_06.htm:' (Section 21.11). ch16_06.htm:(Section 15.8) command gives accurate disk usage. ch16_07.htm:tr (Section 21.11): ch16_07.htm:

uniq Section 21.20

ch16_08.htm:editors, such as Emacs (Section 19.1) and vim Section 17.1), also support syntax coloring and ch16_08.htm:

gawk Section 20.11

ch16_09.htm:sometimes need just the words (Section 16.7). ch16_09.htm:designed to strip out troff Section 45.11) constructs and punctuation from files. ch16_09.htm:-u (Section 22.6) if you want only one of ch16_09.htm:tr (Section 21.11), ch16_09.htm:

< Section 43.1

ch16_09.htm:syntax (Section 32.4)? Then, instead of ch16_09.htm:(Section 21.11) has slightly different syntax. ch17_01.htm:(Section 19.1)? That's because ch17_02.htm:without leaving vi: Section 17.3, Section 17.4, and Section 17.6. ch17_02.htm:

Recover deletions from up to nine numbered buffers: Section 17.7. ch17_02.htm:

Do global search and replacement with pattern matching: Section 17.8, Section 17.13, Section 17.14, Section 17.16, and Section 17.22. ch17_02.htm:

Save a lot of typing with word abbreviations: Section 17.23, Section 17.24, and Section 17.25. ch17_02.htm:fit on the screen as you would like: Section 17.28. ch17_02.htm:a filter-through): Section 17.18 and Section 17.21. ch17_02.htm:files in a local directory: Section 17.5. ch17_02.htm:ex in a later chapter: Section 20.3, Section 20.4, and Section 20.5. ch17_03.htm:command sequences that you have defined, and you keep yank buffers (Section 17.4) so ch17_03.htm:(Section 17.21) and when writing out the contents of ch17_04.htm:command (Section 17.3). Thus, by yanking ch17_05.htm:directory (Section 1.15) and unset them ch17_05.htm:( Section 17.23) and key mappings (Section 18.2). ch17_05.htm:ex in an environment variable called EXINIT (Section 17.27). If ch17_05.htm:(Section 10.5) to them ch17_06.htm:nine (Section 17.7) ch17_06.htm:are lost when you change files. See Section 17.4. ch17_08.htm:course) can address lines (Section 20.3) using search ch17_08.htm:patterns (Section 32.1). For example: ch17_09.htm:the previous version of the buffer with :e! (Section 17.3). ch17_11.htm:(Section 20.3) with the write command, ch17_12.htm:

$ Section 20.3

ch17_13.htm:blocks of text delimited by patterns (Section 17.8). For ch17_13.htm:syntax (Section 20.3), but it is not ch17_14.htm:explanations. (Section 32.21 has a list of ch17_14.htm:

% Section 20.3

ch17_14.htm:and \) (Section 34.11) and restored on the ch17_14.htm:

g Section 20.4

ch17_14.htm:first closing quote. As Section 32.18 explains, using ".*" would ch17_14.htm:(;) (Section 28.16) on a Unix ch17_15.htm:file (Section 17.30). ch17_15.htm:/\<very\> (Section 32.12) instead ch17_16.htm:

\(...\)...\1 Section 32.21

ch17_16.htm:try putting it in a keymap (Section 18.2). ch17_17.htm:special character (Section 27.17).) ch17_17.htm:file (Section 17.5). To make the editor ch17_17.htm:read it, map (Section 18.2) a function key like F1 (or any other key ch17_17.htm:

source Section 20.4, ^[Section 18.6 ch17_17.htm:filename (Section 17.3).) ch17_17.htm:links (Section 10.4) between them. That ch17_18.htm:case (Section 17.16), but it's also easy to ch17_18.htm:(Section 21.11) ch17_19.htm:

Figure Section 17.20

ch17_20.htm:file with vi -r (Section 17.19), typing ZZ may not save ch17_20.htm:in my tmp directory. Then I use a shell escape (Section 17.21) to ch17_20.htm:run diff (Section 11.1) and compare the draft file on disk ch17_20.htm:# shortcuts (Section 17.3) are handy here. Oops: diff ch17_20.htm:

less Section 12.3

ch17_20.htm:recovered buffer, as Section 17.4 explains, ch17_21.htm:(Section 23.3), that works on most Unix systems. Job control ch17_21.htm:Give this file to the rcsdiff (Section 11.3) program to see what you've changed since the ch17_21.htm:the file you're editing now (Section 17.3). ch17_21.htm:starts a subshell (Section 24.4); it will not
take you ch17_21.htm:control, you'll almost always want to use job control to suspend vi temporarily instead (Section 23.6). Press CTRL-z, or use the ch17_22.htm:map Section 18.2): ch17_22.htm:

^M Section 18.6

ch17_24.htm:ab (Section 17.23) is ch17_24.htm:with a colon (:)), abbreviations can be better than keymaps (Section 18.2). That's ch17_24.htm:(If your text is confidential and your umask (Section 49.4) isn't set ch17_24.htm:directory.) Here are some abbreviations from my .exrc (Section 17.30) file: ch17_24.htm:by using named buffers (Section 17.4), but temporary files are the only method that ch17_25.htm:

Abbreviations (Section 17.23) ch17_25.htm:

in your .exrc (Section 17.5) file. ch17_25.htm:abbreviation may be recursive (Section 17.23) because the vi is ch17_26.htm:through the program fmt (Section 17.28). ch17_27.htm:(Section 3.7) of a directory on a filesystem with ch17_27.htm:while using vi and then use the :e command (Section 17.3), all ch17_27.htm:(Section 17.5), setting ch17_28.htm:of your lines too short or long? The fmt (Section 21.2) utility ch17_28.htm:

5!! Section 17.18

ch17_28.htm:(Section 17.18) 5 lines through ch17_28.htm:

% Section 20.3

ch17_28.htm:blocks. cut (Section 21.14) can remove columns, fields, or shorten lines; ch17_28.htm:tr (Section 21.11) ch17_28.htm:through with the setup in Section 21.17. In ch17_30.htm:settings to be executed any time you start the vi or ex editors (Section 17.2) in .exrc in your home ch17_30.htm:set, ab (Section 17.23), and map ch17_30.htm:(Section 18.2) commands that you want to have in ch17_30.htm:are RETURNs. Make them by pressing CTRL-v, then RETURN (Section 18.6). Lines that start with a double quote ch17_30.htm:particular project (Section 17.5). ch18_01.htm:

Save time by mapping keys: Section 18.2, ch18_01.htm:Section 18.4, Section 18.7, and Section 18.8. ch18_01.htm:

Know when to map a key and when not to: Section 18.3. ch18_01.htm:

Map keys like ESC and RETURN: Section 18.6.

ch18_01.htm:

Move around the file without leaving text-input mode: Section 18.11 ch18_01.htm:window: Section 18.5. ch18_01.htm:

Put custom commands in your .exrc file: Section 18.9 and Section 18.12. ch18_01.htm:

Break long lines of text: Section 18.13.

ch18_02.htm:lot like ab (Section 17.23) except that you define a macro for command ch18_02.htm:(Section 17.30) or typed in after a colon (:). If you ch18_02.htm:that vi @-functions (Section 18.4) are easier to create and use. The map ch18_02.htm:

^[ Section 18.6

ch18_02.htm:(Section 5.2) defines those keys. For example, to make ch18_02.htm:use. There's more information in Section 18.12 about the noremap option. ch18_02.htm:abbreviations (Section 17.23); the difference is that ch18_02.htm:and then ESC (Section 18.6). After your ch18_02.htm:

Section 18.3 lists some problems with ch18_04.htm:command (Section 18.2) lets you define ch18_04.htm:@z. They're stored in named buffers (Section 17.4). ch18_04.htm:before each ESC or RETURN (Section 18.6). ch18_05.htm:(Section 21.2) utility to reformat and clean up lines ch18_05.htm:

^[ Section ch18_05.htm:back, try a filter-through (Section 17.18) with unexpand. ch18_06.htm:(Section 24.11) and stopping ch18_06.htm:jobs (Section 23.1). ch18_06.htm:an abbreviation (Section 17.23) or a substitution command. For example, the ch18_06.htm:the word Section. The & ch18_06.htm:text-input mode map (map! (Section 18.2)) -- it needs three CTRL-v characters, ch18_06.htm:F1 (Section 18.2) insert the string ch18_07.htm:

Another way to do this is with @-functions (Section 18.4). ch18_07.htm:characters with CTRL-v (Section 18.6). ^[ is the sequence that ch18_07.htm:(Section 17.3 explains % ch18_07.htm:uppercase (Section 17.16). If ch18_08.htm:series (Section 17.3): ch18_08.htm:(Section 18.6) ESC. Finally, you append the closing ch18_08.htm:option (Section 18.12), which is normally ch18_09.htm:map (Section 18.2) ch18_10.htm:(Section 17.5) file: ch18_10.htm:

when you want FORTRAN mode. Of course, you can define a function key (Section 18.2) to :source this. ch18_11.htm:CTRL-h (Section 5.8) outside ch18_11.htm:

The lines for your .exrc file (Section 17.30) are as follows: ch18_12.htm:map (Section 18.2) ch18_12.htm:file (Section 17.5): ch18_13.htm:with a filter-through (Section 17.18) and the fmt ch18_13.htm:(Section 17.28) command: ch18_14.htm:trailing tilde (~) is an Emacs convention. Section 14.17 shows ways to remove these backup ch18_14.htm:

^M Section 18.6

ch18_14.htm:

The first command uses cp -p (Section 10.12) to make a backup of the previously written ch19_01.htm:(I'll give a list of favorite features in Section 19.2.) Emacs' best feature ch19_01.htm:(Section 17.1), but we will point out some of its ch19_02.htm:completions (Section 19.6). So if you're creating a ch19_02.htm:that can be executed automatically. This is similar to vi's map (Section 18.2) facility, with one extra twist: Emacs ch19_03.htm:directory. In Section 19.7, ch19_05.htm:overwrite-mode. You can use command abbreviation (Section 19.6) to shorten this to ESC-x ch19_08.htm:search.el. Just stick this into your directory for Emacs hacks (Section 19.12), and add something like the following to your ch19_09.htm:( Section 1.16), starting ch19_09.htm:shell's PWD environment variable (Section 35.5) has been incorrectly set. There are a few ch19_09.htm:(Section 29.1): ch19_09.htm:

(..) Section 43.7

ch19_12.htm:PATH (Section 35.6) ch20_01.htm:

sed (Section 34.1) is an editor that can ch20_01.htm:differences (Section 34.2) from ch20_01.htm:

awk (Section 20.10) is a great way to pull apart a line of text ch20_01.htm:

patch (Section 20.9) is a specialized editor designed to apply ch20_01.htm:editing scripts created with diff (Section 11.1). You can do this with ed ch20_01.htm:and awk (Section 20.10) lie more complete programming languages like ch20_01.htm:perl (Section 41.1) ch20_01.htm:and python (Section 42.1) that are very adept at manipulating text. ch20_02.htm:control system (Section 39.4) to preserve ch20_04.htm:built by diff (Section 18.6) make heavy ch20_04.htm:

c Section ch20_04.htm:17.9, \U Section 17.14

ch20_04.htm:(Section 43.1) of command. ch20_05.htm:(Section 17.5), which is, at bottom, a list of ch20_05.htm:it with the :so command (Section 20.4). For example, Bruce Barnett uses this trick ch20_05.htm:programs (Section 18.10). ch20_05.htm:(Section 34.1) is ch20_06.htm:editors or the patch (Section 20.9) program. They'll apply your ch20_06.htm:

Figure Section 20.8

ch20_06.htm:

>> Section 43.1

ch20_06.htm:run diff -e (Section 11.1); I save the result in ch20_06.htm:w (Section 27.5) to add the command. ch20_08.htm:

There are no limits on sed (Section 34.1), although you'll need to ch20_08.htm:save its output somehow (Section 34.4), and your editing script may have to be ch20_08.htm:variable $filename (Section 35.9)): ch20_08.htm:

2>&1 Section 36.16, ch20_08.htm:[ ] Section ch20_08.htm:35.26, $? Section 35.12

ch20_09.htm:Wall's widely used programs (including perl (Section 41.1), a ch20_09.htm:(Section 11.1) ch20_09.htm:asking (usually only if the diff file is a context diff (Section 11.3) ch20_09.htm:(Section 39.4) file and check it out, if the filename ch20_10.htm:gawk (Section 18.11), this article tries to ch20_10.htm:the standard input (Section 43.1). ch20_10.htm:expression (Section 32.4). Each record (by ch20_10.htm:described later in Section 20.10.3. ch20_10.htm:described in Section 32.15. In addition, ch20_10.htm:^ and $ (Section 32.5) can be used to refer to the beginning and end ch20_10.htm:

Relational expressions use the relational operators listed in Section 20.10.4 later in this ch20_10.htm:Section 20.10.4 later in ch20_10.htm:status (Section 34.12). ch20_10.htm:(Section 34.12). The status of the command that is ch21_01.htm:

fmt (Section 21.2) ch21_01.htm:and related scripts (Section 21.3) for reformatting jagged lines into neat ch21_01.htm:

recomment (Section 21.4), a script for reformatting comment blocks ch21_01.htm:

behead (Section 21.5), a script for removing the headers from mail ch21_01.htm:

center (Section 21.8), a script for centering lines of text in a ch21_01.htm:

split (Section 21.9) ch21_01.htm:and csplit (Section 21.10) let you split a big file into smaller pieces. ch21_01.htm:

tr (Section 21.11) ch21_01.htm:

dd (Section 21.6, ch21_01.htm:Section 21.13) lets you perform various data ch21_01.htm:

cut (Section 21.14) ch21_01.htm:lets you cut columns or fields out of a file, and paste (Section 21.18) lets you ch21_02.htm:with vi (Section 17.28). (Emacs has ch21_02.htm:options for other structured data. The -p option (Section 21.4) ch21_02.htm:doesn't have -p, the recomment (Section 21.4) ch21_02.htm:(Section 21.3) simple (and a little slower) version ch21_03.htm:

fmt (Section 21.2) is hard to do without once ch21_03.htm:sed (Section 37.4) ch21_04.htm:

The fmt (Section 21.2) program neatens lines of a text file. ch21_04.htm:fmt utility, and uses sed (Section 34.1) to add the ch21_04.htm:vi, with filter-through (Section 17.18) ch21_04.htm:

-n Section ch21_04.htm:34.3, expr Section 36.22, cut Section 21.14

ch21_04.htm:

When the expr command in backquotes (Section 28.14) is ch21_05.htm:

mail Section 1.21

ch21_06.htm:

Why would you want to do this? Section 21.9 ch21_06.htm:writing it to a series of smaller files. Section 21.13 shows even more uses for ch21_08.htm:#! (Section 36.3), ch21_08.htm:shell wrapper (Section 35.19). ch21_08.htm:

In vi, you can use a filter-through (Section 17.18) ch21_09.htm:

wc Section ch21_09.htm:CD-ROM [see http://examples.oreilly.com/upt3]. Alternatively, if you have installed perl (Section 41.1), it is ch21_09.htm:Unix tool you can use to do the splitting is dd (Section 21.6). For ch21_09.htm:

for Section 35.21, > Section 28.12

ch21_10.htm: Like split (Section 21.9), ch21_10.htm:period is a metacharacter (Section 32.21) ch21_10.htm:backslash or to surround the pattern in quotes (Section 27.12). A ch21_10.htm:(Section 32.5) is used to match the beginning of the ch21_10.htm:line and the C shell requires quotes around the braces (Section 28.4). The ch21_11.htm:command is a character translation filter, reading standard input (Section 43.1) ch21_11.htm:

< Section 43.1

ch21_11.htm:

As described in Section 17.18, this translation (and the reverse) can be ch21_11.htm:(Section 27.12)): ch21_11.htm:example, as described in Section 1.8, ch21_11.htm:script (Section 37.7).) ch21_12.htm:eight-bit byte. Usenet (Section 1.21), ch21_12.htm:a compressed file (Section 15.6) ch21_12.htm:

mail Section 1.21

ch21_12.htm:cat > (Section 11.2), create a mail body with ch21_12.htm:headers, so you should strip off the header first. The behead (Section 21.5) script ch21_12.htm:

Extract (Section 39.2) smallfile.tar.gz and ch21_13.htm:of dd (Section 21.6) we've covered, you also can ch21_13.htm:close" (Section 38.5) to ch21_14.htm:(Section 27.12) if you want a space or other special ch21_14.htm:you want, try perl (Section 41.1) or awk ch21_14.htm:(Section 20.10), which let you output fields in any ch21_14.htm:

who Section 2.8

ch21_14.htm:

Extract usernames and real names from /etc/passwd (Section 22.3): ch21_14.htm:

Section 21.18 covers the ch21_15.htm:(Section 45.6) is famous for printing a file neatly ch21_15.htm:compare a directory with its RCS (Section 39.5) ch21_15.htm:

Also see paste (Section 21.18). Of course, programming languages like ch21_15.htm:awk (Section 20.10) ch21_15.htm:and perl (Section 41.1) can also make text into columns. ch21_16.htm:column-making program, besides cols and pr (Section 21.15), is the ch21_16.htm:sed 1d (Section 34.1) to delete the total ch21_16.htm:subshells (Section 24.4) to make both commands use the same standard ch21_16.htm:

; Section 28.16, > Section 28.12

ch21_17.htm:article's title. After a few minutes with wc -l -c (Section 16.6), ch21_17.htm:cut (Section 21.14), ch21_17.htm:sort (Section 22.1), ch21_17.htm:and join (Section 21.19), I had a file that looked like this: ch21_17.htm:The column (Section 21.16) command could do it automatically, but I ch21_17.htm:awk (Section 20.10) ch21_18.htm:handy when used with cut (Section 21.14). You can cut data from one position on a line ch21_18.htm:

Use quoting (Section 27.12), if necessary, to protect characters from the ch21_19.htm:(Section 16.6) to count the number of ch21_19.htm:number; I used sort (Section 22.1) to sort the files on that field. I used ch21_20.htm:

uniq is often used as a filter. See also comm (Section 11.8), sort (Section 22.1), and ch21_20.htm:especially sort -u (Section 22.6). ch21_20.htm:

grep Section 13.1

ch21_21.htm:-r (Section 42.1): ch22_01.htm:

Section 22.2 describes how to select ch22_01.htm:

Section 22.3 describes how to change the ch22_01.htm:

Section 22.4 describes the kinds of problems ch22_01.htm:

Section 22.5 clarifies the distinctions ch22_01.htm:

Section 22.6 gives miscellaneous hints about ch22_01.htm:

Sort lines by how long they are (Section 22.7). ch22_01.htm:there's a middle name as well (Section 22.8). ch22_03.htm:

Section 22.2 ch22_03.htm:

/etc..wd Section 1.7

ch22_04.htm:delimiter (Section 22.3). This makes it ch22_04.htm:-v (Section 12.5, Section 12.4) shows that the file really looks like this: ch22_06.htm:powerful than uniq (Section 21.20) because: ch22_06.htm:lines "unique" if the sort fields (Section 22.2) ch22_06.htm:printf statements, write some Emacs (Section 19.1) macros to ch22_06.htm:

head Section 12.12

ch22_07.htm:

deroff Section 16.9, uniq Section 21.20

ch22_07.htm:

find Section 9.1

ch22_07.htm:(Section 20.10) to print ch22_07.htm:Next, sort sorts the lengths numerically (Section 22.5). ch22_07.htm:Then sed (Section 34.1) strips off the lengths and the spaces and ch22_08.htm:see Section 41.11. ch23_01.htm:
command & (Section 23.3)
ch23_01.htm:
CTRL-c (Section 24.11)
ch23_01.htm:Kill the current foreground job by sending the INTR signal (Section 24.10). ch23_01.htm:
CTRL-z (Section 23.3, Section 23.6)
ch23_01.htm:Suspend the current foreground job by sending the TSTP signal (Section 24.10). ch23_01.htm:(Section 23.7). ch23_01.htm:
bg %num (Section 23.3)
ch23_01.htm:
fg %num (Section 23.3)
ch23_01.htm:
kill %num (Section 23.3)
ch23_01.htm:
kill pid (Section 24.12)
ch23_01.htm:
jobs (Section 23.3)
ch23_01.htm:
set notify (Section 23.8)
ch23_01.htm:
stty tostop (Section 23.9)
ch23_01.htm:processes by name. See Section 24.15, which introduces killall. ch23_02.htm:control (Section 23.3), however, most ch23_02.htm:the fly with a suspend signal (Section 24.1) by typing CTRL-z. Then use ch23_02.htm:job ( Section 23.5) into the ch23_04.htm:separated by semicolons (Section 28.16) into the background. These shells put only ch23_04.htm:back until the sleep (Section 25.9) command has finished. ch23_04.htm:

( ) Section 43.7

ch23_04.htm:stopped (Section 23.1) in the background. ch23_04.htm:

Stopping vi (Section 23.6) is more efficient than using its shell escape mechanism (Section 17.21), since it lets you go back to your original ch23_04.htm:use the nohup (Section 23.10) command. ch23_04.htm:( Section 26.5). This is ch23_06.htm:man (Section 2.1) ch23_06.htm:or info (Section 2.9) command when you're in the ch23_06.htm:(Section 23.1), that solves all these problems. (If ch23_06.htm:it doesn't, you can still use a shell escape (Section 17.21).) ch23_06.htm:my .exrc file (Section 17.5) instead. ch23_07.htm:(Section 24.12) some processes, but you'll ch23_07.htm:renice ( Section 26.7) the ch23_07.htm:speeds up, unless you're the superuser (Section 1.18). ch23_07.htm:ps (Section 24.5) or ch23_07.htm:time (Section 26.2) ch23_07.htm:CTRL-z (Section 23.3) to stop it. If the job is running in the ch23_07.htm:can use kill (Section 24.12) with the -STOP signal and ch23_07.htm:file (Section 3.3). Later, when the ch23_08.htm:tostop (Section 23.9). ch23_09.htm:(Section 43.1) its output, text that the job writes ch23_09.htm:(Section 3.3).

ch23_09.htm:stopped. To make it do that, set notify (Section 23.8). ch23_10.htm:down all its child processes (Section 24.3) with it. ch23_10.htm:( Section 24.10), though ch23_10.htm:trap (Section 35.17) ch23_11.htm:shell sends my background job a HUP signal. I could use nohup (Section 23.10) to block ch23_11.htm:control on, so the jobs are just cluttering the jobs (Section 23.3) list. ch23_11.htm:start the job in a subshell (Section 43.7), and put the job inside that subshell into ch23_11.htm:list, but ps (Section 24.5) should ch23_11.htm:process (Section 24.3)) is 1; this means ch23_11.htm:init (Section 24.2). ch23_12.htm:consoles, a series of ttys (Section 2.7) that you ch23_12.htm:ttys, with getty (Section 24.2) processes ch23_12.htm:

cat > Section 12.2

ch24_01.htm:(Section 24.5, Section 24.6, ch24_01.htm:Section 24.8). ch24_01.htm:

What are signals (Section 24.10)?

ch24_01.htm:

How to send signals from the keyboard (Section 24.11 and Section 24.12; also see ch24_01.htm:Section 5.8). ch24_01.htm:signals (Section 24.13 and Section 35.17). ch24_01.htm:

How to kill all your processes (Section 24.14).

ch24_01.htm:

How to kill processes by name rather than by process ID (Section 24.16). ch24_01.htm:

How to stop runaway jobs (Section 24.17).

ch24_01.htm:kill them (Section 24.18, Section 24.19). ch24_01.htm:

How to get rid of a frozen window (Section 24.22). ch24_01.htm:(Section 23.10). ch24_02.htm:Section 27.2, but the concept comes up so ch24_02.htm:(non-network (Section 1.21) logins) works. The init ch24_02.htm:built into the shell (Section 1.9). ch24_02.htm:environment (Section 24.3), some commands ch24_02.htm:prompt; see Section 36.5. Watch out, though: ch24_03.htm:shell (Section 27.1). The shell you use may be a variant of the ch24_03.htm:process is allowed to read from or write to (Section 50.1), as well as who is allowed to kill the process (Section 24.12) (tell it to stop running). ch24_03.htm:Section 50.2. ch24_03.htm:directory (Section 1.15), it has told you ch24_03.htm:variable (Section 35.3) called ch24_03.htm:working directory (Section 31.3) is the ch24_03.htm:pathname (Section 31.2), the program will look in the current working ch24_03.htm:the current directory (Section 35.6 ch24_03.htm:

Versions of Unix with job control (Section 23.1) ch24_03.htm:(Section 24.10, Section 24.11, Section 24.14). It's also used to control ch24_03.htm:the process that gets the input you type. See Section 24.6. ch24_03.htm:process ID, since the child is assigned a new one. Built-in shell commands (Section 1.9) such as cd ch24_03.htm:window system such as X (Section 1.22) and want to start up a new ch24_03.htm:(Section 23.1) features (processes that are running in the ch24_03.htm:vice versa) after that point. For example, if you start up the editor vi, suspend it (Section 24.6), and then use the cd ch24_03.htm:needed (Section 24.10, Section 35.29). ch24_03.htm:exit status (Section 35.12) to its parent process. By convention, a ch24_03.htm:manipulate file descriptors (Section 36.16). ch24_04.htm:process starts another process), the new process runs as a subprocess (Section 24.3) or ch24_04.htm:without a fork first. Section 24.2 explains.

[71]When you use the ch24_04.htm:shell's exec (Section 35.5) command, it does not start a ch24_04.htm:are run in a subshell (unless you use the source or . commands (Section 35.29) to start the script). If the script makes ch24_04.htm:home directory, reset some aliases, use a different PATH (Section 35.6), whatever. ch24_04.htm:

If your parent shell has job control (Section 23.3), ch24_04.htm:(or kill -STOP $$ (Section 27.17)) will stop it. Otherwise, just type CTRL-z at ch24_04.htm:

prompt Section 4.1

ch24_04.htm:escape (Section 17.21) starts a subshell. ch24_04.htm:(usually CTRL-d) will do the same thing. Section 35.16 explains how exit sets a ch24_05.htm:terminal (Section 24.6). ch24_05.htm:output to head (Section 12.12), which will display the most active ch24_05.htm:(f77). This process has PID (Section 24.3) 12923 and ch24_05.htm:

User ID (Section 24.3) of process owner ch24_05.htm:

T: Stopped (Section 23.1) ch24_05.htm:

Z: Zombie process (Section 24.19) ch24_05.htm:

N (BSD): Niced (Section 26.5, Section 26.7), execution ch24_05.htm:raised (Section 26.7) ch24_05.htm:

Process nice number (Section 26.5) ch24_06.htm:

In Section 24.5, we pointed out that the ps ch24_06.htm:(Section 1.21) look to the operating system just like ch24_06.htm:(Section 1.10) never had one -- they were started ch24_06.htm:processes (Section 23.11) fit this category ch24_07.htm:help you track down and kill (Section 24.12) a runaway process. If it's ch24_07.htm:orphans (Section 24.19). If you have a serious runaway process ch24_07.htm:(Section 1.10) that handle system services like mail, ch24_07.htm:man (Section 2.1) ch24_07.htm:or info (Section 2.9) on the process name. ch24_07.htm:

Section 24.22 shows a similar thing: how to ch24_08.htm:exec (Section 24.2) ch24_09.htm:(Section 1.19). On many modern Unix systems, even ch24_09.htm:(Section 24.3). Some versions of ch24_09.htm:

-F Section 8.10

ch24_09.htm:you want an alias (Section 29.2) that simply shows how much memory is free, ch24_09.htm:

grep Section 13.1

ch24_09.htm:niced user mode (Section 26.5), system (kernel) mode, and the idle task, ch24_09.htm:the CPU ststistics, then the start of an awk (Section 20.10) script that ch24_09.htm:

!! Section 30.8

ch24_09.htm:"directory" is actually a symbolic link (Section 10.4) ch24_09.htm:(Section 36.15) are currently pointing to. This ch24_09.htm:(disk file, tty (Section 2.7), pipe, etc.) but the actual full pathname of ch24_09.htm:(Section 43.12) and lists again. ch24_09.htm:for the process PID (Section 24.3). Here are a series of examples of the useful ch24_09.htm:(Section 35.3) to ch24_09.htm:(Section 21.11) command translates the NUL-separated ch24_09.htm:you'd like to know what the EXINIT (Section 17.27) ch24_09.htm:in ps (Section 24.5) ch24_09.htm:process 918 has, or what process started it (its parent PID (Section 24.3)): ch24_09.htm:Let's see...using echo (Section 27.5) to add a ch24_09.htm:

; Section 28.16

ch24_10.htm:kernel (Section 1.10) ch24_10.htm:systems (these can be changed; see Section 5.8). ch24_10.htm:foreground). Sent when you type CTRL-z. stty (Section 5.8) calls this ch24_10.htm:

It can trap (Section 35.17) the signal ch24_10.htm:

The kill (Section 24.12) command doesn't ch24_11.htm:(Section 24.10) will ch24_11.htm:(interrupt) signal (Section 24.10) to the ch24_11.htm:Emacs almost always ignore most signals. The trap ( Section 35.17) command handles signals in the Bourne shell. ch24_11.htm:group (Section 24.3). This ch24_11.htm:

Section 5.8 explains how to set the key that ch24_11.htm:sends these and other signals. The kill (Section 24.12) command ch24_12.htm:signal a process (Section 24.13); this is the purpose of the ch24_12.htm:

Zombies. A process in the zombie state (Section 24.19) is ch24_12.htm:displayed as Z status in BSD ps (Section 24.5) displays ch24_12.htm:

Processes waiting for unavailable NFS (Section 1.21) resources ch24_12.htm:(Section 1.18) to kill someone else's ch24_12.htm:

If you're using the X Window System, Section 24.20 shows how to find which window has the ch24_13.htm:(Section 35.17) command to catch several different signals ch24_13.htm:runs lpq (Section 45.2) on all ch24_13.htm:user with the write (Section 1.21) command. (You could change it to write to the ch24_13.htm:use xmessage (Section 36.26) to pop a notice window onto ch24_13.htm:(Section 43.1, Section 36.16) away ch24_13.htm:and shells that kill background jobs when you log out, use nohup (Section 23.10).

ch24_13.htm:

/dev/null Section 43.12

ch24_13.htm:

kill Section 24.12

ch24_13.htm:controlling tty (Section 24.6). Also, the error messages that egrep (Section 13.4) searches ch24_14.htm:

On many Unix systems, kill (Section 24.12) interprets ch24_14.htm:

To see if your system supports this feature, type man 2 kill (Section 2.1) to ch24_14.htm:through ps (Section 24.5) to find the right process. The zap (Section 24.16) script ch24_14.htm:control (Section 23.3). ch24_15.htm:version of killall (Section 24.16) that doesn't seem to have as ch24_15.htm:Section 24.12) or by process names. To an old ch24_15.htm:

& Section 23.2

ch24_15.htm:version of ps (Section 24.5). It shows me what the default ch24_15.htm:executable's directory from the PATH (Section 35.6) prepended, ch24_15.htm:(Section 27.3). So (whew): to kill these shell ch24_15.htm:a process by name is that a process can start a subprocess (Section 24.3) with ch24_15.htm:a different name. For instance, if your make (Section 11.10) job starts ch24_15.htm:haven't been disowned (Section 23.11), for ch24_15.htm:can just write an alias (Section 29.2) to override your shell's ch24_15.htm:control (Section 23.1) numbers like ch24_15.htm:number -- or use a script like zap (Section 24.16) instead. ch24_16.htm:it's a pain in the neck to run ps (Section 24.5), figure out ch24_16.htm:the process ID, and then kill the process -- although sometimes you have to do it that way (Section 24.15). We'll look at two easier ch24_16.htm:says: kills all processes on the system (when run as the superuser (Section 1.18)). ch24_16.htm:

& Section 23.2, [5] Section 23.3

ch24_16.htm:(Section 13.4) to pick the processes to kill; ch24_16.htm:you can type extended expressions (Section 32.15) that match more than one process. The ch24_16.htm:

'...' Section 36.24

ch24_16.htm:processes. Your version of ps may need different options (Section 24.5). ch24_16.htm:awk (Section 20.10) ch24_16.htm:pick. The inner set of nested (Section 36.24) ch24_16.htm:backquotes (Section 28.14) in zap pass ch24_16.htm:(Section 36.23) to just a newline, ch24_16.htm:backquotes passes kill (Section 24.12) the output of pick, ch24_16.htm:

/dev/tty Section 36.15

ch24_17.htm:processes forking (Section 24.2) out of ch24_17.htm:(Section 23.3), there's a good answer: use ch24_17.htm:

kill Section 24.12

ch24_17.htm:into the shell (Section 1.9) (like ch24_17.htm:killall (Section 24.16), which would be nice to use in this ch24_17.htm:built-in wildcard matching (Section 1.13) to show you the shell's ch24_17.htm:

exec Section 36.5

ch24_18.htm:process that (according to ps (Section 24.5)) has been sleeping for several days, waiting ch24_18.htm:for input. If you can't kill (Section 23.12) the ch24_19.htm:open file descriptors (Section 24.3) and shutting down other resources (memory, ch24_19.htm:hold on to its name and exit status (Section 35.12). ch24_19.htm:fork (Section 24.2); ch24_19.htm:(the PID of init (Section 24.2)). While the original parent is around, it can ch24_19.htm:single byte of status (Section 35.12) from each child. The ch24_20.htm:System (Section 1.22). Actually, a lot of ch24_20.htm:"first window." Find its tty (Section 2.7). Next, in ch24_20.htm:variable (Section 35.3) with a unique name ch24_20.htm:previous xterm's. Run env or printenv (Section 35.3), and you should see the special environment ch24_20.htm:directory (Section 3.7), you may have ch24_20.htm:steps, you've started a chain of processes (Section 24.3). ch24_20.htm:-ef (Section 24.5). You should get lines ch24_20.htm:tty (Section 2.7) ch24_20.htm:init (Section 24.2), ch24_20.htm:(Section 24.12) a hung window or a process in a window. ch24_20.htm:xterm gets a signal (Section 24.10), and the ch24_20.htm:you had started the second xterm in the background (Section 23.2), you ch24_21.htm:Section 24.20, when the process exits, the ch24_21.htm:window, use the -e option (Section 5.22), followed by the command line to run the ch24_21.htm:with a scrollbar. Start by choosing a file and using wc -l (Section 16.6) to count ch24_21.htm:

cat Section 12.2

ch24_21.htm:read command (Section 35.18) to pause until you give a dummy ch24_21.htm:interprets it. The three commands are separated by semicolons (;) (Section 28.16). ch24_21.htm:the sh -c '...' to run a little shell script (Section 35.1) ch24_22.htm:rid of it, the easier way is usually to kill (Section 24.12) the ch24_22.htm:process. As Section 24.20 explains, there may ch24_22.htm:(Section 24.5) to track down the process(es) behind ch24_22.htm:set user ID (Section 1.17) -- you can use run ps ch24_22.htm:of process IDs, parent-to-child, in that window. The tty (Section 2.7) of the ch24_22.htm:is still alive by trying to open its menus (Section 5.17). If a ch24_22.htm:

-9 Section 23.3

ch24_22.htm:console (Section 23.12)). So the processes ch24_22.htm:owned by the init (Section 24.2) process (PID 1), these ch24_22.htm:were either disowned (Section 23.11) by Mozilla, or somehow the top-level ch24_22.htm:zombie process (Section 24.19) that can't be killed, but it ch24_22.htm:accesses and the zombie is tying up the hardware. Section 24.18 has some ways to clean up in that case. ch24_22.htm:(Section 10.4), or names: ch24_22.htm:

$! Section 27.17, '...' Section 28.14

ch24_22.htm:xmessage in the background (that is, disowned (Section 23.11)) and ch25_01.htm: cron (Section 25.2) system ch25_01.htm:at (Section 25.5) command is ideally suited. ch25_01.htm:(Section 25.9) command is available. ch25_02.htm:(Section 43.1), ch25_02.htm:path (Section 27.6) is usually shorter; ch25_02.htm:( Section 1.10). What to ch25_02.htm:a relative pathname (Section 31.2), it will probably be in your home directory. ch25_02.htm:

/proc Section 24.9, ch25_02.htm:2>&1 Section 36.16, \% Section 25.4

ch25_02.htm:runs the commands together in a subshell (Section 43.7).) The ch25_02.htm:wear and tear and load on your disk, try to combine find jobs (Section 14.19). Also, as Section 25.8 explains, try not to ch25_02.htm:discarding it to /dev/null (Section 43.12). If no output redirection is performed, the ch25_02.htm:shown in the seventh entry. He uses the test (Section 35.26) and ch25_02.htm:operator (Section 35.14) runs the ch25_03.htm:see Section 25.6. ch25_06.htm:at output into the Unix trash can, /dev/null (Section 43.12): ch25_06.htm:

>& Section 43.5

ch25_06.htm:

exec > Section 36.5

ch25_07.htm:Section 25.8. The jobs are ordered according ch25_07.htm:emptying the file (Section 15.2). Or the superuser (Section 1.18) can ch25_08.htm:at -l (Section 24.7) ch25_08.htm:(Section 25.2), you won't be able to ch25_09.htm:

( ) & Section 43.7, ; Section 28.16

ch25_09.htm:(Section 25.5), and you have to run a job later (say, ch25_09.htm:

!! Section 30.8

ch25_09.htm:mail (Section 1.21) ch25_09.htm:

foreach Section 28.9

ch26_01.htm:(Section 26.4) to see how many processes were recently ch26_01.htm:(Section 26.2) command exists as part of both C and ch26_03.htm:The emacs process on the tty (Section 2.7) ttyp1 ch26_03.htm:stopped (Section 23.3) to run ch26_03.htm:

tee Section 43.8

ch26_03.htm:(Section 37.7) and then run ch26_03.htm:shell (Section 1.9). Those commands are ch26_04.htm:priorities and niceness (Section 26.5) of the processes that are running. ch26_04.htm:CPU-bound background job at the same time as the X Window System (Section 1.22) ch26_05.htm:(Section 26.1) process that will monopolize the CPU from ch26_05.htm:renice(8) command (Section 26.7); this ch26_05.htm:like a text editor. See Section 26.6. ch26_05.htm:lower priority) for their jobs. Only the superuser (Section 1.18) can ch26_05.htm:version in any situation: within makefiles (Section 11.10), when ch26_06.htm:foreground job (Section 23.3). If the system gets busy, your terminal could ch26_06.htm:time to do something. You may not even be able to kill (Section 24.11) a ch26_07.htm:nice level (Section 26.5) for the job. It ch26_07.htm:is the ID number (Section 24.3) (as shown by ps (Section 24.5)) of the ch26_07.htm:(Section 24.3), as shown by ps -l; this ch27_01.htm:shell has to break the command into words and expand aliases (Section 29.2), ch27_01.htm:history operators (Section 30.8), and shell and ch27_01.htm:environment variables (Section 35.3, Section 35.9). It also sets up ch27_01.htm:standard input and output streams (Section 43.1) and performs a lot of other tasks. Indeed, if ch27_02.htm:external command (Section 1.9), what happens? ch27_02.htm:some Unix manuals. Section 24.2 has more ch27_03.htm:cat -v afile bfile > cfile), interprets it (Section 27.1), ch27_03.htm:command is in the background (Section 23.2)), the shell is ready to read another command ch27_03.htm:script (Section 35.1) or shell program. ch27_03.htm:you type from a terminal (though the shell uses its non-interactive mode (Section 3.4), which means, basically, that it ch27_03.htm:bash (Section 1.6), ch27_03.htm:

As Section 26.6 explains, if the shell is trying to run a ch27_03.htm:Section 7.4. ch27_03.htm:

Newer Bourne shells have features -- such as shell functions (Section 29.11), an unset command for ch27_03.htm:yourself (Section 4.1). If your account ch27_03.htm:default. This is normally done using the special #! notation (Section 36.2) in the first line of the script. ch27_05.htm:named showargs; you might want to save it in a file and run it yourself (Section 35.1). The script shows how many arguments were ch27_05.htm:later, its built-in echo (Section 27.5) command has the -E option to ch27_05.htm:

cat Section 12.2, ch27_05.htm:&& Section 35.14, ch27_05.htm:$# Section 35.20, path Section 35.7

ch27_06.htm: Your search path (Section 35.6, ch27_06.htm:Section 35.7) controls what directories -- and in ch27_06.htm:what order -- the shell searches for external (Section 1.9) ch27_06.htm:file (Section 3.3). You might also want ch27_06.htm:(Section 3.3). ch27_06.htm:simply to add the new directory's absolute path (Section 31.2) to the end of the existing ch27_06.htm:

Searching the path (Section 27.6) takes ch27_07.htm:

wc Section 16.6

ch27_08.htm:you read the previous article (Section 27.7), you saw that, most of the time, the shell ch27_08.htm:program (Section 1.8): ch27_08.htm:in Section 5.3 and others. ch27_09.htm:shell function (Section 29.11), a built-in ch27_09.htm:command ( Section 1.9), or an ch27_09.htm:external command (Section 1.9). ch27_09.htm:PATH (Section 35.6)) ch27_10.htm:

[Section 27.9 shows ch27_11.htm:( Section 43.1) to a file: ch27_11.htm:

Section 36.16 has much more about the ch27_12.htm:is slightly more complicated. See Section 27.13.) ch27_12.htm:substitution (Section 28.14). ch27_12.htm:substitution (Section 30.8). ch27_12.htm:! (Section 27.13) except that, in ch27_12.htm:(Don't use C shell; it's different (Section 27.13).) If you need to start a Bourne-type shell, ch27_12.htm:\* is a literal asterisk, not a filename wildcard (Section 1.13). So, the first expr (Section 36.21) command ch27_12.htm:those two examples using echo (Section 27.5) instead of expr.) ch27_12.htm:comment character (Section 35.1). That means the shell will ignore the rest of ch27_12.htm:substitution (Section 35.9, Section 35.3) and command ch27_12.htm:substitution (Section 28.14) inside ch27_12.htm:was expanded into the shell's process ID number (Section 24.3) (in this shell, 18437). ch27_12.htm:(Section 35.9) with a multiline message, the kind that might ch27_12.htm:Bourne shell prints secondary prompts (Section 28.12) (>) until all quotes ch27_13.htm:haven't read Section 27.12 ch27_13.htm:substitution (Section 30.8) inside quotes. ch27_13.htm:

Section 29.10 shows an amazing pair of aliases ch27_14.htm:

/dev/null Section 43.12

ch27_14.htm:determine the end of each argument. Quoting (Section 27.12, Section 27.13) changes that -- for example, the ch27_15.htm:

set Section 35.9

ch27_15.htm:

If you wish to turn the options off, use unset (Section 35.9) instead ch27_16.htm:

This is very useful because variables (Section 35.9, ch27_16.htm:Section 35.3) are evaluated during this operation. ch27_16.htm:anonymous ftp (Section 1.21)[84] from a shell script: ch27_16.htm:substitutions (Section 28.14) are done. If ch27_16.htm:Section 36.19. ch27_17.htm:expressions (Section 32.1), you should ch27_17.htm:understand how quoting (Section 27.12) works in Unix. ch27_17.htm:expression (Section 32.2). If you need a ch27_17.htm:!$, and so on; see Section 30.8 instead. ch27_17.htm:

Section 28.6

ch27_17.htm:

Section 28.6

ch27_17.htm:

Section 35.1

ch27_17.htm:

Section 28.14

ch27_17.htm:

Section 27.12

ch27_17.htm:

Section 27.13

ch27_17.htm:

Section 35.3, Section 35.9

ch27_17.htm:

Section 35.9

ch27_17.htm:

Section 28.5

ch27_17.htm:

Section 36.7

ch27_17.htm:

Section 36.7

ch27_17.htm:

Section 36.7

ch27_17.htm:

Section 36.7

ch27_17.htm:

Section 36.7

ch27_17.htm:

Section 36.7

ch27_17.htm:

Section 36.7

ch27_17.htm:

Section 36.7

ch27_17.htm:

Section 35.9

ch27_17.htm:

Section 35.9

ch27_17.htm:

Section 35.9

ch27_17.htm:

Section 1.5, Section 43.1

ch27_17.htm:

Section 43.5

ch27_17.htm:

Section 24.4

ch27_17.htm:

Section 30.5

ch27_17.htm:

Section 23.2

ch27_17.htm:

Section 23.11

ch27_17.htm:

Section 23.11

ch27_17.htm:

Section 1.13, Section 33.2

ch27_17.htm:

Section 1.13, Section 33.2

ch27_17.htm:

Section 35.10

ch27_17.htm:

Section 31.11

ch27_17.htm:

Section 31.11

ch27_17.htm:

Section 30.2

ch27_17.htm:

Section 35.12

ch27_17.htm:

Section 3.19

ch27_17.htm:

Section 35.9,

ch27_17.htm:

Section 35.20,

ch27_17.htm:

Section 35.20

ch27_17.htm:

Section 35.20

ch27_17.htm:

Section 35.12

ch27_17.htm:

Section 27.12

ch27_17.htm:

Section 4.15

ch27_17.htm:

Section 28.9

ch27_17.htm:

Section 35.14

ch27_17.htm:

Section 35.14

ch27_17.htm:

Section 36.24, Section 28.14

ch27_17.htm:

Section 35.29

ch27_17.htm:

Section 35.6

ch27_17.htm:

Section 31.5, Section 35.6

ch27_17.htm:

Section 28.5

ch27_17.htm:

Section 1.13, Section 33.2

ch27_17.htm:

Section 35.26

ch27_17.htm:

Section 23.3

ch27_17.htm:

Section 43.7

ch27_17.htm:

Section 28.4

ch27_17.htm:

Section 43.1

ch27_17.htm:

Section 43.6

ch27_17.htm:

Section 43.6

ch27_17.htm:

Section 43.1

ch27_17.htm:

Section 43.6

ch27_17.htm:

Section 43.1

ch27_17.htm:

Section 27.16, Section 28.13

ch27_17.htm:

Section 27.16

ch27_17.htm:

Section 27.16

ch27_17.htm:

Section 43.5

ch27_17.htm:

Section 36.16

ch27_17.htm:

Section 36.16

ch27_17.htm:

Section 36.16

ch27_17.htm:

Section 36.16

ch27_17.htm:

Section 36.16

ch27_17.htm:

Section 36.16

ch27_18.htm:

In the first case, the shell uses the backslash to quote (Section 27.12) the ch27_18.htm:quote (Section 27.12) ch28_01.htm:onceSection 28.8). ch28_01.htm:(Section 28.6, Section 28.7), which allows you to type the beginning of a ch28_01.htm:(Section 28.14), which lets you use the output from one ch28_01.htm:methods (Section 28.10, Section 28.11). ch28_01.htm:long (Section 28.17). ch28_01.htm:

Job control (Section 23.3), which lets you run several commands at the ch28_01.htm:

Aliases (Section 29.2), or abbreviations, for commands. Shell functions (Section 29.11) ch28_01.htm:

Command-line editing (Section 30.14) and history ch28_01.htm:substitution (Section 30.8). These are two ch28_01.htm:

Quoting (Section 27.12, Section 27.13), the way you ch28_01.htm:

Wildcards (Section 33.2). ch28_02.htm:interrupts you with write (Section 1.21) to say it's time for lunch. ch28_03.htm:editor or the touch (Section 14.8) command: ch28_03.htm:

Stumped? Take a look at Section 1.13 about ch28_03.htm:(Section 14.8) or touch ch28_03.htm:

Section 28.4 explains shell { ch28_03.htm:simply quote (Section 27.12) its name to remove it: ch28_04.htm:to *, ?, and [ ] (Section 33.2), but they don't match ch28_04.htm:echo (Section 27.5) ch28_04.htm:

That would give lpr (Section 45.2) all of these files: ch28_04.htm:vi /usr/foo/file[a-j] would not work (Section 28.3). ch28_04.htm:

foreach Section 28.9

ch28_04.htm:

To send a mail (Section 1.21) message to ch28_04.htm:scp (Section 29.14): ch28_04.htm:

. Section 1.16

ch28_04.htm:your lpr (Section 45.2) command ch28_05.htm:zsh, and bash do history substitutions (Section 30.8) they can also edit the substitution. The C ch28_05.htm:(Section 35.9). ch28_05.htm:pathname (Section 31.2), as follows: ch28_05.htm:used with C shell variables (Section 35.9) as: ch28_05.htm:

This is the C shell's answer to the basename (Section 36.13) ch28_05.htm:command but does not execute it (Section 30.11): ch28_06.htm:variable filec (Section 30.9) or complete, then press ch28_06.htm:This works with pathnames (Section 1.16) too: each time you press TAB, the shell ch28_06.htm:(Section 1.12) named alpha.o. ch28_06.htm:.o files. Section 28.7 ch28_06.htm:problem in most cases. Section 31.10 shows an ch28_06.htm:commands (Section 1.21) to connect to ch28_06.htm:the MH email system (Section 6.2). You use MH ch28_06.htm:setup file (Section 3.3): ch28_06.htm:

{ } Section 28.4

ch28_06.htm:folder output with sed (Section 34.1) to exclude ch28_06.htm:matches any pattern included with backquotes (Section 28.14) from ch28_06.htm:the cat (Section 12.2) command, which gives us the contents of ch28_06.htm:Section 28.4 has an example of ch28_07.htm:(Section 28.6). For example, you may be more likely ch28_07.htm:

set Section 35.9

ch28_07.htm:files (Section 19.4)), and so on. Section 1.12 has a list of them. ch28_07.htm:Emacs) has to be quoted ((Section 27.13) when it's stored in the ch28_07.htm:(Section 31.11).

ch28_08.htm:

Type !! (Section 30.8) to repeat the previous command line, or ch28_08.htm:(Section 30.9) ch28_08.htm:

Press the up-arrow key (Section 30.14) or a vi- or Emacs-style ch28_08.htm:mouse (Section 28.10) ch28_08.htm:loops (Section 28.9) can vary the commands they run by picking a ch28_08.htm:(Section 28.11). ch28_09.htm:command line editing (Section 30.14) or -- as we show here -- history substitution ch28_09.htm:(Section 30.5): ch28_09.htm:

-v Section 12.4, less Section 12.3

ch28_09.htm:a word into a shell variable (Section 35.9), then running the command(s). The loop goes ch28_09.htm:are secondary prompts (Section 28.12); the shell will keep printing them until you ch28_09.htm:filenames. Among other things, you can use wildcards (Section 1.13), ch28_09.htm:backquotes (Section 28.14) (command substitution), variables (Section 35.9, ch28_09.htm:Section 35.3), and the handy curly brace ({}) ch28_09.htm:operators (Section 28.4). For example, you ch28_09.htm:

set Section 35.9

ch28_09.htm:email (Section 1.21) ch28_09.htm:it's a good idea to put a command like sleep 5 (Section 25.9) on a ch28_09.htm:

cat - Section 12.2 ch28_09.htm:shell programming (Section 35.2). I usually don't recommend ch28_09.htm:prompts (Section 28.12); the Bourne shell ch28_09.htm:have to be filenames. Among other things, you can use backquotes (Section 28.14) ch28_09.htm:(Section 35.9, Section 35.3), ch28_09.htm:wildcards (Section 33.1), and, on shells like bash ch28_09.htm:operators (Section 28.4). For ch28_09.htm:command (Section 35.18). It reads ch28_09.htm:

Section 35.21 has more information about the ch28_09.htm:for loop. Section 36.12 ch28_10.htm:xterm window (Section 24.20) or another type of terminal emulator with ch28_10.htm:paste, try using a scratchpad window or xclipboard (Section 5.19). ch28_11.htm:command over and over again -- for example, ps (Section 24.5) to monitor ch28_11.htm:the progress of your background processes, or lpq (Section 45.2) to know ch28_11.htm:repeatedly, or even using shell history (Section 30.2) to ch28_12.htm:on the next line. For example, to send a quick write (Section 1.21) message ch28_12.htm:(Section 27.13). In tcsh, ch28_12.htm:to use a program like sed (Section 34.1) from the ch28_12.htm:

nroff -msSection 3.21, lpSection 45.2 ch28_12.htm:programming constructs for non-programmers, the for and foreach loops (Section 28.9), work. While ch28_12.htm:script (Section 1.8), it is often even ch28_12.htm:.tif are sent through netpbm (Section 45.19) filters, ch28_12.htm:

case Section 35.10, echoSection 27.5

ch28_13.htm:

Figure <<Section 27.16 ch28_13.htm:(Section 27.16) is often used in shell ch28_13.htm:throwaway script. But you also can just type it in at a Bourne shell prompt (Section 28.12). (If you use csh or ch28_13.htm:tcsh, you can either use a foreach loop (Section 28.9) or ch28_13.htm:start a subshell (Section 24.4).) ch28_13.htm:(Section 28.9) that prints ch28_13.htm:three friendly form letters with the lpr (Section 45.2) command. ch28_13.htm:don't indent the loop body.) The backquotes (Section 28.14) run ch28_14.htm:

-l Section 33.6

ch28_14.htm:mail message (Section 1.21) to all the users logged on to the system now. ch28_14.htm:(Section 2.8). The who output also lists ch28_14.htm:(Section 21.14): ch28_14.htm:sort -u (Section 22.6). You're done. Just put the ch28_14.htm:(Section 26.5): ch28_14.htm: (Section 36.24) the backquotes -- this is where the ch28_14.htm:them: making unique filenames (Section 8.17), removing some files ch28_14.htm:from a list (Section 14.18), setting your shell prompt (Section 4.6, Section 4.8, Section 4.14), and setting ch28_14.htm:variables (Section 4.8, Section 36.23). ch28_15.htm:

'...' Section 28.14

ch28_15.htm:(Section 28.17). If your system doesn't have ch28_16.htm:they'll be grouped together in the history list (Section 30.7). ch28_16.htm:

I can repeat that same command later by using a history substitution (Section 30.8) like !ll. ch28_16.htm:

It's useful with sleep (Section 25.9) to run a command after a delay. The next ch28_16.htm:your interrupt key (Section 24.10) -- like CTRL-c -- will stop execution ch28_16.htm:ndown (Section 24.22) (which run ch28_16.htm:has connected). So the shell runs ptbk (Section 38.9) to make a ch28_16.htm:into a subshell (Section 43.7) in the background (Section 23.2).) ch28_16.htm:|| (Section 35.14), work like a semicolon, ch28_17.htm:arguments. The shell's backquotes (Section 28.14) do the ch28_17.htm:

< Section 43.1

ch28_17.htm:files with pr (Section 45.6) first, you could type: ch28_17.htm:

In the next example, find (Section 9.1) gets a list of all files in the directory ch28_17.htm:and run grep -l (Section 33.6) to find which files contain the word ch28_18.htm:interactive applications such as telnet (Section 1.21) and ch28_18.htm:Expect scripts work great as CGI scripts or from cron (Section 25.2) or ch29_01.htm:Section 29.2 through Section 29.10 cover C shell aliases. Section 29.4 through Section 29.14 cover ch29_01.htm:

All except the oldest Bourne-type shells have shell functions (Section 29.11), which are explained in Section 29.11 through Section 29.13. These ch29_02.htm:get very complicated. Section 29.3 describes ch29_02.htm:Section 29.4 covers some of the differences ch29_02.htm:function (Section 29.11). ch29_02.htm:file (Section 3.3), so ch29_02.htm:(Section 3.3), so putting ch29_03.htm:at the end (Section 29.2) this way: ch29_03.htm:

Using cat and a pipe that way is inefficient (Section 43.2). It ch29_03.htm:do we do this? The C shell's history (Section 30.8) ch29_03.htm:

But why couldn't we just use single quotes or double quotes (Section 27.12)? This isn't the right place ch29_03.htm:does (Section 27.13). If you want to be ch29_03.htm:match the wildcard (Section 1.13) pattern !*. That fails ch29_03.htm:Here's a sample alias. It uses cat (Section 12.2) to add a ch29_03.htm:

~ Section 31.11

ch29_04.htm:Section 29.2 applies to the ch29_04.htm:This article, along with Section 29.5 and ch29_04.htm:Section 29.6, have an overview of ch29_04.htm:understand how quoting (Section 27.12) works in aliases. ch29_04.htm:operator (Section 29.3) does. To ch29_04.htm:(Section 29.11). ch29_05.htm:the regular command alias covered in Section 29.4. ch29_05.htm:aliases keep track of the locations of external (Section 1.9) ch29_05.htm:-t
shows. Next, I add a tracked alias for less (Section 12.3) (which ch29_06.htm:in Section 29.4. zsh is ch29_06.htm:isn't quoted). These are like a shell variable (Section 35.9) ch29_07.htm:capability is shell scripts (Section 1.8). Each has its strengths. An alias is just ch29_07.htm:visible (Section 24.3) to the parent shell ch29_07.htm:command-line arguments into a variable and then source (Section 35.29) a script to ch29_07.htm:starting a subshell (Section 24.4) for the script, it can do everything an alias ch29_07.htm:functions (Section 29.11). ch29_07.htm:the end of its name. I put all of the scripts in my ~/bin (Section 7.4). [Instead ch29_07.htm:

<< Section 27.16

ch29_07.htm:

set Section 35.9

ch29_08.htm:

Section 27.9 has similar information for ch29_08.htm:that came up on the Net a while ago. Someone wanted an exit (Section 24.4) alias that ch29_08.htm:would run a ~/.exit file (Section 31.13) before leaving the shell. The obvious ch29_08.htm:

Section 27.10 has the hairy details of what ch29_08.htm:Where name is the name of a built-in (Section 1.9) ch29_09.htm:(Section 29.7). Or that's what I ch29_09.htm:eval (Section 27.8) ch29_09.htm:(Section 29.3) and another during the first pass of ch29_10.htm:type. The output of cat is piped to the less (Section 12.3) pager. For ch29_11.htm:(Section 29.2). ch29_11.htm:

Let's start with two aliases from Section 29.2, changed into shell functions: ch29_11.htm:(Section 35.20) is ch29_11.htm:then sed (Section 34.1) to pull out the "ANSWER ch29_11.htm:

for Section 35.21

ch29_11.htm:

The mx function looks like a little shell program (Section 35.2). ch29_11.htm:script (Section 35.30). But, as ch29_11.htm:shell prompt. (Section 24.3 has details.) ch29_11.htm:links (Section 10.4) named for each ch29_11.htm:

if Section 35.13, '...' Section 28.14, wc Section 16.6

ch29_11.htm:$1, the second in $2, and so on (Section 35.20). ch29_11.htm:(Section 35.12) to the ch29_11.htm:-x (Section 27.15) at a shell prompt. Then ch29_11.htm:operator (Section 36.16).) ch29_11.htm:

${..-..} Section 36.7

ch29_11.htm:shells, and Section 29.14 shows how to ch29_12.htm:

Section 27.11 introduces shell functions for all Bourne-type ch29_12.htm:system-wide setup file (Section 3.3) like /etc/profile. ch29_12.htm:Section 27.9 explains, you can type ch29_12.htm:If a function uses an environment variable -- like VISUAL or EDITOR (Section 35.5), your standard text editor -- you can set ch29_12.htm:(Section 29.11): ch29_13.htm:files (Section 3.3). Here are two other ch29_13.htm:other bash subshells (Section 24.4). (The original Korn shell, but not the ch29_13.htm:

How does this work? It stores the function in an environment variable (Section 35.3) whose value starts with ( ch29_13.htm:env (Section 35.3). For example, ch29_13.htm:(Section 35.6). So you can ch29_13.htm:chmod +x foo (Section 35.1)), and then the shell can find the function. ch29_13.htm:command (Section 1.9) -- means the ch29_13.htm:first uses set -xv (Section 37.1) for debugging. func1 was a ch29_13.htm:

First, without autoloading, I use type (Section 2.6) to see if ch29_13.htm:

Next I played with func2. typeset -f (Section 29.11) ch29_13.htm:cat (Section 12.2) ch29_13.htm:file (Section 3.3): ch29_13.htm:

IFS Section 36.23, for Section 28.9

ch29_13.htm:setup file (Section 3.3) -- typically .zshrc: ch29_14.htm:commands. If you have a Bourne shell with no functions (Section 29.11) or ch29_14.htm:aliases (Section 29.2) and haven't yet turned the ch29_14.htm:the same things with shell variables and the eval (Section 27.8) command. ch29_14.htm:

test Section 35.26

ch29_14.htm:

set Section 35.25

ch30_01.htm:history command (Section 30.7) lists the saved commands, each with an ch30_01.htm:the shells to print the history number of each command as part of your prompt (Section 4.3).) ch30_01.htm:Section 30.8 and Section 28.5 give quick tutorial summaries of some of the ch30_01.htm:Bourne and C shells -- also have interactive command-line editing (Section 30.14). Interactive editing might seem to be better ch30_02.htm:($varname) (Section 35.9) or command substitution ('command') (Section 28.14): the shell replaces what you type (like ch30_02.htm:

Section 30.1 is an introduction to shell ch30_02.htm:

We start with favorite uses from several contributors -- Section 30.3, Section 30.4, Section 30.5, and Section 30.6. ch30_02.htm:

Section 30.8 starts with a quick ch30_02.htm:

(Back in Section 28.5 are examples of ch30_02.htm:bash commands in Section 30.9. ch30_02.htm:history to another shell, see Section 30.12 ch30_02.htm:and Section 30.13. ch30_02.htm:(!) for history. Section 30.15 shows how to use some other character. ch30_02.htm:

The Korn shell does history in a different way. Section 30.14 introduces part of that: command-line editing ch30_02.htm:your prompt (Section 4.3) makes it easy ch30_03.htm:

I get a lot of tar archives (Section 39.2). ch30_04.htm:

I use !$ (Section 30.3) a lot, but ch30_04.htm:example, to use RCS (Section 39.5) and make an edit to article files named Section 35.5 and Section 29.2 for this ch30_04.htm:more of these in Section 30.8. ch30_05.htm:(Section 30.11) to recall an earlier command so I can change ch30_06.htm:

(ls -d a* (Section 8.5) will make less output if any subdirectory ch30_07.htm:editing (Section 30.14) when ch30_07.htm:use !20:$ (Section 30.8) to pass that filename as an argument to ch30_07.htm:

less Section 12.3, \!* Section 29.3

ch30_07.htm:prompt (Section 4.3). Then you can ch30_08.htm:(!) is the default (Section 30.15) history ch30_08.htm:arguments from the command line in aliases (Section 29.3): ch30_08.htm:you want to add a modifier (Section 28.5) like the following: ch30_08.htm:(Section 4.3). ch30_08.htm:

Note that as an operator (Section 28.5,), ch30_08.htm:regular expressions (Section 32.5), !^ gives the beginning ch30_08.htm:-v (Section 12.4) command through ch30_08.htm:the alias is used -- see Section 29.3 for ch30_08.htm:

^xy^yx is the shorthand substitution (Section 30.3, Section 30.5) command. In ch30_08.htm:

The search part, or left side, cannot include metacharacters (Section 32.3). ch30_10.htm:aliases on the C shell command line. (I could have used shell functions (Section 29.11) ch30_10.htm:RCS (Section 39.5) ch30_10.htm:

The h alias stores the filename in a shell variable (Section 35.9). ch30_10.htm:ampersands) (Section 35.14) means that the following ch30_10.htm:(semicolon) (Section 28.16) instead of ch30_12.htm:variable (Section 35.9) to the number of ch30_12.htm:(Section 23.12) logged on as the same user will have ch30_12.htm:ksh shell: customize your setup file (Section 3.3) to ch30_12.htm:tips in Section 3.18 and a series starting at ch30_12.htm:Section 3.10.) ch30_12.htm:

The simplest fix is to use $$ (Section 27.17) -- which will probably expand differently ch30_12.htm:may be world-readable (Section 50.2) if your umask isn't set to ch30_12.htm:history -r. Section 30.13 ch30_12.htm:a login shell (Section 3.4),[95] you can run history -h from your ch30_12.htm:

[95]xterm -lsSection 5.10 runs a ch30_12.htm:the shell with an exit (Section 24.4) command. ch30_12.htm:

Set an alias for exit (Section 29.8) that runs history -h ch30_12.htm:script (Section 30.13) that saves and ch30_13.htm:a history of the commands you type (Section 30.12). You can add your own commands to some ch30_13.htm:another shell (Section 30.12). ch30_13.htm:

Of course, you can also use bash interactive command-line editing (Section 30.14) on the saved commands. ch30_14.htm:them you had to retype them.) The C shell added history substitution operators (Section 30.2) that were great on teletypes -- and are ch30_14.htm:partially-typed filenames (Section 28.6), ch30_14.htm:the usual map (Section 18.2) command; instead, the ch30_14.htm:variety of different editor settings (Section 30.14.5), to set up the editing mode. To make this the ch30_14.htm:default, store the command in your shell's setup file (Section 3.3) (in ch30_14.htm:

If you know the Emacs (Section 19.1) editor, ch30_14.htm:can't run psychoanalyze-pinhead (Section 19.13) :-)) -- the emacs-mode ch30_14.htm:(Section 3.3) (in bash, you can ch30_14.htm:pager such as less (Section 12.3) that lets you page through and do searches. ch30_14.htm:and bindkey -l into one list with perl (Section 41.1) or ch30_14.htm:awk (Section 20.10) ch30_14.htm:(Section 27.13) special characters. And the special ch30_14.htm:history substitutions (Section 30.8) in the command line, then lets you continue ch30_14.htm:remember to quote (Section 27.12) any special characters. So, if you want to ch30_14.htm:make CTRL-r be the traditional Unix rprnt (Section 28.2) operation ch30_14.htm:have to put quotes (Section 27.12) around the whole binding -- so watch out ch30_14.htm:for quoting conflicts. For example, to make CTRL-o output a redirection (Section 43.1) ch30_14.htm:

less Section 12.3

ch30_15.htm:character (Section 30.5)). For example: ch30_15.htm:character (Section 35.1) only in ch30_16.htm:(Section 1.21) command), you can type a backslash ch30_16.htm:

By the way, if you have a window system, you can probably copy and paste the command line (Section 28.10) instead of using shell history. ch31_01.htm:

Using relative and absolute pathnames: Section 31.2. ch31_01.htm:

What good is a current directory? Section 31.3. ch31_01.htm:cdpath: Section 31.5. ch31_01.htm:using and let you get to them quickly: Section 31.7, Section 31.8. ch31_01.htm:

Quick cd aliases: Section 31.9. ch31_01.htm:directories and files: Section 31.11. ch31_01.htm:cd'ing back: Section 31.12. ch31_01.htm:

Automatic setup for entering and exiting a directory: Section 31.13. ch31_02.htm:(Section 1.16). ch31_02.htm:

The symbolic link (Section 10.4) adds a twist to pathnames. What two absolute ch31_03.htm:

When you use a subshell (Section 43.7, Section 24.4) or a shell ch31_03.htm:(Section 1.16). Without a current directory and relative ch31_03.htm:pathnames, you'd always have to use absolute pathnames (Section 31.2) like ch31_04.htm:external (Section 1.9) command that isn't built ch31_04.htm:(Section 10.2). ch31_04.htm:book. Also see the last few paragraphs of Section 10.4 for more about the links between directories. ch31_05.htm:

Some people make a shell alias (Section 29.2) for ch31_05.htm:shell variables (Section 35.9) to hold the pathnames of directories they ch31_05.htm:startup files (Section 3.3) each time you ch31_05.htm:directories (Section 1.16). This ch31_05.htm:

~ Section 31.11

ch31_05.htm:PATH variable, is actually an empty entry (Section 35.6) ch31_06.htm:

Normally a for loop (Section 35.21) iterates ch31_06.htm:until it has processed all its word arguments. while and until loops (Section 35.15) iterate until the loop control command ch31_06.htm:

'...' Section 28.14, || Section 35.14, * Section 1.13, test Section 35.26

ch31_07.htm:(Section 31.5) that includes your home directory, ch31_07.htm:prompt (Section 4.14), but I personally ch31_08.htm:

The pushd command (Section 31.7) ch31_08.htm:(Section 29.2) in Daniel Gilly's ch31_09.htm:make aliases (Section 29.2) that take you to each directory quickly. For ch31_09.htm:shell function (Section 29.11). A shell ch31_09.htm:script (Section 1.8) ch31_09.htm:won't work, though, because it runs in a subshell (Section 24.4).) ch31_09.htm:Section 35.27 shows how to pick a new name. ch31_09.htm:shell setup file (Section 3.3), like this C shell example for your ch31_09.htm:

source Section 35.29, ~ Section 31.11

ch31_10.htm:shells that don't have filename completion (Section 28.6). This function works a bit like filename ch31_10.htm:

set Section 35.25, $# Section 35.20

ch31_11.htm:GNU Emacs (Section 19.4) editor and vi, may create ch31_11.htm:is. It's a directory full of symbolic links (Section 10.4) ch31_11.htm:

In fact, using echo (Section 27.5) yourself is a good way to see how ch31_12.htm:does not exist, csh tries searching its cdpath (Section 31.5), then ch31_12.htm:(Section 31.7) to store directory names; ch31_12.htm:your shell setup file (Section 3.3), use cdable_vars=1 for ch31_13.htm:.exit file is sourced (Section 35.29) into ch31_13.htm:(Section 31.7), you'll probably want ch31_13.htm:

setprompt Section 4.7

ch31_13.htm:links (Section 10.4) between the files. If ch31_13.htm:have to use a symbolic link (Section 10.4) -- though that probably ch31_13.htm:

source Section 35.29

ch32_01.htm:in Section 32.4. We did this because regular ch32_01.htm:(Section 32.16 and Section 32.18) and a few tools that help you see what your ch32_01.htm:expressions are matching (Section 32.17). ch32_01.htm:There's also a quick reference (Section 32.21) for those of you who just need a refresher. ch32_02.htm:the special characters in a regular expression must be quoted (Section 27.12) when ch32_03.htm:(Section 13.2) that accept regular expressions must first ch32_03.htm:is matched and what is not. In Section 32.4 ch32_04.htm:explains the incompatibility at the end of Section 32.15. -- TOR
] ch32_04.htm:(Section 32.5) ch32_04.htm:

Matching a character with a character set (Section 32.6) ch32_04.htm:

Match any character with . (dot) (Section 32.7) ch32_04.htm:(Section 32.8) ch32_04.htm:

Exceptions in a character set (Section 32.9)

ch32_04.htm:

Repeating character sets with * (Section 32.10) ch32_04.htm:\} (Section 32.11) ch32_04.htm:\> (Section 32.12) ch32_04.htm:\), and \1 (Section 32.13) ch32_04.htm:

Potential problems (Section 32.14)

ch32_04.htm:

Extended regular expressions (Section 32.15)

ch32_05.htm:(Section 13.9, Section 11.10). -- JP] You see, the ch32_05.htm:the last argument on the previous line (Section 30.8 explains). ch32_05.htm:ed and sed. cat -v -e (Section 12.5, Section 12.4) marks ends of lines with a ch32_06.htm:the lines of a mail message (Section 1.21) that identify the sender. Use this pattern ch32_06.htm:

$USER Section 35.5

ch32_10.htm:useless (Section 32.4), as it matches any ch32_11.htm:some programs (Section 32.20) recognize a special pattern you can use to ch32_13.htm:on the replacement side (Section 34.11). ch32_14.htm:that extended expressions (Section 32.15) offer, I want to mention two potential ch32_14.htm:

The other potential point of confusion is the extent of the pattern matches (Section 32.17). Regular expressions match the longest ch32_15.htm:GNU Emacs (Section 19.1) does, by the way -- it combines all of the ch32_16.htm:an expression (Section 32.1) by looking up each word in the dictionary. ch32_19.htm:(Section 32.20 lists the metacharacters that ch32_20.htm:descriptions of each of the characters can be found in Section 32.21. ch32_21.htm:

Section 32.4 ch33_01.htm: (Section 1.13) ch33_01.htm:in many situations. If not, they are summarized in Section 33.2. Here are a few of my favorite wildcard ch33_01.htm:than find (Section 9.1). ch33_01.htm:problems (Section 33.5).) ch33_02.htm:(Section 28.4) ch33_02.htm:shopt. (For other shells, see nom (Section 33.8).) ch33_02.htm:^ab[c]. (For other shells, see nom (Section 33.8).) ch33_02.htm:regular expresssion (Section 32.2) x*). The pattern can have parentheses ch33_02.htm:expresssion (Section 32.15) x+). The ch33_02.htm:( Section 27.12, ch33_02.htm:Section 27.13), of course. In the C shells, you can ch33_03.htm:

Wildcards (Section 1.13) are ch33_03.htm:variants (Section 1.6)) honor the same ch33_03.htm:anyone change the rules. (But most new shells also have extended wildcards (Section 33.2). And different shells do different things ch33_03.htm:match (Section 33.4).) ch33_03.htm:files from a tape, which requires the command tar x (Section 38.6), so you ch33_03.htm:of the files you want are already in your current directory (Section 1.16). The shell expands the wildcard ch33_03.htm:shell. Simply put *.txt in quotes (Section 27.12). ch33_03.htm:and scp (Section 46.6)) know how to handle ch33_03.htm:{} characters (Section 28.4), you can use them because they can generate ch33_03.htm:workaround (Section 38.10). ch33_04.htm:probably by using !! (Section 30.8) when I knew there weren't ch33_04.htm:echo (Section 27.5), ch33_05.htm:parentheses) (Section 43.7) if you want ch33_05.htm:

&& Section 35.14

ch33_05.htm:(Section 28.17) command.) ch33_06.htm: when you run grep (Section 13.1) on a group ch33_06.htm:

'...' Section 28.14

ch33_07.htm:(Section 13.2) option -c to tell you how ch33_07.htm:uppercase, you'll also want the -i option (Section 9.22).) ch33_07.htm:

Using sed (Section 34.1) to truncate the :0, you ch33_07.htm:a $ anchor (Section 32.5) to be sure sed matches ch33_07.htm:(Section 27.12) the $ for ch33_07.htm:pathname (Section 1.16) puts the ch33_07.htm:

"$@" Section 35.20

ch33_08.htm:don't match. As Section 33.2 shows, some shells have an ch33_08.htm:substitution (Section 27.14): ch33_08.htm:

trap Section 35.17, case Section 35.11, $* Section 35.20, comm Section 11.8

ch33_08.htm:

The -d option (Section 8.5) tells ls to list the names ch33_08.htm:of any directories, not their contents. The ${1+"$@"} (Section 36.7) works ch34_01.htm:through a pipe (like all well-behaved Unix filters (Section 1.5) do). ch34_01.htm:

In this chapter, we start out with the basics: Section 34.2, Section 34.3, Section 34.4, Section 34.5, Section 34.6, and Section 34.7 show you how ch34_01.htm:advanced scripts. Section 34.8 through Section 34.14 cover regular expressions and complex ch34_01.htm:transformations. Section 34.15 through Section 34.24 deal with advanced topics such as multiline ch34_02.htm:(Section 43.1) or a file, transform it, and pass it ch34_02.htm:to standard output (Section 43.1). If you want to edit a file, you have to ch34_02.htm:write a shell wrapper (Section 34.4) to capture standard output and write it back ch34_03.htm:were using sed on the fly, as a stream editor (Section 34.2), ch34_03.htm:scripts (Section 1.8)) you can use the ch34_04.htm:script (Section 35.2) that invokes ch34_04.htm:loop (Section 35.21) to apply the ch34_04.htm:(Section 8.2) ch34_04.htm:metacharacters (Section 33.2) can be used ch34_05.htm:expression (Section 32.4) that describes a pattern. ch34_06.htm:(Section 34.16) reads another line into the pattern ch34_06.htm:Section 34.14 and other articles after it. ch34_09.htm:

2 Section 34.12

ch34_11.htm:of use. (Section 32.13 has more information.) ch34_11.htm:test document, using checksed (Section 34.4): ch34_11.htm:

Section 43.10, Section 31.10, ch34_11.htm:Section 10.9, and Section 36.23 have ch34_13.htm:function to tr (Section 21.11). It replaces any character found in the first ch34_13.htm:(Section 1.21) from being read except by someone who ch34_14.htm:

For other scripts that use the hold space, see Section 34.18. For a fanciful analogy that makes clear how ch34_14.htm:it works, see Section 34.17. ch34_15.htm:command, y (Section 34.13), acts on the ch34_16.htm:

Most programs that use regular expressions (Section 32.4) are able to match a pattern only on a single ch34_16.htm:

or use the \(..\) operators (Section 34.11) to keep the newline: ch34_17.htm:

Section 34.18 shows a practical application of ch34_18.htm:

[Section 13.9 introduced a script called ch34_18.htm:advanced applications of this obscure yet wonderful editor. Section 34.14 through Section 34.17 ch34_18.htm:

Let's review the two examples from Section 13.9. The first command below finds all lines ch34_18.htm:

case Section 35.11, expr Section 36.21, shift Section 35.22, ${?} Section 36.7, \~..~ Section 34.8, "$@" Section 35.20

ch34_18.htm:(Section 35.19) to ch34_18.htm:enclosed in double quotes (Section 27.12). We use the -n option ch34_19.htm:d, deletes the contents of the pattern space (Section 34.14) and ch34_21.htm:

First, h (Section 34.14) holds a copy of the current input line. Then, ch34_21.htm:g (Section 34.14) ch34_22.htm:

Figure Section 34.23

ch34_22.htm:

-n Section 34.3

ch34_23.htm:

The sed quit command, q (Section 34.22), is very ch34_24.htm:

Feeding sed (Section 34.1) ch34_24.htm:(Section 27.12). ch34_24.htm:such as bash, which do what I consider the proper thing (Section 27.12) with this input. The C shell, however, thinks ch34_24.htm:trailing backslashes (Section 27.13), and ch34_24.htm:commands in a separate file (Section 34.3) to keep the shell's sticky ch35_01.htm:

who (Section 2.8) ch35_01.htm:

cut -c1-8 (Section 21.14) outputs columns 1-8 of the ch35_01.htm:

sort -u (Section 22.6) puts names in order and takes out names of ch35_01.htm:

pr -l1 -8 -w78 -t (Section 21.15, Section 45.6) takes the list ch35_01.htm:

If your system supports the special #! notation (Section 36.2) (and it probably does), the first line of the ch35_01.htm:Section 36.2 has more information.) ch35_01.htm:you need to make the shell script executable. The chmod (Section 50.5) (change ch35_01.htm:your login shell (Section 3.4) is csh or ch35_01.htm:

rehash Section 27.6

ch35_01.htm:be in your shell's command search path (Section 35.6, Section 35.7). In that case, ch35_01.htm:that's in your search path and/or change your search path (Section 27.6). If you're the only person ch35_01.htm:bin directory (Section 7.4). Otherwise, you might ask your system ch35_02.htm:standard input is a tty (Section 2.7), checking options and arguments, or something ch35_02.htm:

On the other hand, maybe your script needs lots of pipes ( | ) (Section 1.5) or ch35_02.htm:

To see how to write a simple shell program, Section 35.1. To embed scripts from other languages such as ch35_02.htm:Section 35.19. ch35_02.htm:

For explanation of shells in general, Section 27.3. ch35_02.htm:

To read about environment and shell variables, Section 35.3 and Section 35.9, ch35_02.htm:

Shell quoting is explained in Section 27.12.

ch35_02.htm:for loop is discussed in Section 28.9 (as well as in Section 35.21, later in this chapter). ch35_02.htm:

Test strings with a case statement, Section 35.10. Match patterns in a case ch35_02.htm:statement, Section 35.11. ch35_02.htm:command substitution, Section 28.14. ch35_02.htm:Section 35.12. ch35_02.htm:that loop, Section 35.15. ch35_02.htm:

Set exit status of a shell (shell script), Section 35.16. ch35_02.htm:

Handle interrupts (like CTRL-c) and other signals, Section 35.17. ch35_02.htm:

Read input from the keyboard, Section 35.18.

ch35_02.htm:

Handle command-line arguments (options, filenames, etc.), Section 35.20. ch35_02.htm:if it worked or failed, Section 35.13 and ch35_02.htm:Section 35.14. ch35_02.htm:shift commands, Section 35.22. ch35_02.htm:with getopt, Section 35.24. ch35_02.htm:set command, Section 35.25. ch35_02.htm:command, Section 35.26. ch35_02.htm:

Pick a name for a new command with no conflict, Section 35.27. ch35_02.htm:

Find the name of a program and use it in the script, Section 35.28. ch35_02.htm:the current environment, Section 35.29. ch35_02.htm:test (Section 35.26) ch35_03.htm:(Section 5.2) ch35_03.htm:(Section 35.6) variable. When you type a command, ch35_03.htm:command directories (Section 7.4), and ch35_03.htm:you'll need to tell the shell how to find them (Section 27.6). ch35_03.htm:variables (Section 35.9) is that a shell ch35_03.htm:(Section 24.4). That is, the new process gets its own ch35_03.htm:(Section 35.5) that these names are important. But if ch35_03.htm:understands filename wildcard (Section 1.13)-type expressions -- for instance, ch35_03.htm:

The set (Section 35.9) command provides a similar listing of shell ch35_04.htm:(Section 35.3) we said that each process gets its own ch35_04.htm:found. The problem is simple. A Unix process (Section 24.3) cannot ch35_04.htm:(Section 3.3). -- JP] ch35_05.htm:

PATH (Section 35.6)
ch35_05.htm: (Section 27.6). This is a list of directories in which the ch35_05.htm:one of your shell setup files (Section 3.3). ch35_05.htm:(usually set to a line editor (Section 20.1) such as ed) and ch35_05.htm:editing mode (Section 30.14).) ch35_05.htm:
PRINTER (Section 45.4) or LPDEST
ch35_05.htm:need to tell lpr or lp (Section 45.2) which printer to use. ch35_05.htm:
HOME (Section 31.11) (called LOGDIR on some systems)
ch35_05.htm:new Korn shell is started. (See Section 3.3.) Korn shell only. ch35_05.htm:new bash shell is started. (See Section 3.3.) bash only. Often set to ch35_05.htm:program like less (Section 12.3) or ch35_05.htm:more. (Programs like man (Section 2.1) use ch35_05.htm:the .cshrc file (Section 3.3) is read to set up each instance of the shell. ch35_05.htm:See Section 4.4.) ch35_05.htm:
PS2 (Section 28.12)
ch35_05.htm:
MANPATH (Section 3.21)
ch35_05.htm:if your man (Section 2.1) command supports it, is a colon-separated ch35_05.htm:(Section 1.22) to identify the display server ch35_05.htm:command (Section 8.6). ch35_05.htm:to look at the end of a command's manual page (Section 2.1) in ch35_05.htm:printenv (Section 35.3)) and make some ch35_06.htm:

$HOME/bin Section 7.4

ch35_06.htm:

Section 27.6 explains more about setting the ch35_06.htm:built-in commands (Section 1.9) and commands for which you give the complete ch35_06.htm:exit instead.) Another fix is to read (Section 35.29) whichever ch35_06.htm:(Section 35.27). If you really need an overlapping ch35_06.htm:pathname (Section 1.16) to specify ch35_06.htm:PATH for a command with which (Section 2.6), ch35_06.htm:Section 35.7 explains the pair of ch35_07.htm:(Section 35.6) in csh or ch35_07.htm:variable (Section 35.9) is the actual ch35_07.htm:

~ Section 30.11

ch35_08.htm:environment, the DISPLAY environment variable will propagate (Section 35.3) to ch35_08.htm:Section 6.10 for more information on running ch35_09.htm:"general case" of environment variables (Section 35.3). If you're a programmer, ch35_09.htm:(Section 3.3)). If you're a ch35_09.htm:example, the C shell uses the history (Section 30.1) ch35_09.htm:if the noclobber (Section 43.6) variable is defined, the C shell prevents you ch35_09.htm:.tcshrc (Section 3.3) files to define ch35_09.htm:them up into context-specific files and then read them into their environment (Section 35.29) as needed. ch35_09.htm:or env (Section 35.3).[105] If you want to list all of your Bourne or C shell ch35_09.htm:external (Section 1.9) commands; they work with any shell.

ch35_09.htm:programming (Section 35.2). ch35_10.htm:(Section 35.9, Section 35.3)) to one ch35_10.htm:expressions (Section 35.11). When the ch35_10.htm:

Here's an example that tests your TERM (Section 5.2) ch35_10.htm:

exit Section 35.16

ch35_10.htm:line with semicolons (Section 28.16)). ch35_11.htm:

A case statement (Section 35.10) is good at ch35_11.htm:wildcards (Section 1.13) in the shell, ch35_11.htm:the pattern What now?. The quotes (Section 27.12) tell the ch35_12.htm:exit status in this way, because there are several ways (Section 35.13, ch35_12.htm:Section 35.14, Section 35.15) to use ch35_13.htm:special null command, a colon (:) (Section 36.6). ch35_13.htm:"true"), the || operator (Section 35.14) ch35_13.htm:first filename from the command line -- see Section 35.20.) ch35_13.htm:named test (Section 35.26). The test command does a ch35_14.htm:cat returns an exit status of 1), you exit (Section 24.4). If you ch35_14.htm:write an "inverse if (Section 35.13)): ch35_15.htm:

The loop runs who (Section 2.8) and pipes that output to grep (Section 13.1), which ch35_15.htm:

/dev/null Section 43.12

ch35_16.htm:return a status (Section 35.12). Your shell script should, too. This section ch35_16.htm:Section 35.13. If the script can make a backup ch35_17.htm:your interrupt key (Section 5.8) ch35_17.htm:process ID number (Section 24.3). Because no other process will have the same ch35_17.htm:ID number, that file should have a unique name. The script uncompresses (Section 15.6) ch35_17.htm:

exit Section 35.16

ch35_17.htm:(Section 28.16). The first command removes the ch35_17.htm:option (Section 14.10), so ch35_17.htm:have two traps. Look at the nom (Section 33.8) script for ch35_17.htm:echo commands in the script have 1>&2 (Section 36.16) at ch35_17.htm:it's probably neater to call a shell function (Section 29.11) ch35_18.htm:(Section 43.1); they can only read from the ch35_18.htm:(Section 28.14): ch35_19.htm:(Section 36.3) without needing the Bourne shell, ch35_19.htm:line (Section 35.20) and pass information ch35_19.htm:and so on. Simply use correct quoting (Section 27.12) to pass ch35_19.htm:

|| Section 35.14

ch35_19.htm:scripts (Section 35.2): ch35_19.htm:

<<\ Section 27.16

ch35_19.htm:command becomes the equivalent of a shell eval (Section 27.8); it ch35_19.htm:line has to end with a backslash (\) (Section 27.13). Section 27.12 and ch35_19.htm:Section 27.13 have more about quoting. ch35_20.htm:articles (Section 35.16, Section 35.17), $1 holds the first ch35_20.htm:reading this series (Section 35.2) of ch35_20.htm:articles in order, you saw the zmore (Section 35.17) script that accepted just one command-line ch35_20.htm:a script, the shell will replace that string with a quoted (Section 27.12) set of ch35_20.htm:unusual characters (Section 14.11): ch35_20.htm:no command-line arguments, the "$@" becomes a single empty argument (Section 37.5), as if you'd typed this: ch35_20.htm:${1+"$@"} (Section 36.7). That means that if $1 is ch35_20.htm:loop (Section 35.21) can step through all ch35_20.htm:command-line arguments, one by one. You can also use a while loop (Section 35.15) that ch35_20.htm:by one with the shift command (Section 35.22). The getopt and ch35_20.htm:getopts (Section 35.24) commands handle ch35_20.htm:script in Section 35.17) with case (Section 35.10) or ch35_20.htm:test (Section 35.26). ch35_21.htm:(The "$@" parameter (Section 35.20) gives you all of them at once.) The Bourne ch35_21.htm:shell variable (Section 35.9)), then executes the commands from ch35_21.htm:loop, let's hack on the zmore (Section 35.17) script. ch35_21.htm:

case Section 35.11

ch35_21.htm:quoted (Section 27.12). This way, if $switches is ch35_21.htm:IFS (Section 36.23)-separated) list of words -- not just ch35_21.htm:substitution (Section 28.14) (backquotes) ch35_21.htm:or shell wildcards (Section 33.2), or just ch35_21.htm:

lpr Section 45.2

ch35_21.htm:

The getopt and getopts (Section 35.24) commands handle command-line arguments in a ch35_22.htm:loop (Section 35.21) is great if you want ch35_22.htm:of while (Section 35.15), test (Section 35.26), case (Section 35.10), and shift. ch35_22.htm:while loop uses test (Section 35.26) to check ch35_22.htm:approach is perhaps obsolete if you have getopts (Section 35.24) ch35_23.htm:loop (Section 35.21) iterates until it has ch35_23.htm:until loops (Section 35.15) iterate until ch35_23.htm:

'...' Section 28.14, || Section 35.14, * Section 1.13, test Section 35.26

ch35_24.htm:command-line arguments -- options, filenames, and so on. Section 35.20, Section 35.21, and Section 35.22 show how to parse command lines with any ch35_24.htm:you'll usually give "$@" (Section 35.20) to pass ch35_24.htm:error message and returns a nonzero status (Section 35.12). ch35_24.htm:

|| Section 35.14, : Section 36.6

ch35_24.htm:script starts by running getopt inside backquotes (Section 28.14) and ch35_24.htm:using the set (Section 35.25) ch35_24.htm:dashes) (Section 35.25), is important: it ch35_24.htm:empty "$@" parameter (Section 37.5). If ch35_25.htm:option (Section 27.15): ch35_25.htm:around that problem, you could start a subshell (Section 24.4) with ch35_25.htm:Unix command with backquotes (Section 28.14). For example, you can get a list of all ch35_25.htm:(Section 2.8) and cut ch35_25.htm:(Section 21.14) to strip off everything but the ch35_25.htm:

for Section 35.21

ch35_25.htm:functions (Section 29.11) and other shell ch35_25.htm:from a cron (Section 25.2) job, in the middle of the night when no one ch35_25.htm:parameters. Then use shift (Section 35.22) to shift away the x, ch35_25.htm:them, wildcards (Section 33.2) and other special ch35_25.htm:characters (Section 27.17) will be ch35_25.htm:(Section 27.12). You can take advantage of this to ch35_25.htm:IFS (Section 36.23) ch35_25.htm:(Section 43.7) for the part of the script where you ch35_26.htm:shell's manual page (if your shell has test built in (Section 1.9)) ch35_26.htm:

The test command returns a zero status (Section 35.12) if the ch35_26.htm:

$HOME Section 35.5, $myname Section 35.28

ch35_26.htm:a couple of other common gotchas caused by empty arguments; Section 37.3 and Section 37.4 have ch35_27.htm:

which Section 2.6, whereis Section 2.3, alias Section 29.2

ch35_28.htm:/xxx/yyy/bin/someprog. The basename (Section 36.13) ch35_28.htm:make links (Section 10.3) to give Unix files several names, you can use ch35_28.htm:names (Section 36.8). For instance, see ch35_29.htm:

As Section 35.4 explains, Unix programs can never, ch35_29.htm:functions (Section 29.11), you can ch35_29.htm:simulate them (Section 29.14) with the . command. It acts a lot like a ch35_30.htm:

So far, we have discussed some shell function basics (Section 29.11), using examples such as the mx( ch35_30.htm:commands to include those functions from an external file (Section 35.29). ch35_30.htm:

We've also discussed using functions to automate repetitive tasks (Section 29.11), such as calculating factorials. ch36_01.htm:file to read. Chris Torek's Usenet classic, Section 36.2, explains how #! ch36_01.htm:started. Section 36.3 explains that your ch36_01.htm:exec command, Section 36.5, replaces the shell with another process; it ch36_01.htm:status -- Section 36.6 explains why you ch36_01.htm:substitution, explained in Section 36.7, is a ch36_01.htm:Section 36.8. Section 36.9 shows the easy way to get the last ch36_01.htm:command-line argument. Section 36.10 has an ch36_01.htm:into a single shell variable. Section 36.11 ch36_01.htm:input. Section 36.12 has techniques for making ch36_01.htm:can be used to split pathnames with a loop; see Section 36.13. A while loop can have more ch36_01.htm:than one command line at the start; see Section 36.14. ch36_01.htm:

Next is an assortment of articles about input/output. Section 36.15 introduces open files and file ch36_01.htm:standard input/output/error than you might have realized! Section 36.16 has a look at file-descriptor handling ch36_01.htm:Section 36.17 points out, a shell can also ch36_01.htm:problems. Section 36.18 shows one place ch36_01.htm:Section 36.19 explains. Section 36.20 shows how to turn off echoing while your ch36_01.htm:

Two articles -- Section 36.22 and Section 36.23 -- show uses for the versatile ch36_01.htm:expr expression-handling command. Section 36.21 is a quick reference to ch36_01.htm:expr. Section 36.24 covers ch36_01.htm:multiple command substitution (Section 28.14). ch36_01.htm:

Section 36.25 shows a trick for making one ch36_01.htm:case statement (Section 35.10) test two things at once. Finally, Section 36.27 has a simple technique for getting ch36_02.htm:read your .cshrc file (Section 3.3). ch36_03.htm:

Let's run both commands and time (Section 26.2) them. ch36_04.htm:

As Section 36.3 ch36_04.htm:command will search your PATH (Section 35.6) for an interpreter, then execute (exec (Section 24.2), replace ch36_05.htm:terminates the current shell and starts a new process (Section 24.3) in its ch36_05.htm:

exec also manipulates file descriptors (Section 36.16) in the Bourne shell. When you use ch36_06.htm:returns a zero exit status (Section 35.12). Here are a few places to use it: ch36_06.htm:make an endless while loop (Section 35.15). This is more efficient because the shell ch36_06.htm:if ( Section 35.13) but ch36_06.htm:(Section 35.7) like ch36_07.htm:bkedit script (Section 35.13, Section 35.16): ch36_07.htm:

If the VISUAL (Section 35.5) environment variable is set and is not empty, ch36_07.htm:You'll see them used with the colon (:) operator (Section 36.6), checking or setting default values. ch36_08.htm:links (Section 10.4, Section 10.3) to it instead. The program can find the name ch36_08.htm:/usr/joe/bin/prog (Section 31.2 explains pathnames). There are a couple of ch36_08.htm:Section 35.11) handles the different pathnames ch36_08.htm:also want to use basename (Section 36.13) to strip off any leading pathname and store ch36_09.htm:

eval Section 27.8

ch36_10.htm:

The shift (Section 35.22) command ch36_10.htm:(Section 35.20) to unset all parameters. ch36_10.htm:set (Section 35.25) a ch36_11.htm:for loop (Section 35.21) is to step through a list of ch36_11.htm:loop with backquotes (Section 28.14) and cat ch36_11.htm:(Section 12.2), and the loop will step through the ch36_12.htm:shell for loop (Section 35.21) lets you take a list of items, store the ch36_12.htm:

set Section 35.25

ch36_12.htm:shell's eval (Section 27.8) command to rescan the contents of the ch36_13.htm:(Section 31.2) to find a file or directory. There are ch36_13.htm:run split (Section 21.9) on them, and add huge. ch36_13.htm:

|| Section 35.14, exit Section 35.16

ch36_14.htm:(Section 35.15) looked like this, with a single ch36_15.htm:starts any process (Section 24.3) -- for example, grep, ch36_15.htm:you'll see in Section 36.16, ch36_15.htm:

When Unix starts a new subprocess (Section 24.3), the ch36_15.htm:redirected-I/O loop, as discussed in Section 43.6, takes advantage of this. ch36_16.htm:standard output, and standard error (Section 36.15 explains). Without redirection, ch36_16.htm:/dev/tty (Section 36.15). It's easy to redirect any ch36_18.htm:

Figure Section 36.17

ch36_18.htm:lib-glob-aprog.c. You can use sed (Section 34.2) to convert ch36_18.htm:an even better solution can be developed using nawk (Section 20.11). The ch36_18.htm:following example uses find (Section 9.1) to make a list of pathnames, one per line, in ch36_18.htm:sh -v, the shell's verbose option (Section 37.1) ch36_18.htm:status (Section 35.12) -- that might ch36_19.htm:your hereis document (Section 27.16) terminators, there's an ch36_20.htm:

stty Section 5.7, read Section 35.18

ch36_20.htm:

The response is stored in $ans. The trap (Section 35.17) helps to ch36_21.htm:status (Section 35.12) values for ch36_21.htm:output (Section 43.1); if false, it writes ch36_21.htm:Sort of like grep (Section 13.1); ch36_21.htm:expression (Section 32.4) to search for in ch36_21.htm:symbol (Section 32.5) is assumed by ch36_22.htm:

The expr (Section 36.21) command ch36_22.htm:expression (Section 32.4). The string and ch36_22.htm:so on. expr is usually run with backquotes (Section 28.14) to ch36_22.htm:status (Section 35.12). If you want a ch36_22.htm:

/dev/null Section 43.12

ch36_23.htm:(Section 36.21) can grab part of a string with a ch36_23.htm:command-line arguments in a single word. (Using "$@" (Section 35.20) here ch36_23.htm:(Section 21.14) command starts more quickly than ch36_23.htm:

The Bourne shell set (Section 35.25) command can ch36_23.htm:store it in the command-line parameters (Section 35.20) "$@", ch36_23.htm:and so on. Then you can also loop through the words with a for loop (Section 35.21) and ch36_23.htm:(Section 35.25) command to store the fields in ch36_23.htm:stty by the backquotes (Section 28.14). It ch36_23.htm:external command like cut (Section 21.14) or awk ch36_23.htm:(Section 20.10). ch36_23.htm:substitution (Section 28.14) at spaces, ch36_23.htm:escaped parentheses (Section 34.11) to do the searching and the parsing could ch36_23.htm:

The Unix sed (Section 34.1) utility is ch36_23.htm:output of the df (Section 15.8) command. On ch36_23.htm:operators (Section 34.11) ch36_23.htm:eval (Section 27.8) ch36_24.htm:

Section 28.14 introduced command substitution with a pair of ch36_24.htm:the special meaning (Section 27.12) of the ch36_24.htm:

2>&1 Section 36.16

ch36_24.htm:case, the find (Section 9.1) -- is run first. Its output, a list of ch36_24.htm:filenames, is put on the command line of the tar (Section 38.2) command. ch36_24.htm:There's another nice example in Section 24.16. ch36_25.htm:case statement (Section 35.10) has some advantages over the test command (Section 35.26) -- for instance, case ch36_25.htm:matching (Section 35.11) and that ch36_26.htm:Window System (Section 1.22)), give the ch36_26.htm:variable (Section 35.5) is set; if not, it ch36_26.htm:

: Section 36.6, ${..?..} Section 36.7

ch36_26.htm:

`...`Section 28.14

ch36_26.htm:(Section 35.15) is endless because ch36_26.htm:0 (Section 35.12). As long as the user ch36_26.htm:statement (Section 35.13). On the ch36_26.htm:statement (Section 35.10) that tests ch36_26.htm:$? (Section 35.12).) ch36_26.htm:(Section 21.2) ch36_27.htm:and file permissions (Section 50.2) are handled. ch36_27.htm:

2> Section 36.16, /dev/null Section 43.12, set Section 35.25

ch36_27.htm:umask 222 command is run in a subshell (Section 24.4), it ch36_27.htm:(Section 35.15) running. ch37_01.htm:handle #!, use the command set -xv (Section 35.25)). The ch37_01.htm:stdout and stderr (Section 43.4) to the ch37_01.htm:in a file and see it on your screen, too? Use tee (Section 43.8) to copy the ch37_01.htm:shell's output and errors (Section 43.5, Section 27.11) into a ch37_01.htm:temporary file. Use tail -f (Section 12.10) to "watch" ch37_01.htm:two files (Section 43.1). ch37_01.htm:outputs (Section 43.6). Some Bourne shells ch37_02.htm:and displays their values (Section 36.14): ch37_02.htm:value of that variable is displayed; the eval (Section 27.8) command ch37_03.htm:( Section 35.26) can ch37_04.htm:(square bracket) command (Section 35.26) ch37_04.htm:the shell replaces ${var+X} (Section 36.7) with just X and the first ch37_04.htm:

See also Section 37.3 for a brief example of ch37_05.htm:with multiple words. I thought that putting quotes (Section 27.12) around ch37_05.htm:

"$@" Section 35.20

ch37_05.htm:shortcuts" (Section 36.7). Another more generally useful one is ch37_06.htm:mysterious helper programs (Section 1.10)) to take care of this.[120] ch37_07.htm:control (Section 23.3) during the script. ch37_07.htm:different filename, type its pathname (Section 1.16) on the ch37_07.htm:done, type CTRL-d or exit (Section 24.4) at a shell prompt. ch37_07.htm:back" whatever happened by catting (Section 12.2) the ch37_07.htm:or od -c (Section 12.4) will show you these characters.) If the file ch37_07.htm:Section 21.11 and Section 37.8. ch37_07.htm:its menus (Section 5.17). ch37_08.htm:

As Section 37.7 ch37_08.htm:the sed (Section 34.1) substitute command to remove CTRL-m (RETURN) ch37_08.htm:command (Section 34.21) to repeat a series ch37_08.htm:character (Section 5.8), change the ch37_08.htm:sed script has doublequotes (Section 27.12) ch37_08.htm:

eval Section 27.8, exec Section 36.5

ch37_09.htm:(Section 14.5) outputs ch37_09.htm:testing, make it with yes and head (Section 12.12). For ch38_01.htm:

tarring (Section 38.2) files to a tape. ch38_02.htm:archiver, one of its common uses is making an archive file on disk (Section 39.2). Because tar ch38_02.htm:(Section 39.3) can ch38_02.htm:(Section 15.7) than ch38_02.htm:inode information, it can make a more complete copy (Section 10.13) of a file or directory tree than utilities ch38_02.htm:

Yes, we do have articles about archives on tape. Section 38.3 has enough information to make your own ch38_02.htm:archive, although you might need the details from Section 38.5, too. After you've made an ch38_02.htm:least as a test to be sure your archive is okay. Section 38.6 explains how. ch38_02.htm:Section 38.7 about using a drive on another ch38_02.htm:files and directories (Section 39.3). ch38_04.htm:

Section 38.3 ch38_04.htm:

Section 39.2 and Section 39.3 have more information on using ch38_04.htm:RCS (Section 39.5) ch38_04.htm:or CVS (Section 39.7) to save every version of a file you are ch38_05.htm:

As Section 38.3 says, the ch38_05.htm:command can be used directly, as we saw in Section 39.2, to make a backup. For example, the command: ch38_05.htm:Section 39.2. ch38_05.htm:look at the end of Section 21.9.) ch38_05.htm:(Section 38.13) is an archiving utility that packs files ch38_06.htm:use GNU tar (Section 39.3), which allows you to remap pathnames starting ch38_06.htm:that starts with slash (/) or tilde (~) (Section 31.11) (since the shell will expand ch38_06.htm:

rsh Section 1.21

ch38_06.htm:(Section 38.8). ch38_07.htm:tar (Section 38.2) ch38_07.htm:NFS (Section 1.21), you can just rlogin (Section 1.21) to the ch38_07.htm:own files, you can use tar, rsh (Section 1.21), and ch38_07.htm:dd (Section 21.6) to ch38_07.htm:can use man tar (Section 2.1) to refresh your memory. The command to dump ch38_07.htm:machine's name to the remote .rhosts file (Section 1.21) if ch38_08.htm:Section 38.7 about using a tape drive on a ch38_08.htm:

{ } Section 28.4

ch38_08.htm:search path (Section 27.6) for the rsh-command; you ch38_08.htm:like which (Section 2.6)): ch38_09.htm:control system (Section 39.4), but those ch38_09.htm:(Section 9.8) to get ch38_09.htm:another method. For instance, it could copy using rcp (Section 1.21) or simply ch38_09.htm:NFS-mounted filesystem (Section 1.21). ch38_09.htm:

|| Section 35.14, '...' Section 28.14

ch38_10.htm:them (Section 27.12) from the shell, so ch38_10.htm:

'...' Section 28.14

ch38_10.htm:files on the tape. The pattern supplied to egrep (Section 13.4) ch38_10.htm:the files from the archive. Note that these patterns are regular expressions, not wildcards (Section 32.2). ch38_10.htm:with ^ or $ characters (Section 32.4), they can match anywhere in the file ch38_10.htm:have to quote (Section 27.12) the ch38_10.htm:regular expressions (Section 32.2). Unlike ch38_10.htm:

> Section 28.12

ch38_10.htm:expression! (Section 27.18 shows a situation ch38_10.htm:[ (or test) (Section 35.26): ch38_11.htm:pathnames (Section 31.2) when you create a ch38_11.htm:tape, you're stuck. If you use relative paths (Section 31.2) ch38_13.htm:whether BSD tar (Section 38.2, Section 39.2) (tape ch38_13.htm:ships out cpio archives over the Net (Section 1.21). ch38_13.htm:available, including GNU tar (Section 39.3). ch38_13.htm:list of files to be archived is often specified with find (Section 9.1), but it ch39_01.htm:to a tape for safety (Section 38.3). In ch39_01.htm:aware that you can use the backup program tar (Section 38.2) to ch39_02.htm:

tar (Section 38.2) is a ch39_02.htm:

There are other options, which we cover in Section 38.5. Section 38.12 has more ch39_02.htm:Section 39.3 has a lot more about GNU ch39_02.htm:info page (Section 2.9) for tar for more details ch39_02.htm:of the OS; some have a slightly more specific default). Section 38.5 talks about using tar in ch39_02.htm:pathname (Section 1.16) ch39_02.htm:Section 38.11 explains and lists workarounds. ch39_02.htm:tar manpage or info page (Section 2.9) and ch39_03.htm:

Section 15.7 describes how to ch39_03.htm:absolute pathnames (Section 38.11). GNU ch39_04.htm:(Section 11.1) listings of ch39_04.htm:how you ever did without them. Section 39.5 ch39_04.htm:explains how to protect your files with RCS. See Section 39.7 for an introduction to CVS. ch39_05.htm:functions (Section 29.1) with names like ch39_05.htm:more). Section 13.7 and Section 39.6 explain tools for searching RCS files. ch39_05.htm:Section 39.7, which discusses CVS. CVS is ch39_06.htm:that are stored in an RCS (Section 39.5) file. For instance: ch39_06.htm:(Section 13.7) uses ch39_06.htm:in a loop (Section 28.9). The shell loop below gets all the revision ch39_06.htm:(Section 39.5) to send each revision to the pr -h (Section 45.6) command ch39_06.htm:

'...' Section 28.14, > Section 27.12

ch39_06.htm:(Section 12.12) to grab the two highest revision ch39_06.htm:numbers from the rcsrevs output, tail -r (Section 12.9) to ch39_06.htm:Then run rcsdiff to do the comparisons and email (Section 1.21) them to ch39_06.htm:

? Section 28.12

ch39_07.htm:working together on a common set of files. Where RCS (Section 39.5) deals only ch39_07.htm:diff (Section 11.1). ch39_08.htm:in a shell setup file (Section 3.3), I need to set an environment variable (Section 35.3) named ch39_08.htm:

!$ Section 30.3

ch40_08.htm:HTTP, HTTPS, and FTP (Section 40.8). It ch40_10.htm:tar (Section 15.7) ch41_01.htm:that can be accessed through the perldoc (Section 41.10) system. ch41_02.htm:later in Section 41.11. ch41_03.htm:Network (CPAN) (Section 41.11). You can ch41_04.htm:(Section 41.10), scripts ch41_04.htm: @INC (Section 41.2) for these ch41_04.htm:both to get at values that are pointed to by references (Section 41.5.4) and to make ch41_05.htm:while (Section 41.7) ch41_05.htm:(Section 41.7). Although ch41_08.htm:available through modules (Section 41.9). In fact, there are too many Unix-like ch41_09.htm:system (Section 41.11) before you can use ch41_09.htm:reference operator (Section 41.5.4) \. Without a passed ch41_09.htm:use perldoc modulename (Section 41.10) to the module's ch41_09.htm:programmer's sleeve is the Comprehensive Perl Archive Network (Section 41.11) (CPAN), which is the central repository for ch41_11.htm:Section 41.3. If the tests all succeed, change to ch41_12.htm:Perl (Section 41.1), ch41_12.htm:(Section 1.21) messages always use a blank ch41_13.htm:module (Section 41.11) like this: ch42_04.htm:

urllib (Section 42.5) provides basic functions for opening and ch42_04.htm:

urllib2 (Section 42.6) provides an extended, extensible interface ch42_04.htm:

htmllib and HTMLParser (Section 42.7) ch42_04.htm:

cgi (Section 42.8) ch42_04.htm:(Section 42.9) is an ch42_05.htm:client activities is through modules called urllib and urllib2 (Section 42.6). urllib is the simple web ch42_06.htm:(Section 42.5). Underneath, however, ch43_01.htm:(Section 1.21). To ch43_01.htm:to a file. As we said, Unix is file-based (Section 1.19). ch43_01.htm:

Section 36.15 ch43_01.htm:c (see Section 27.16) ch43_01.htm:

We'll discuss commands like this in Section 43.3 and Section 43.5. ch43_01.htm:Bourne shell (Section 36.16). ch43_01.htm:(Section 20.11), support ch43_01.htm:those are symbolic links (Section 10.4) to /proc/self/fd/0, ch43_02.htm:

cat Section 12.2

ch43_02.htm:< character (Section 43.1): ch43_03.htm:command in a subshell (Section 43.7). The standard output of the command is ch43_03.htm:outside the subshell is the standard error; the |& operator (Section 43.5) ch43_03.htm:redirects it (along with the empty standard output) to the mail (Section 1.21) program: ch43_03.htm:(Section 36.15) as the ch43_03.htm:the more complicated syntax (Section 36.16). Here's how to run your ch43_04.htm:(Section 12.3) can be mighty handy. But piping to a ch43_04.htm:and gail/.cshrc are read-protected (Section 50.2). ch43_04.htm:grep writes its errors to the standard error (Section 36.15)! But both ch43_05.htm:

make Section 11.10

ch43_05.htm:tail -f (Section 12.10). If you don't want the ch43_05.htm:Section 43.1. ch43_05.htm:background or on another computer and mailing (Section 1.21) any ch43_06.htm:output (Section 43.1). ch43_06.htm:variable, so any new shells you create won't inherit it (Section 35.9). Therefore, if you want this feature, put the ch43_06.htm:(Section 3.3). ch43_06.htm:redirecting standard output to /dev/null (Section 43.12) or to ch43_07.htm:(Section 24.4) that, in effect, ch43_07.htm:

echo Section 27.5

ch43_07.htm:entire sequence of commands separated by semicolons (;) (Section 28.16) ch43_07.htm:active shell's current directory (Section 24.3): ch43_08.htm:tail -f (Section 12.10). Or use a program like script (Section 37.7). ch43_09.htm:

The tee (Section 43.8) command writes its standard input to a file ch43_09.htm:

> Section 28.12

ch43_09.htm:operators (Section 43.7) collect the ch43_10.htm:%%Pages: at the end of the file. Using bzcat (Section 15.6) to ch43_10.htm:commands into a for loop (Section 28.9) (or put them into a shell script). This loop ch43_10.htm:

-n Section 34.3

ch43_10.htm:

Using process substitution and tee (Section 43.8), I can do ch43_10.htm:CD-ROM [see http://examples.oreilly.com/upt3]. tpipe is similar to tee (Section 43.8), but ch43_10.htm:

You can also simulate tpipe by using awk (Section 20.10). Write a ch43_11.htm:like a file. It has a filename and permissions (Section 1.17), ch43_11.htm:mode like chmod (Section 50.5) uses. To remove a FIFO, ch43_11.htm:xterm (Section 24.20)); you'll write to the ch43_11.htm:background (Section 23.2) and run the reading process in the ch43_11.htm:writing process. If it does, and if your system has job control (Section 23.3), do ch43_11.htm:

-F Section 8.10

ch43_11.htm:cat (Section 12.2) ch43_11.htm:FIFO, here's a little shell script (Section 35.1) ch43_11.htm:

while Section 35.15, ch43_11.htm:sleep Section 24.9

ch43_11.htm:program, like the pr (Section 45.6) formatter with its -l15 ch43_11.htm:see when tail (Section 12.8) reads from a pipe or FIFO? ch43_12.htm:top of" the other file (Section 15.2). ch43_12.htm:

That redirects (Section 43.1) standard output but leaves standard error ch43_12.htm:yes (Section 14.5).) ch43_12.htm:instance, the grep (Section 13.1) programs won't give the name ch43_12.htm:one (Section 9.21): ch43_12.htm:

Section 15.3 shows even more uses for ch43_12.htm:(Section 12.12) will give you a stop!):[133] ch43_12.htm:

od Section 12.4

ch44_01.htm:and disks (Section 44.4, Section 44.5), CD-ROMs (Section 44.6), ch44_01.htm:ethernet cards (Section 44.8), modems ch44_01.htm:(Section 44.10), sound ch44_01.htm:cards (Section 44.13), and so on. Each ch44_01.htm:ifconfig (Section 44.8) for network ch44_01.htm:devices (Section 44.6, Section 44.7), mount ch44_01.htm:(Section 44.9) for disks and so forth. ch44_04.htm:and in /etc/fstab (Section 44.5). ch44_05.htm:manually mounted (Section 44.6)) and a standard procfs. ch44_07.htm:(Section 44.4)). This allows mounting a file as if it ch44_07.htm:size (this is effectively creating a partition (Section 44.4) -- in this case, a 100 megabyte image. ch44_11.htm:connection -- you can use ifconfig (Section 44.8, Section 46.3) to examine it and packets will be routed to ch44_11.htm:the PPP connection by default, and tools like traceroute (Section 46.4) can ch44_11.htm:ISP's DNS (Section 46.9) server. Some implementations of ch44_12.htm:modules (Section 44.3) loaded (and on many ch45_01.htm:

The first few articles in this chapter, Section 45.2, ch45_01.htm:Section 45.3, Section 45.4, and Section 45.5, discuss the basic Unix spooling system and ch45_01.htm:line-printer emulation mode. Section 45.6 ch45_01.htm:describes this kind of simple formatting, and Section 45.7 gets a little more complicated on the same ch45_01.htm:PostScript. They're discussed in Section 45.10 through Section 45.17, along ch45_01.htm:

Finally, Section 45.19 is about the ch45_02.htm:command lpc status (Section 45.3) can be used to determine which printers are ch45_02.htm:variable (Section 45.4). ch45_02.htm:variable (Section 45.4). ch45_03.htm:

The printer daemon (Section 1.10) watches ch45_03.htm:the queue for jobs that people submit with lpr (Section 45.2). If ch45_04.htm:includes lpr (Section 45.2), various scripts to format typeset documents, ch45_04.htm:variable (Section 35.3); if ch45_05.htm:symbolic link (Section 10.4) to your file from the spooling directory. ch45_05.htm:troff file (Section 45.16) for a PostScript ch45_06.htm:

The line printer spooler (Section 45.2) prints what you send it. If you send it a ch45_06.htm:Section 21.15. ch45_06.htm:chopped to fit. See Section 21.15. This is a ch45_06.htm:(Section 21.18). ch45_06.htm:See Section 21.15. ch45_06.htm:(Section 12.13). ch45_06.htm:carriage-return character to be read from /dev/tty (Section 36.15).) ch45_06.htm:cat -n (Section 12.13) to supply the line numbers: ch45_09.htm:However, lpd does know how to run files through a filter (Section 45.17). So what we'll do is provide ch45_10.htm:complex languages (Section 45.14) to print, ch45_10.htm:text (Section 45.7) so it could be ch45_10.htm:

What we will try to cover are formatting languages (Section 45.12 and Section 45.13), printer ch45_10.htm:languages (Section 45.14), and ways to use ch45_10.htm:(Section 45.15 through Section 45.17). ch45_10.htm:OpenOffice, Section 45.18 might help. ch45_13.htm:

Section 45.12 shows an example of a ch45_15.htm:

Section 45.7 introduced one tool that can convert plain ch45_15.htm:a2ps and enscript (Section 45.7) can do what you need. If your printer ch45_15.htm:to get that output to go to the printer properly. Section 45.17 shows how to arrange for most of that to be ch45_16.htm:

Section 45.15 showed the steps necessary to convert plain text into something ch45_16.htm:Section 45.15, because the default options all do what we want. Even ch45_16.htm:so, it can be made even simpler; Section 45.17 ch45_17.htm:

Section 45.15 ch45_17.htm:and Section 45.16 showed what sorts of steps are ch45_17.htm:

In Section 45.9, we used an input filter ch45_19.htm:(Section 1.22) bitmaps out of pictures in newspapers ch45_19.htm:PICT format. Then I ftp (Section 1.21) the file to ch46_01.htm:(Section 46.1). When you ch46_01.htm:telnet, HTTP servers and web browsers, SSH (Section 46.6), and ch46_01.htm:email (Section 46.8). ch46_01.htm:broadcast. Services like DNS (Section 46.9) and DHCP ch46_01.htm:(Section 46.10) use UDP rather than TCP, as do many ch46_01.htm:the like. /etc/services (Section 46.2) lists most of the well-known ports used by ch46_01.htm:ping and traceroute (Section 46.4) to diagnose problems, check network status, ch46_02.htm:the top of your head. SMTP (Section 46.8) is port 25, HTTP is port 80, and so on. ch46_03.htm:(Section 44.8), but it also can be used to see the current ch46_03.htm:can ping (Section 46.4) other machines on your local network, but you ch46_03.htm:point to your gateway (Section 46.11). For a private LAN running NAT (Section 46.11), your ch46_03.htm:DNS (Section 46.9) ch46_04.htm:ping sends one or more ICMP (Section 46.1) Echo ch46_04.htm:you know you don't have a firewall (Section 46.12) ch46_04.htm:trying anything more complex; start looking for interfaces down or routing problems (Section 46.3) or, possibly, unplugged cables or the like. ch46_05.htm:(Section 46.1) and start up the appropriate server ch46_05.htm:firewall (Section 46.12), as it provides extra security by ch46_05.htm:into your machine. As an example, my home firewall allows SMTP (Section 46.8) and ch46_05.htm:SSH (Section 46.6) ch46_05.htm:resolved (Section 46.9), thus requiring a ch46_06.htm:mode, telnet connects to an inetd (Section 46.5)-managed ch46_08.htm:(Section 46.9) for your ch46_09.htm:address (Section 46.1). ch46_09.htm:mail (Section 46.8). ch46_09.htm:(Section 46.3) for anything more complicated than a quick ch46_10.htm:server. Section 46.11 describes NAT, which can ch46_11.htm:(Section 46.12); ch46_11.htm:correct private addresses on the way back in. If you use DHCP (Section 46.10) to configure ch46_11.htm:(Section 44.3) ch46_12.htm:(Section 46.11) ch46_12.htm:(Section 46.1) it is ch46_12.htm:(Section 46.8) port) on the mail server machine, ch46_12.htm:machine, and port 22 (the SSH (Section 46.6) port) on any server that should be able to ch46_13.htm:configure one Unix machine as a gateway (Section 46.11), with ch46_13.htm:(Section 44.11), turn ch46_13.htm:on PPP's NAT (Section 46.11) handling and then turn ch46_13.htm:on gatewaying (Section 46.11). Make sure ch46_13.htm:gateway (handing out addresses via DHCP (Section 46.10) is an easy ch47_02.htm:wish to use the web administration tool SWAT (Section 47.4) to ch47_02.htm:talked about in more detail in Section 47.6. For now, ch47_02.htm:writable by SMB clients that are able to connect (Section 47.6). When ch47_08.htm:creates a private network on your machine so that, with Samba (Section 47.2), you can ch48_01.htm:security checklist (Section 48.2). ch48_02.htm:security alerts (Section 48.3), where to get security patches for your ch48_02.htm:(Section 50.5) on a file: ch48_02.htm:(Section 48.5). ch48_03.htm:(Section 48.2). ch48_03.htm:most current advisory was warning about a potential buffer overflow (Section 48.4) problem related to FreeBSD's ch48_06.htm:problems. Probably the most commonly used utility is ps (Section 24.5); however, ch48_07.htm:

Check logfiles first, and then check for any unusual setgid (Section 49.5) or ch48_07.htm:find (Section 9.1) command. For ch48_07.htm:/etc/passwd and the crontab file (Section 25.3), ch48_09.htm:ps (Section 49.6)), ch48_09.htm:point you can use cat (Section 11.2) to print out the cmdline ch48_12.htm:

The same configuration and TCP wrapper (Section 46.5) -- known as the Wietse ch49_01.htm:usernames and also added to one or more Unix groups (Section 49.7). Both a ch49_08.htm:particularly C shell scripts, as discussed in Section 50.9. And since the scripts can be run by anybody, ch49_13.htm:

You can temporarily disable logins by creating an entry in /etc/nologin (Section 3.1) and ch50_02.htm:accessing files inside that directory. (Section 10.2 has more information ch50_02.htm:the contents of a file. (See Section 50.9.) ch50_02.htm:you don't. (See Section 50.10.) ch50_02.htm:the group (Section 49.6) of the file, and one set for everyone else. ch50_02.htm:specifies the type of file (Section 9.13). The first three of the nine permissions ch50_02.htm:with three octal digits instead of nine characters. (Section 1.17 has diagrams of permission bits and explains ch50_02.htm:don't apply to the superuser (Section 1.18), who ch50_02.htm:mechanism (Section 49.7) to deny one group ch50_02.htm:(Section 50.5) command ch50_02.htm:letters. (See Section 7.5.) ch50_02.htm:some aliases (Section 49.4) defined: ch50_02.htm:different names. Section 31.13 shows how. ch50_02.htm:(Section 9.1) three times a day and search for files owned ch50_02.htm:

$USERSection 35.5, xargsSection 28.17, chmodSection 50.5

ch50_02.htm:(Section 25.2) to ch50_03.htm:change file ownership (Section 50.14, Section 50.15). ch50_03.htm:(Section 50.9). ch50_03.htm:

With an editor like vi (Section 17.2), the file keeps its original owner because a ch50_03.htm:

An editor like Emacs (Section 19.1), which makes a backup copy, can be different. ch50_03.htm:-l (Section 50.2). ch50_04.htm:person (see Section 50.9). Many newer ch50_04.htm:can set its sticky bit (mode (Section 1.17) 1000). The ch50_05.htm:(Section 1.17, ch50_05.htm:Section 50.2), and give a command like this one: ch50_05.htm:

Set exactly this permission (Section 50.6). ch50_05.htm:bit" (Section 50.4, Section 1.17). ch50_05.htm:

(Section 50.2 explains the ch50_05.htm:(Section 9.9, Section 50.6). You won't need this often, ch50_06.htm:owner's group. Section 50.2 ch50_06.htm:have chmod -R, use this find (Section 9.9): ch50_07.htm:chmod +x. Section 50.8 ch50_07.htm:(Section 49.4), you can find some file that might be ch50_07.htm:

"$@"Section 35.20, ${..=..}Section 36.7

ch50_08.htm:(Section 50.7). ch50_09.htm:(Section 1.20), and one of its nagging problems has always ch50_09.htm:umask (Section 49.4) ch50_09.htm:correctly and using chmod (Section 50.5) to fix permissions of existing directories. ch50_09.htm:bit (Section 50.4). ch50_10.htm:

-d Section 8.5

ch50_10.htm:error shown above. Section 31.4 has details.) ch50_10.htm:

In the example above, toria made a hard link (Section 10.5) to ch50_10.htm:keeps the file's i-number (Section 10.2) but a symbolic link doesn't. ch50_10.htm:

This setup can still be a little confusing. For instance, as Section 31.4 explains, the pwd ch50_10.htm:$PWD (Section 35.5) will probably have the ch50_11.htm:the groups command (Section 49.6) to find out what groups a user belongs to: ch50_11.htm:the chgrp (Section 1.17) command: ch50_11.htm:(Section 49.4) first.) ch50_12.htm:ls -l (Section 50.2), but the corrupted file could have the same ch50_12.htm:date (Section 8.2), but ch50_12.htm:

$? Section 35.12

ch50_12.htm:Some software downloading and distribution systems, like RPM (Section 40.11), can do ch50_13.htm:

Figure Section 35.17

ch50_14.htm:restriction is not bogus, because the system supports disk quotas (Section 15.11). If ch50_14.htm:

If you need to change ownership, there is a workaround (Section 50.15) that ch50_15.htm:quotas (Section 15.11) won't let you change the ch50_15.htm:owner (Section 50.14) of a file; only the ch50_15.htm:

-d Section 8.5, -f Section 14.10

ch50_15.htm:same time, su (Section 49.9) is probably the fastest way to change ch50_15.htm:(Section 10.12) command preserves the ch51_01.htm:

Enabling SSH (Section 46.6) on Mac OS X is fairly simple. Access the System ch51_01.htm:file (using sudo (Section 49.11) if you're logged in as a ch51_01.htm:(Section 49.7) or login as root). Remove the pound ch51_01.htm:restart inetd (Section 46.5) by typing: ch51_02.htm:(Section 46.6). SSH encrypts any communication ch51_03.htm:(Section 46.6) is built-in. In other cases you can use ch51_05.htm:ssh (Section 46.6), scp, ssh-agent, ssh-keygen, etc., ch51_06.htm:configurationfiles (Section 6.3). If you ch51_06.htm:subshell) (Section 6.3). ch51_07.htm:client configuration file (Section 7.1). Remember that multiple sections of the gloss.htm:also Section 27.18. gloss.htm:also Section 7.4. gloss.htm:See also Section 15.4. gloss.htm:See Section 3.3.

gloss.htm:notification of incoming mail. See also Section 1.10. gloss.htm:.profile
. See also Section 3.6. gloss.htm:See also Section 27.12 gloss.htm:and Section 27.13. gloss.htm:also Section 23.2. gloss.htm:See also Section 1.10. gloss.htm:Section 3.4. gloss.htm:See also Section 1.17. gloss.htm:also Section 1.21 and Section 44.9. gloss.htm:See Section 35.6.

gloss.htm:processes. See also Section 24.3. gloss.htm:starts. See also Section 24.3. This number allows you to refer to a process gloss.htm:See Section 3.4.

gloss.htm:file you want to execute. See also Section 17.29 and Section 35.6. gloss.htm:programs. See also Section 27.3. gloss.htm:pathname. See also Section 1.16. gloss.htm:Section 27.12 and Section 27.13. gloss.htm:every tape drive. See also Section 1.19. gloss.htm:Section 1.16 and Section 7.7. gloss.htm:See also Section 39.2. gloss.htm:resources. See also Section 24.20.