ch01_04.htm:For example, if you are calling grep (Section 13.1), a program for searching through files for a ch01_05.htm:are even exceptions to this exception. A program like less (Section 12.3) can read ch01_09.htm:(Section 1.16) beginning with /, like ch01_10.htm:the ps x (Section 24.5) ch02_01.htm:man command may understand the MANPATH (Section 3.21) environment variable, a list of where ch02_04.htm:
Your manpage files may be compressed (Section 15.6). In ch02_06.htm:Which command you'll get depends on your PATH (Section 35.6) 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, ch03_03.htm:( Section 35.3) like HOME, PATH, SHELL, TERM, MAIL, and ch03_03.htm:(Section 29.2) should, ch03_03.htm:/etc/csh.cshrc,[5] and for ch03_03.htm:present. The .profile can set the ENV (Section 35.5) 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:(Section 35.3) that might ch03_09.htm:(Section 24.4) (like the one that which ch03_10.htm: Bourne-type shells use case (Section 35.10) and ch03_10.htm:TERM environment variable (Section 3.11). Testing other 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:obscure tset (Section 5.3) program ch03_10.htm:that sets the terminal type is qterm (Section 5.4). ch03_13.htm:and ssh (Section 1.21), ch03_18.htm:
As Section 4.1 explains, the simplest ch04_02.htm:
Notice the single quotes (Section 11.3) ch04_06.htm:
Section 4.3 has examples of some shells' ch04_06.htm:(Section 28.5) like :t; the Korn Shell, ch04_06.htm:is a case statement (Section 35.11) that ch04_06.htm:prompt string is inside double quotes (Section 27.12) ch04_08.htm:(Section 1.21), ch04_10.htm:later. (The GNU dircolors (Section 8.6) ch04_14.htm:.tcshrc to make a multiline prompt (Section 4.7) that shows the directory stack: ch04_15.htm:(Section 24.3) of the background shell. Before you log out, ch04_16.htm:uptime (Section 26.4) every ch04_18.htm:
Section 4.17 ch05_03.htm:the value determined for the terminal type to standard output (Section 43.1). ch05_03.htm:(Section 28.14) surrounding ch05_03.htm:also allow you to set the TERMCAP variable (Section 35.5). (You 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:(by NFS) (Section 1.21)? ch05_06.htm:
Enter the command kill PID (Section 24.12), where ch05_08.htm:stty (Section 5.7) ch05_11.htm:Options menu (Section 5.17) by holding ch05_14.htm:charClass resource variable (Section 6.3). The value this resource accepts is a ch05_17.htm:
Note that a Release 5 patch (Section 20.9) has ch05_18.htm:
The xterm VT Fonts menu (Section 5.17) ch05_18.htm:constant-width fonts shown in Table 5-4. ch05_21.htm:vi filter-through (Section 17.18): 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 ch07_03.htm:(Section 50.2) for 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_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:(Section 12.4) command ch08_10.htm:or -A option (Section 8.9) ch08_12.htm:-b option.[37] This ch08_13.htm:
I use awk (Section 20.10) a lot. One ch08_15.htm:
If your system doesn't have a head ( Section 12.12) command, use sed 1q ch08_17.htm:
Use a + parameter and backquotes (``) (Section 28.14) to get a temp file named for the current date ch09_09.htm:
The C shell (Section 29.1) uses ch09_19.htm:(Section 1.13) (* , ch10_05.htm:ln command creates both hard and soft (symbolic) links (Section 10.4). If by some strange chance ch10_05.htm:
Note that symbolic links can get out-of-date (Section 10.6). 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_07.htm:(Section 10.5) (a.k.a. ch10_07.htm:
But when I do a pwd,[42] I see that ch10_10.htm:
Section 10.9 shows how to rename a set of files, e.g., ch10_12.htm:-r option. But it also has an rcp (Section 1.21) command that does have ch10_13.htm:&& operator (Section 35.14) tells the shell to start tar xvf ch10_13.htm:(Section 1.21) or ssh, you can run either ch11_03.htm:Incidentally, these examples would also work with cvs diff (Section 39.7), if you ch11_07.htm:(Section 11.1); it tells ch11_07.htm:(Section 35.12) that ch11_11.htm:NIS (Section 1.21) (formerly called YP, or ch12_04.htm:(Section 13.15) program finds printable strings of characters ch12_07.htm:( Many versions of less (Section 12.3) and ch12_11.htm:(Section 25.2) job to rotate log files (rename the files, ch13_02.htm:
grep is also often used as a filter (Section 1.5), to ch13_02.htm:( Section 24.5) and ch13_05.htm:
egrep (Section 13.4) lets you look ch13_10.htm:(Section 27.17) to ch13_11.htm:mechanism (Section 30.2) and ch13_11.htm:
[Yes, you can do the exact same thing with multiple grep -v (Section 13.3) commands, 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:
Use revision control (Section 39.4). ch14_08.htm:
Using noclobber (Section 43.6) and ch14_08.htm:-i file in your home directory and hard link (Section 15.4) ch14_09.htm:via a cron (Section 25.2) entry like ch14_10.htm:
Normally, rm's exit status (Section 35.12) is 0 if ch14_14.htm:The ls -q (Section 8.12) ch14_14.htm:You can see exactly what the filename is by using ls -b (Section 8.12): ch14_15.htm:( Section 9.25) for ch14_17.htm:find commands to your crontab file (Section 25.2). ch14_18.htm:( Section 28.14) ch14_18.htm:(Section 13.3) command, and then use backquotes to give the ch15_09.htm:in the current directory and below. It uses find (Section 9.2) to ch16_02.htm:
The original Unix spell-checking program, spell (Section 15.1), is fine ch16_03.htm:
If you're using ispell ( Section 16.2) or the newer aspell, you ch16_04.htm:and sort -u ( Section 22.6) to remove ch16_05.htm:
ispell (Section 16.2) ch16_05.htm:ispell -a (Section 16.3) option. ch16_06.htm:ls command is aliased (Section 29.2) to ch16_06.htm:(Section 15.8) command gives accurate disk usage. ch16_07.htm:tr (Section 21.11): ch16_09.htm:(Section 21.11) has slightly different syntax. ch17_01.htm:(Section 19.1)? That's because 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_08.htm:patterns (Section 32.1). For example: ch17_13.htm:blocks of text delimited by patterns (Section 17.8). For ch17_18.htm:(Section 21.11) ch17_21.htm:(Section 23.3), that works on most Unix systems. Job control ch17_25.htm:
Abbreviations (Section 17.23) ch17_28.htm:of your lines too short or long? The fmt (Section 21.2) utility ch17_30.htm:are RETURNs. Make them by pressing CTRL-v, then RETURN (Section 18.6). Lines that start with a double quote ch18_02.htm:(Section 5.2) defines those keys. For example, to make ch18_07.htm:
Another way to do this is with @-functions (Section 18.4). ch19_02.htm:completions (Section 19.6). So if you're creating a ch19_02.htm:has very good integration with XEmacs (neè Lucent Emacs) and ch19_09.htm:( Section 1.16), starting ch20_01.htm:
sed (Section 34.1) is an editor that can 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_05.htm:(Section 34.1) is ch20_09.htm:(Section 11.1) ch21_03.htm:
fmt (Section 21.2) is hard to do without once ch21_08.htm:
In vi, you can use a filter-through (Section 17.18) ch21_10.htm: Like split (Section 21.9), ch21_10.htm:period is a metacharacter (Section 32.21) ch21_10.htm:
breaks the list into 19 segments of 10 lines each.[63] ch21_11.htm:
As described in Section 17.18, this translation (and the reverse) can be ch21_12.htm:a compressed file (Section 15.6) ch21_12.htm:headers, so you should strip off the header first. The behead (Section 21.5) script ch21_15.htm:compare a directory with its RCS (Section 39.5) ch22_03.htm:
Section 22.2 ch22_07.htm:(Section 20.10) to print ch23_01.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:(Section 23.1) features (processes that are running in the ch24_04.htm:
If your parent shell has job control (Section 23.3), ch24_06.htm:
In Section 24.5, we pointed out that the ps ch24_07.htm:orphans (Section 24.19). If you have a serious runaway process ch24_09.htm:(Section 36.15) are currently pointing to. This ch24_09.htm:(Section 35.3) to ch24_10.htm:
It can trap (Section 35.17) the signal ch24_11.htm:(Section 24.10) will 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_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:(Section 1.18) to kill someone else's ch24_13.htm:(Section 35.17) command to catch several different signals ch24_13.htm:runs lpq (Section 45.2) on all ch24_14.htm:
On many Unix systems, kill (Section 24.12) interprets 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_17.htm:processes forking (Section 24.2) out of ch24_17.htm:(Section 23.3), there's a good answer: use ch24_19.htm:hold on to its name and exit status (Section 35.12). ch24_20.htm:(Section 24.12) a hung window or a process in a window. ch25_01.htm: cron (Section 25.2) system ch25_01.htm:at (Section 25.5) command is ideally suited. ch25_02.htm:(Section 43.1), ch25_02.htm:( Section 1.10). What to 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_05.htm:(Section 26.1) process that will monopolize the CPU from ch26_07.htm:(Section 24.3), as shown by ps -l; this ch27_03.htm:
As Section 26.6 explains, if the shell is trying to run a ch27_06.htm: Your search path (Section 35.6, 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_08.htm:you read the previous article (Section 27.7), you saw that, most of the time, the shell ch27_09.htm:command ( Section 1.9), or an ch27_11.htm:( Section 43.1) to a file: ch27_12.htm:substitution (Section 28.14). ch27_12.htm:substitution (Section 35.9, Section 35.3) and command ch27_12.htm:substitution (Section 28.14) inside 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_16.htm:anonymous ftp (Section 1.21)[84] from a shell script: ch27_17.htm:
Table 27-3 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_04.htm:
To send a mail (Section 1.21) message to 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_08.htm:loops (Section 28.9) can vary the commands they run by picking a ch28_08.htm:(Section 28.11). ch28_09.htm:(Section 30.5): ch28_09.htm:operators (Section 28.4). For ch28_09.htm:command (Section 35.18). It reads ch28_12.htm:programming constructs for non-programmers, the for and foreach loops (Section 28.9), work. While ch28_13.htm:(Section 28.9) that prints ch28_14.htm:(Section 2.8). The who output also lists ch28_14.htm:(Section 21.14): ch28_14.htm: (Section 36.24) the backquotes -- this is where the ch28_15.htm:(Section 28.17). If your system doesn't have ch28_16.htm:
It's useful with sleep (Section 25.9) to run a command after a delay. The next ch28_17.htm:arguments. The shell's backquotes (Section 28.14) do the ch28_18.htm:Expect scripts work great as CGI scripts or from cron (Section 25.2) or ch29_02.htm:function (Section 29.11). ch29_02.htm:(Section 3.3), so putting ch29_04.htm:operator (Section 29.3) does. To ch29_04.htm:(Section 29.11). ch29_07.htm:command-line arguments into a variable and then source (Section 35.29) a script to ch29_11.htm:(Section 29.2). ch29_11.htm:(Section 35.20) is ch29_11.htm:$1, the second in $2, and so on (Section 35.20). ch29_11.htm:(Section 35.12) to the ch29_12.htm:
Section 27.11 introduces shell functions for all Bourne-type ch29_12.htm:(Section 29.11): ch29_13.htm:(Section 35.6). So you can 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: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_05.htm:(Section 30.11) to recall an earlier command so I can change ch30_07.htm:prompt (Section 4.3). Then you can ch30_08.htm:
^xy^yx is the shorthand substitution (Section 30.3, Section 30.5) command. In ch30_12.htm:
[95]xterm -ls (Section 5.10 runs a ch30_14.htm:
If you know the Emacs (Section 19.1) editor, ch30_16.htm:(Section 1.21) command), you can type a backslash ch31_03.htm:(Section 1.16). Without a current directory and relative ch31_05.htm:
Some people make a shell alias (Section 29.2) for ch31_05.htm:directories (Section 1.16). This ch31_06.htm:
Normally a for loop (Section 35.21) iterates ch31_08.htm:
The pushd command (Section 31.7) ch32_03.htm:(Section 13.2) that accept regular expressions must first ch32_05.htm:ed and sed. cat -v -e (Section 12.5, Section 12.4) marks ends of lines with a ch33_01.htm: (Section 1.13) ch33_02.htm:( Section 27.12, ch33_06.htm: when you run grep (Section 13.1) on a group ch33_07.htm:(Section 13.2) option -c to tell you how ch34_04.htm:loop (Section 35.21) to apply the ch34_04.htm:(Section 8.2) ch34_05.htm:expression (Section 32.4) that describes a pattern. ch34_14.htm:it works, see Section 34.17. ch34_16.htm:
Most programs that use regular expressions (Section 32.4) are able to match a pattern only on a single ch34_18.htm:
[Section 13.9 introduced a script called ch34_18.htm:(Section 35.19) to ch34_19.htm:d, deletes the contents of the pattern space (Section 34.14) and ch34_24.htm:
Feeding sed (Section 34.1) ch34_24.htm:(Section 27.12). 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:be in your shell's command search path (Section 35.6, Section 35.7). In that case, ch35_03.htm:(Section 5.2) ch35_03.htm:
The set (Section 35.9) command provides a similar listing of shell 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:PRINTER (Section 45.4) or LPDEST ch35_05.htm:HOME (Section 31.11) (called LOGDIR on some systems) ch35_05.htm:program like less (Section 12.3) or ch35_05.htm:more. (Programs like man (Section 2.1) use ch35_05.htm:PS2 (Section 28.12) ch35_05.htm:MANPATH (Section 3.21) ch35_10.htm:Here's an example that tests your TERM (Section 5.2) ch35_11.htm:
A case statement (Section 35.10) is good at ch35_11.htm:the pattern What now?. The quotes (Section 27.12) tell the ch35_13.htm:special null command, a colon (:) (Section 36.6). ch35_14.htm:write an "inverse if (Section 35.13)): ch35_16.htm:
#!/bin/sh ch35_17.htm:your interrupt key (Section 5.8) ch35_20.htm:reading this series (Section 35.2) of ch35_21.htm:The getopt and getopts (Section 35.24) commands handle command-line arguments in a ch35_25.htm:(Section 2.8) and cut ch35_29.htm:
As Section 35.4 explains, Unix programs can never, ch35_30.htm:
So far, we have discussed some shell function basics (Section 29.11), using examples such as the mx( ch36_01.htm:executable with #! on ch36_03.htm:
Let's run both commands and time (Section 26.2) them. ch36_04.htm:
As Section 36.3 ch36_05.htm:
exec also manipulates file descriptors (Section 36.16) in the Bourne shell. When you use ch36_06.htm:if ( Section 35.13) but ch36_08.htm:links (Section 10.4, Section 10.3) to it instead. The program can find the name ch36_10.htm:
The shift (Section 35.22) command ch36_15.htm:
When Unix starts a new subprocess (Section 24.3), the ch36_21.htm:Sort of like grep (Section 13.1); ch36_22.htm:
The expr (Section 36.21) command ch36_22.htm:so on. expr is usually run with backquotes (Section 28.14) to ch36_23.htm:(Section 36.21) can grab part of a string with a 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:
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_24.htm:
Section 28.14 introduced command substitution with a pair of ch36_26.htm:(Section 35.15) is endless because ch36_26.htm:statement (Section 35.13). On the ch36_26.htm:statement (Section 35.10) that tests ch36_26.htm:(Section 21.2) ch36_27.htm:and file permissions (Section 50.2) are handled. ch36_27.htm:(Section 35.15) running. ch37_03.htm:( Section 35.26) can ch37_05.htm:
ch37_05.htm:shortcuts" (Section 36.7). Another more generally useful one is ch37_08.htm:foreach arg ($argv:q) # colon q ?!?As Section 37.7 ch37_09.htm:(Section 14.5) outputs ch37_09.htm:testing, make it with yes and head (Section 12.12). For 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_04.htm:
Section 38.3 ch38_05.htm:(Section 38.13) is an archiving utility that packs files ch38_07.htm:NFS (Section 1.21), you can just rlogin (Section 1.21) to the ch38_09.htm:(Section 9.8) to get ch38_10.htm:files on the tape. The pattern supplied to egrep (Section 13.4) ch38_10.htm:have to quote (Section 27.12) the ch39_01.htm:aware that you can use the backup program tar (Section 38.2) to ch39_04.htm:(Section 11.1) listings of ch39_06.htm:(Section 13.7) uses ch39_06.htm:Then run rcsdiff to do the comparisons and email (Section 1.21) them to ch41_01.htm:
Perl[123] is 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:
Like many other languages, Perl supports Boolean operators (see Table 41-3) that return true or false values. Typically, ch41_05.htm:
Looking at Table 41-4, ch41_05.htm:(Section 41.7). Although 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:(Section 42.9) is an ch43_01.htm:terminal.[127] Likewise, if a ch43_01.htm:(Section 1.21). To ch43_01.htm:(Section 20.11), support ch43_02.htm:< character (Section 43.1): ch43_04.htm:grep writes its errors to the standard error (Section 36.15)! But both ch43_05.htm:tail -f (Section 12.10). If you don't want the ch43_10.htm:
Using process substitution and tee (Section 43.8), I can do ch43_12.htm:/dev/null is a Unix device.[132] It's not a ch44_02.htm:
listing:[134] ch50_02.htm:(Section 50.5) command ch50_02.htm:(Section 9.1) three times a day and search for files owned ch50_02.htm:(Section 25.2) to ch50_05.htm:(Section 1.17, ch50_05.htm:(Section 9.9, Section 50.6). You won't need this often, ch50_09.htm:(Section 1.20), and one of its nagging problems has always ch51_01.htm:# FreeBSD ch45_03.htm:The printer daemon (Section 1.10) watches ch45_06.htm:
The line printer spooler (Section 45.2) prints what you send it. If you send it a 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_13.htm:
Section 45.12 shows an example of a ch45_15.htm:
Section 45.7 introduced one tool that can convert plain ch45_16.htm:
Section 45.15 showed the steps necessary to convert plain text into something ch45_17.htm:
Section 45.15 ch46_01.htm:(Section 46.1). When you ch46_03.htm:(Section 44.8), but it also can be used to see the current ch46_08.htm:(Section 46.9) for your ch46_09.htm:address (Section 46.1). ch46_09.htm:(Section 46.3) for anything more complicated than a quick 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_13.htm:(Section 44.11), turn ch47_02.htm:wish to use the web administration tool SWAT (Section 47.4) to ch48_02.htm:(Section 50.5) on a file: ch48_02.htm:(Section 48.5). ch48_03.htm:(Section 48.2). ch48_07.htm:find (Section 9.1) command. For ch48_12.htm:
The same configuration and TCP wrapper (Section 46.5) -- known as the Wietse ch49_13.htm:
You can temporarily disable logins by creating an entry in /etc/nologin (Section 3.1) and ch50_02.htm:-l
Enabling SSH (Section 46.6) on Mac OS X is fairly simple. Access the System ch51_03.htm:(Section 46.6) is built-in. In other cases you can use