1. Trang chủ
  2. » Công Nghệ Thông Tin

Classic Shell Scripting phần 7 pps

44 331 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 44
Dung lượng 875,45 KB

Nội dung

265 y Create a soft (symbolic) link existent file $ file two Diagnose this file Find all files ./two Find soft links only $ find . -type l -follow Find soft links and try to ow them : cannot follow symbolic link ./two: No such file or directory hat many h s are selected. If it has a rd ind . -links +1. e. A common idiom is find odified in the last week. $ ls Show that we have an empt directory $ ln -s one two nto a no two: broken symbolic link to one $ find . . $ find . -type l ./two foll indf les having tThe -links option requires a following integer number. If it is unsigned, it selects only fi ard links. If it is negative, only files with fewer than that many (in absolute value) link plus sign, then only files with more than that many links are selected. Thus, the usual way to find files with ha links is f The -atime (access time), -ctime (inode-change time), and -mtime (modification time) options require a following integer number, measured in days. If unsigned, it means exactly that many days old. If negative, it means less than that absolute value. With a plus sign, it means more than that valu find files m . -mtime -7 to It is regrettable that does not allow the number to have a fractional part or a unfind its suffix: we've often wanted to specify units of years, months, weeks, hours, minutes, or seconds with these options. GNU find provides the -amin, -cmin, and -mmin options which take values in minutes, but units suffixes on the original timestamp selection options would have been more general. the specified file. If you need me timestampfile, and then egate the selector: ! -newer timestampfile. n to be taken. They can be th the -a (AND) option if you wish. There is also a -o (OR) option that specifies that at least one selector of the surrounding pair must match. Here are two simple examples of the use of these Boolean es smaller than 10 blocks (5120 bytes) Find files that are empty or unread in the past year A related option, -newer filename, selects only files modified more recently than finer granularity than a day, you can create an empty file with touch -t date_ti use that file with the -newer option. If you want to find files older than that file, n The find command selector options can be combined: all must match for the actio interspersed wi operators: $ find . -size +0 -a -size -10 Find nonempty fil find . -size 0 -o -atime +365 $ Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 266 The -a selecto complex enough that you'll hide them in a script o 10.4.3. So far, we have used find just to produce lists of files matching particular selection requirements, possibly ction 3.2.7.1 and -o operators, together with the grouping options \( and \), can be used to create complex Boolean rs. You'll rarely need them, and when you do, you'll find them nce they are debugged, and then just use that script happily ever after. 2. A simple find script feeding them into a simple pipeline. Now let's look at a slightly more complex example. In Se , we : d commands for converting H s/<H1>/<h1>/g h2>:g s/<[Hh][Tt][Mm][LL]>/<html>/g . X s the task in just a few all HTML filename into variable progress mv $file $file.save Save a backup copy sed -f $HOME/html2xhtml.sed < $file.save > $file Make the change In this section, we develop a real working example of find's virtuosity. [8] presented a simple sed script to (begin to) convert HTML to XHTML Show se $ cat $HOME/html2xhtml.sed TML to XHTML s/<H2>/<h2>/g s:</H1>:</h1>:g s:</H2>:</ s:</[Hh][Tt][Mm][LL]>:</html>:g s:<[Bb][Rr]>:<br/>:g L, the standardized Such a script can automate a large part of the task of converting from HTML to XHTM ML-based version of HTML. Combining sed with find and a simple loop accomplishe lines of code: cd top level web site directory find . -name '*.html' -type f | Find files while read file Read do echo $file Print done 10.4.3.3. A complex find script It is a shell script named rontab filesdirectories that some of our local users with large home-directory trees run nightly via the c system (see Section 13.6.4) to create several lists of files and directories, grouped by the number of days within faster elf. iple output files to be ver a version that which they have been changed. This helps remind them of their recent activities, and provides a much its way to search their trees for particular files by searching a single list file rather than the filesystem [8] Our thanks go to Pieter J. Bowman at the University of Utah for this example. filesdirectories requires GNU find for access to the -fprint option, which permits mult this script o created in one pass through the directory tree, producing a tenfold speedup for used multiple invocations of the original Unix find. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 267 .4 The script begins with the usual security features: specify the - option in the #! line (see Section 2 ): bin/sh - ind for -fprint option export PATH or exit 1 al security feature, the script invokes umask to limit access to the owner of the output files: umask 077 # ensure file privacy It then initializes TMPFILES to a long list of temporary files that collect the output: $TMP/DIRECTORIES.all.$$ $TMP/DIRECTORIES.all.$$.tmp $TMP/DIRECTORIES.last01.$$ $TMP/DIRECTORIES.last01.$$.tmp ES.last02.$$.tmp 7.$$.tmp last14.$$.tmp $TMP/DIRECTORIES.last31.$$ $TMP/DIRECTORIES.last31.$$.tmp MP/FILES.all.$$ $TMP/FILES.all.$$.tmp FILES.last01.$$.tmp $TMP/FILES.last02.$$ $TMP/FILES.last02.$$.tmp $TMP/FILES.last07.$$ $TMP/FILES.last07.$$.tmp $TMP/FILES.last14.$$ $TMP/FILES.last14.$$.tmp $TMP/FILES.last31.$$ $TMP/FILES.last31.$$.tmp " contain the names of directories and files in the entire tree ( *.all.*), as well as the names of t day (*.last01.*), last two days (*.last02.*), and so on. The WD variable saves the argument directory name for later use, and then the script changes to that directory: Changing the working directory before running find solves two problems: #! / set the IFS variable to newline-space-tab: IFS=' ' and set the PATH variable to ensure that GNU find is found first: PATH=/usr/local/bin:/bin:/usr/bin # need GNU f It then checks for the expected single argument, and otherwise, prints a brief error message on standard err and exits with a nonzero status value: if [ $# -ne 1 ] then echo "Usage: $0 directory" >&2 fi As a fin filesdirectories allows the default temporary file directory to be overridden by the TMPDIR environment variable: TMP=${TMPDIR:-/tmp} # allow alternate temporary directory TMPFILES=" $TMP/DIRECTORIES.last02.$$ $TMP/DIRECTORI $TMP/DIRECTORIES.last07.$$ $TMP/DIRECTORIES.last0 $TMP/DIRECTORIES.last14.$$ $TMP/DIRECTORIES. $T $TMP/FILES.last01.$$ $TMP/ ese output files Th those modified in the las WD=$1 cd $WD || exit 1 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 268 ment is not a directory, or is but lacks the needed permissions, then the cd command fails, and the script terminates immediately with a nonzero exit value. w symbolic links unless given extra options, but there is no way to tell it to do so only for the top-level directory. In t is erminates: The exit status value is preserved across the TRap (see Section 13.3.2 • If the argu • If the argument is a symbolic link, cd follows the link to the real location. find does not follo practice, we do not want filesdirectories to follow links in the directory tree, although i straightforward to add an option to do so. The trap commands ensure that the temporary files are removed when the script t trap 'exit 1' HUP INT PIPE QUIT TERM trap 'rm -f $TMPFILES' EXIT EXIT ). The lines with the -name e names of the output files from a previous run, and the -true option causes them to be ignored so ey do not clutter the output reports: IRECTORIES.all -true \ -o -name 'DIRECTORIES.last[0-9][0-9]' -true \ rue \ 0-9][0-9]' -true \ es to $TMP/FILES.all.$$: \ The next five lines select files modified in the last 31, 14, 7, 2, and 1 days (the -type f selector is still in effect), -a -mtime -14 -fprint $TMP/FILES.last14.$$ \ ones, il the next three, so it will be included only in the FILES.last31.$$ and FILES.last14.$$ files. l.$$: r still applies) and S.last31.$$ \ -a -mtime -2 -fprint $TMP/DIRECTORIES.last02.$$ \ TORIES.last01.$$ files, but they have not yet been sorted. The script then finishes the job with a loop over the report files: for i in FILES.all FILES.last31 FILES.last14 FILES.last07 \ S.last01 DIRECTORIES.all \ The wizardry, and all of the hard work, come next in the multiline find command. option match th that th find . \ -name D -o -name FILES.all -t -o -name 'FILES.last[ The next line matches all ordinary files, and the -fprint option writes their nam -o -type f -fprint $TMP/FILES.all.$$ and the -fprint option writes their names to the indicated temporary files: -a -mtime -31 -fprint $TMP/FILES.last31.$$ \ -a -mtime -7 -fprint $TMP/FILES.last07.$$ \ -a -mtime -2 -fprint $TMP/FILES.last02.$$ \ -a -mtime -1 -fprint $TMP/FILES.last01.$$ \ The tests are made in order from oldest to newest because each set of files is a subset of the previous reducing the work at each step. Thus, a ten-day-old file will pass the first two -mtime tests, but will fa The next line matches directories, and the -fprint option writes their names to $TMP/DIRECTORIES.al -o -type d -fprint $TMP/DIRECTORIES.all.$$ \ The final five lines of the find command match subsets of directories (the -type d selecto write their names, just as for files earlier in the command: TORIE -a -mtime -31 -fprint $TMP/DIREC -a -mtime -14 -fprint $TMP/DIRECTORIES.last14.$$ \ -a -mtime -7 -fprint $TMP/DIRECTORIES.last07.$$ \ -a -mtime -1 -fprint $TMP/DIREC e find command finishes, its preliminary reports are available in the temporary When th FILES.last02 FILE DIRECTORIES.last31 DIRECTORIES.last14 \ Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 269 prefix ./ in each report line with the user-specified directory name so that the output files LC_ALL=C sort > $TMP/$i.$$.tmp d to, and avoids surprise iverse environments because our systems differ in their default locales. he loop over the report files: DIRECTORIES.last07 DIRECTORIES.last02 DIRECTORIES.last01 do sed replaces the contain full, rather than relative, pathnames: sed -e "s=^[.]/=$WD/=" -e "s=^[.]$=$WD=" $TMP/$i.$$ | sort orders the results from sed into a temporary file named by the input filename suffixed with .tmp: Setting LC_ALL to C produces the traditional Unix sort order that we have long been use n when more modern locales are set. Using the traditional order is particularly helpful in our and confusio d The cmp command silently checks whether the report file differs from that of a previous run, and if so, replaces the old one: cmp -s $TMP/$i.$$.tmp $i || mv $TMP/$i.$$.tmp $i Otherwise, the temporary file is left for cleanup by the trap handler. The final statement of the script completes t done At runtime, the script terminates via the EXIT trap set earlier. The complete script is collected in filesdirectories Example 10-1. Its structure should be clear enough that t files, such as for files and directories modified in the last quarter, f the -mtime values, you can get reports of files that have not been recently modified, which might be helpful in tracking down obsolete files. iles and directories, and groups of ently modified ones, in a directory tree, creating s in FILES.* and DIRECTORIES.* at top level. es directory t PATH if [ $# -ne 1 ] tory you can easily modify it to add other repor half year, and year. By changing the sign o Example 10-1. A complex shell script for find #! /bin/sh - # Find all f # rec # list # # Usage: # filesdirectori IFS=' ' PATH=/usr/local/bin:/bin:/usr/bin # need GNU find for -fprint option expor then echo "Usage: $0 directory" >&2 exit 1 fi umask 077 # ensure file privacy TMP=${TMPDIR:-/tmp} # allow alternate temporary direc Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 270 $TMP/DIRECTORIES.all.$$ $TMP/DIRECTORIES.all.$$.tmp mp /FILES.last01.$$ $TMP/FILES.last01.$$.tmp $TMP/FILES.last02.$$ $TMP/FILES.last02.$$.tmp .$$.tmp 4.$$.tmp $$ $TMP/FILES.last31.$$.tmp " WD=$1 cd $WD || exit 1 trap 'exit 1' HUP INT PIPE QUIT TERM -name DIRECTORIES.all -true \ -o -name FILES.all -true \ -a -mtime -31 -fprint $TMP/FILES.last31.$$ \ or i in FILES.all FILES.last31 FILES.last14 FILES.last07 \ ES.all \ 14 \ DIRECTORIES.last07 DIRECTORIES.last02 DIRECTORIES.last01 e "s=^[.]$=$WD=" $TMP/$i.$$ | oblem Files TMPFILES=" $TMP/DIRECTORIES.last01.$$ $TMP/DIRECTORIES.last01.$$.tmp $TMP/DIRECTORIES.last02.$$ $TMP/DIRECTORIES.last02.$$.tmp $TMP/DIRECTORIES.last07.$$ $TMP/DIRECTORIES.last07.$$.tmp $TMP/DIRECTORIES.last14.$$ $TMP/DIRECTORIES.last14.$$.t $TMP/DIRECTORIES.last31.$$ $TMP/DIRECTORIES.last31.$$.tmp $TMP/FILES.all.$$ $TMP/FILES.all.$$.tmp $TMP $TMP/FILES.last07.$$ $TMP/FILES.last07 $TMP/FILES.last14.$$ $TMP/FILES.last1 $TMP/FILES.last31. trap 'rm -f $TMPFILES' EXIT find . \ -o -name 'DIRECTORIES.last[0-9][0-9]' -true \ -o -name 'FILES.last[0-9][0-9]' -true \ -o -type f -fprint $TMP/FILES.all.$$ \ -a -mtime -14 -fprint $TMP/FILES.last14.$$ \ -a -mtime -7 -fprint $TMP/FILES.last07.$$ \ -a -mtime -2 -fprint $TMP/FILES.last02.$$ \ -a -mtime -1 -fprint $TMP/FILES.last01.$$ \ -o -type d -fprint $TMP/DIRECTORIES.all.$$ \ -a -mtime -31 -fprint $TMP/DIRECTORIES.last31.$$ \ -a -mtime -14 -fprint $TMP/DIRECTORIES.last14.$$ \ -a -mtime -7 -fprint $TMP/DIRECTORIES.last07.$$ \ -a -mtime -2 -fprint $TMP/DIRECTORIES.last02.$$ \ -a -mtime -1 -fprint $TMP/DIRECTORIES.last01.$$ f FILES.last02 FILES.last01 DIRECTORI DIRECTORIES.last31 DIRECTORIES.last do sed -e "s=^[.]/=$WD/=" - LC_ALL=C sort > $TMP/$i.$$.tmp .$$.tmp $i || mv $TMP/$i.$$.tmp $i cmp -s $TMP/$i one d 10.4.4. Finding Pr Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 271 In Section 10.1, we noted the difficulties presented by filenames containing special characters, such as newline. GNU find has the -print0 option to display filenames as NUL-terminated strings. Since pathnames can legally contain any character except NUL, this option provides a way to produce lists of filenames that can be parsed unambiguously. It is hard to parse such lists with typical Unix tools, most of which assume line-oriented text input. However, in a compiled language with byte-at-a-time input, such as C, C++, or Java, it is straightforward to write a program he presence of problematic filenames in your filesystem. Sometimes they get there by simple isguising For example, suppose that you did a directory listing and got output like this: wo special hidden not have seen any hidden files, and also, there appears to be a space before the first dot in the output. Something -print0 | od -ab Convert NUL-terminated to octal and ASCII 0000000 . nul . / sp . nul . / sp . . nul . / . 056 056 000 056 057 056 . sp . sp nl 012 000 056 057 056 056 040 056 056 040 056 056 040 056 040 012 0000045 e can make this somewhat more readable with the help of tr, turning spaces into S, newlines into N, and NULs into newline: $ find -print0 | tr ' \n\0' 'SN\n' Make problem characters visible and N ./S. ./S ./.N ./ S S S.SNNNSS Now we can see what is going on: we have the normal dot directory, then a file named space-dot, another named ne named dot-dot-space-dot-dot-space-dot- dot-space-dot-space-newline-newline-newline-space-space. Unless someone was practicing Morse code in your f e files look awfully suspicious, and you should investigate them further before you get rid of them. 10.5. Running Commands: xargs en find able to supply that list as arguments to another comma mand substitution feature, as in this example of searching for the symbol POSIX_OPEN_MAX in system header files: grep POSIX_OPEN_MAX /dev/null $(find /usr/include -type f | sort) to diagnose t programmer error, but other times, they are put there by attackers who try to hide their presence by d filenames. $ ls List directory . At first glance, this seems innocuous, since we know that empty directories always contain t option, so we should dotted files for the current and parent directory. However, notice that we did not use the -a is just not right! Let's apply find and od to investigate further: $ find filenames 056 000 056 057 040 056 000 056 057 040 0000020 nl nul . / . . sp . . sp . 0000040 nl nl sp sp nul 012 012 040 040 000 W as S . space-dot-dot, yet another named dot-newline, and finally o ilesystem, thes Wh produces a list of files, it is often useful to be nd. Normally, this is done with the shell's com $ Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 272 /usr/include/limits.h:#define _POSIX_OPEN_MAX 16 W you write a program or a command that deals with a list of objects, you should make sure that it b ments, we supplie roduces no output: that will not happen here, but it is good to develop defensive program The ou es be lengthy, with the result that a nasty kernel limit on t ined length of a command line and its environment variables is exceeded. When that happens, you'll s $ grep POSIX_OPEN_MAX /dev/null $(find /usr/include -type f | sort) /usr/local/bin/grep: Argument list too long. That lim $ get value of AR 31072 On the systems that we tested, the reported values ranged from a low of 24,576 (IBM AIX) to a high of tandard input, one ) to another command given as arguments to xargs. Here is an example that eliminates the obnoxious Argument list too long error: $ find /usr/include -type f | xargs grep POSIX_OPEN_MAX /dev/null nclude/bits/posix1_lim.h:#define _POSIX_OPEN_MAX 16 _POS ing it to print the rted match. If xargs gets no input filenames, it terminates silently without even ng its argument program. has the —null option to handle the NUL-terminated filename lists produced by GNU find's -print0 ption. xargs passes each such filename as a complete argument to the command that it runs, without danger of shell (mis)interpretation or newline confusion; it is then up to that command to handle its arguments sensibly. t awk program, you $ find -ls | awk '{Sum += $7} END {printf("Total: %.0f bytes\n", Sum)}' However, that report underestimates the space used, because files are allocated in fixed-size blocks, and it tells us nothing about the used and available space in the entire filesystem. Two other useful tools provide better solutions: df and du. henever ehave s properly if the list is empty. Because grep reads standard input when it is given no file argu d an argument of /dev/null to ensure that it does not hang waiting for terminal input if find p ming habits. tput from the substituted command can sometim he comb ee this instead: it can be found with getconf: conf ARG_MAX Get system configuration G_MAX 1 1,048,320 (Sun Solaris). The solution to the problem is provided by xargs: it takes a list of arguments on s ARG_MAX per line, and feeds them in suitably sized groups (determined by the host's value of ARG_MAX /usr/i /usr/include/bits/posix1_lim.h:#define _POSIX_FD_SETSIZE IX_OPEN_MAX Here, the argument ensures that grep always sees at least two file arguments, caus /dev/null filename at the start of each repo invoki GNU xargs o xargs has options to control where the arguments are substituted, and to limit the number of arguments passed to one invocation of the argument command. The GNU version can even run multiple argument processes in parallel. However, the simple form shown here suffices most of the time. Consult the xargs(1) manual pages for ls, and for examples of some of the wizardry possible with its fancier features. further detai 10.6. Filesystem Space Information With suitable options, the find and ls commands report file sizes, so with the help of a shor can report how many bytes your files occupy: Total: 23079017 bytes Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 273 lude only local filesystems, excluding network-mounted ones. Here is a typical example from one of our web servers: Filesystem 1K-blocks Used Available Use% Mounted on dev/shm 101089 4421 91449 5% /tmp 32904 269600 12480948 3% /var 32092 1683824 2143444 44% /ww -h (human-readable) option to produce a more compact, but possibly more confusing, il Use% Mounted on 45% / 38M 7.9M 29M 22% /boot 9.7G 6.2G 3.0G 68% /export none 502M 0 502M 0% /dev/shm dev/sda8 99M 4.4M 90M 5% /tmp 3% /var 4% /ww arbitrary, but the presence of the one-line header makes it harder to apply sort . Fortunately, on most systems, the output is only a few lines long. df df [ options ] [ files-or-directories ] Purpose Show the inode or space usage in one or more filesystems. Major options -i Show inode counts rather than space. -k Show space in kilobytes rather than blocks. -l 10.6.1. The df Command df (disk free) gives a one-line summary of used and available space on each mounted filesystem. The units are system-dependent blocks on some systems, and kilobytes on others. Most modern implementations support the - k option to force kilobyte units, and the -l (lowercase L) option to inc $ df -k /dev/sda5 5036284 2135488 2644964 45% / /dev/sda2 38890 8088 28794 22% /boot /dev/sda3 10080520 6457072 3111380 68% /export none 513964 0 513964 0% / /dev/sda8 /dev/sda9 134 /dev/sda6 40 U df provides the GN report: $ df -h Filesystem Size Used Ava /dev/sda5 4.9G 2.1G 2.6G /dev/sda2 /dev/sda3 / /dev/sda9 13G 264M 12G /dev/sda6 3.9G 1.7G 2.1G 4 The output line order may be er while preserving that head Usage Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 274 Lowercase L. Show only local filesystems. Behavior r each file or directory argument, or for all filesystems if there are no such arguments, df produces a one-line header that identifies the output columns, followed by a usage report for the filesystem containing that file or directory. Caveats The output of df varies considerably between systems, making it hard to use reliably in ortable shell scripts. Space reports for remote filesystems may be inaccurate. Fo p df's output is not sorted. Reports represent only a single snapshot that might be quite different a short time later in an active multiuser system. You can supply a list of one or more filesystem names or mount points to limit the output to just those: $ df -lk /dev/sda6 /var For network-mo the column wide en r other software that pa $ df Filesystem /dev/sdd1 17496684 15220472 1387420 92% /export/local df's reports about the free space on remote filesystems may be inaccurate, because of software implementation inconsistencies in accounting for the space reserved for emergency use. Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda6 4032092 1684660 2142608 45% /ww /dev/sda9 13432904 269704 12480844 3% /var unted filesystems, entries in the Filesystem column are prefixed by hostname:, making ough that some df implementations split the display into two lines, which is a nuisance fo rses the output. Here's an example from a Sun Solaris system: 1k-blocks Used Available Use% Mounted on fs:/export/home/0075 35197586 33528481 1317130 97% /a/fs/export/home/0075 In Section B.4.3 in Appendix B, we disc that is set when the filesystem is created uss the issue that the inode table in a filesystem has an immutable size . The -i (inode units) option provides a way to assess inode usage. Here Filesystem Inodes IUsed IFree IUse% Mounted on /de / /dev/sda2 10040 35 10005 1% /boot /dev/sda3 1281696 229304 1052392 18% /export none 128491 1 128490 1% /dev/shm /dev/sda8 26104 144 25960 1% /tmp 996 1705884 1% /var /dev/sda6 513024 218937 294087 43% /ww ape, since its inode use and filesystem space are both just over 40 percent e on all local is an example, from the same web server: $ df -i v sda5 640000 106991 533009 17% / /dev/sda9 1706880 The /ww filesystem is in excellent sh of capacity. For a healthy computing system, system managers should routinely monitor inode usag filesystems. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com [...]... "" last = $1 print }' Here is what its output looks like on a GNU/Linux system: $ show-identical-files /bin/* 2df30 875 121b9 276 7259e89282dd3002 2df30 875 121b9 276 7259e89282dd3002 /bin/ed /bin/red 43252d689938f4d6a513a2f 571 786aa1 43252d689938f4d6a513a2f 571 786aa1 43252d689938f4d6a513a2f 571 786aa1 /bin/awk /bin/gawk /bin/gawk-3.1.0 We can conclude, for example, that ed and red are identical programs on this... web page that looks like this: Public Key Server Get ''0xD333CBA1 '' -BEGIN PGP PUBLIC KEY BLOCK Version: PGP Key Server 0.9.6 mQGiBDftyYoRBACvICTt5AWe7kdbRtJ37IZ+ED5tBA/IbISfqUPO+HmL/J9JSfkV QHbdQR5dj5mrU6BY5YOY7L4KOS6lH3AgvsZ/NhkDBraBPgnMkpDqFb7z4keCIebb -END PGP PUBLIC KEY BLOCK Finally, save the key text in a temporary file—say, temp.key—and add it to your key ring: $ gpg import temp.key... fullname homedir shell do if read user2 passwd2 uid2 gid2 fullname2 homedir2 shell2 then if [ $user = $user2 ] then printf "%s\t%s\t%s\n" $user $uid $uid2 >> old-new-list echo "$user:$passwd:$uid2:$gid:$fullname:$homedir: $shell" else echo $0: out of sync: $user and $user2 >&2 exit 1 fi else echo $0: no duplicate for $user >&2 exit 1 fi done < dupusers > unique2 IFS=$old_ifs We use the shell' s read command... -O - "http://pgp.mit.edu:11 371 /pks/lookup?op=get&search=$g" > $tmpfile 282 ls -l $tmpfile Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com echo "Try: pgp -ka $tmpfile" echo " pgpgpg -ka $tmpfile" echo " rm -f $tmpfile" done Here is an example of its use: $ getpubkey D333CBA1 Get the public key for key ID D333CBA1 -rw-rw-r 1 jones jones 45 67 Apr 6 07: 26 /tmp/pgp-0xD333CBA1.tmp.21649... on an out-of-the-box system, but all are easy to build and install Their output formats differ, but here is a typical example: $ md5sum /bin/l? 696a4fa5a98b81b066422a39204ffea4 /bin/ln cd 676 1364e3350d010c834ce1146 477 9 /bin/lp 351f5eab0baa6eddae391f84d0a6c192 /bin/ls The long hexadecimal signature string is just a many-digit integer that is computed from all of the bytes of the file in such a way as... > unique-ids rm -f old-new-list old_ifs=$IFS IFS=: while read user passwd uid gid fullname homedir shell do if read user2 passwd2 uid2 gid2 fullname2 homedir2 shell2 then if [ $user = $user2 ] then printf "%s\t%s\t%s\n" $user $uid $uid2 >> old-new-list echo "$user:$passwd:$uid2:$gid:$fullname:$homedir: $shell" else echo $0: out of sync: $user and $user2 >&2 exit 1 fi else echo $0: no duplicate for $user... Spellchecking This chapter uses the task of spellchecking to demonstrate several different dimensions of shell scripting After introducing the spell program, we show how a simple but useful spellchecker can be constructed almost entirely out of stock Unix tools We then proceed to show how simple shell scripts can be used to modify the output of two freely available spellchecking programs to produce... answer: $ cp /bin/ls /tmp Make a private copy of /bin/ls 276 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com $ cmp /bin/ls /tmp/ls Compare the original with the copy No output means that the files are identical $ cmp /bin/cp /bin/ls Compare different files Output identifies the location /bin/cp /bin/ls differ: char 27, line 1 of the first difference cmp is silent when its two... Merge and Split due at ????-??-?? gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner Primary key fingerprint: D70D 9D25 AF38 37A5 909A 4683 FDD2 DEAC D333 CBA1 The warning in the successful verification simply means that you have not certified that the signer's key really does belong to him Unless you personally know... apply them Here is how patch can convert the contents of test.1 to match those of test.2: $ diff -c test.[12] > test.dif Save a context difference in test.dif $ patch < test.dif Apply the differences 277 patching file test.1 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com $ cat test.1 Test 2 Show the patched test.1 file patch applies as many of the differences as it can; it . looks like on a GNU/Linux system: 2df30 875 121b9 276 7259e89282dd3002 /bin/ed 43252d689938f4d6a513a2f 571 786aa1 /bin/awk 3252d689938f4d6a513a2f 571 786aa1 /bin/gawk /bin/gawk-3.1.0 ay still. system: 1k-blocks Used Available Use% Mounted on fs:/export/home/0 075 351 975 86 33528481 13 171 30 97% /a/fs/export/home/0 075 In Section B.4.3 in Appendix B, we disc that is set when the. awk '{ print $ show-identical-files /bin/* 2df30 875 121b9 276 7259e89282dd3002 /bin/red 4 43252d689938f4d6a513a2f 571 786aa1 We can conclude, for example, that ed and red are identical

Ngày đăng: 12/08/2014, 10:22

TỪ KHÓA LIÊN QUAN