用于一些简单常用的SHELL用法。 
                           
                          如何实现取出文件中特定的行内容 代码:  
                           
                          如果你只想看文件的前5行,可以使用head命令,  
                          如: head -5 /etc/passwd  
                           
                          如果你想查看文件的后10行,可以使用tail命令,  
                          如: tail -10 /etc/passwd  
                           
                          你知道怎么查看文件中间一段吗?你可以使用sed命令  
                          如: sed -n '5,10p' /etc/passwd 这样你就可以只查看文件的第5行到第10行。  
                            
                           
                          如何查找含特定字符串的文件 代码:  
                           
                          例如查找当前目录下含有"the string you want find..."字符串的文件:  
                            $find . -type f -exec grep "the string you want find..." {}  -print   
                           
                          如何列出目录树代码:  
                           
                          下面的短小的shell程序可以列出目录树, 充分利用了sed强大的模式匹配能力.  
                            目录树形式如下:  
                            .  
                            `----shellp  
                            `----updates  
                            `----wu-ftpd-2.4  
                            | `----doc  
                            | | `----examples  
                            | `----src  
                            | | `----config  
                            | | `----makefiles  
                            | `----support  
                            | | `----makefiles  
                            | | `----man  
                            | `----util  
                            脚本如下:  
                            #!/bin/sh  
                            # dtree: Usage: dtree [any directory]  
                            dir=${1:-.}  
                            (cd $dir; pwd)  
                            find $dir -type d -print | sort -f | sed -e "s,^$1,," -e "/^$/d" -e "s,[^/]*/([^/]*)$,`----1," -e "s,[^/]*/,| ,g"   
                           
                          如何实现取出文件中特定的列内容 代码:  
                           
                          我们经常会遇到需要取出分字段的文件的某些特定字段,例如/etc/password就是通过":"分隔各个字段的。可以通过cut命令来实现。例如,我们希望将系统账号名保存到特定的文件,就可以:  
                            cut -d: -f 1 /etc/passwd > /tmp/users  
                            -d用来定义分隔符,默认为tab键,-f表示需要取得哪个字段。  
                            当然也可以通过cut取得文件中每行中特定的几个字符,例如:  
                            cut -c3-5 /etc/passwd  
                            就是输出/etc/passwd文件中每行的第三到第五个字符。  
                            -c 和 -f 参数可以跟以下子参数:  
                            N 第N个字符或字段  
                            N- 从第一个字符或字段到文件结束  
                            N-M 从第N个到第M个字符或字段  
                            -M 从第一个到第N个字符或字段   
                           
                          在vim中实现批量加密 代码:  
                           
                          密码中还是不能带空格,不管了,能加密就好,先这么用着。  
                           
                          ============================================================  
                          #!/bin/bash  
                          # Encrypt file with vim  
                           
                          if (test $# -lt 2) then  
                              echo Usage: decrypt password filename  
                          else  
                              vim -e -s -c ":set key=$1" -c ':wq' $2  
                              echo "$2 encrypted."  
                          fi  
                          ============================================================  
                          [weeder@SMTH weeder]$ for file in *.txt  do encrypt test $file  done  
                          test2.txt encrypted.  
                          test4.txt encrypted.  
                          test9.txt encrypted.  
                          kick.txt encrypted.  
                              echo "$2 encrypted."  
                          fi  
                          [weeder@SMTH weeder]$ for file in *.txt  do encrypt test $file  done  
                          test2.txt encrypted.  
                          test4.txt encrypted.  
                          test9.txt encrypted.  
                          kick.txt encrypted.  
                          too_old.txt encrypted.  
                          too_old_again.txt encrypted.  
                          bg5.txt encrypted.  
                          [weeder@SMTH weeder]$   
                           
                          $@等特定shell变量的含义 代码:  
                           
                          在shell脚本的实际编写中,有一些特殊的变量十分有用:  
                          $# 传递到脚本的参数个数  
                           
                          $* 以一个单字符串显示所有向脚本传递的参数。与位置变量不同,此选项参数可超过9个  
                           
                          $$ 脚本运行的当前进程ID号  
                           
                          $! 后台运行的最后一个进程的进程ID号  
                           
                          $@ 与$#相同,但是使用时加引号,并在引号中返回每个参数  
                           
                          $- 显示shell使用的当前选项,与set命令功能相同  
                           
                          $? 显示最后命令的退出状态。0表示没有错误,其他任何值表明有错误。  
                            
                           
                          如何使程序的执行结果同时定向到屏幕和文件 代码:  
                           
                          program_name |tee logfile  
                          这样程序执行期间的显示都记录到logfile同时显示到标准输出(屏幕)。   
                           
                          如何用sendmail给系统所有用户送信代码:  
                           
                          首先在aliases文件里面建立一个alias:  
                          alluser: :include:/etc/mail/allusers  
                          并执行newaliases使之生效,然后在/etc/mail/allusers里面列出所有用户,可以使用下面的命令:  
                          awk -F: '$3 > 100 { print $1 }' /etc/passwd > /etc/mail/allusers  
                           
                          如何查找某条命令的相关库文件 代码:  
                           
                          在制作自己的发行版时经常需要判断某条命令需要哪些库文件的支持,以确保指定的命令在独立的系统内可以可靠的运行。  
                          在Linux环境下通过ldd命令即可实现,在控制台执行:  
                          ldd /bin/ls  
                          即可得到/bin/ls命令的相关库文件列表。   
                           
                          如何使用host命令获得更多信息 代码:  
                           
                          Host能够用来查询域名,然而它可以得到更多的信息。host -t mx linux.com可以查询出Linux.com的MX记录,以及处理Mail的Host的名字。Host -l linux.com会返回所有注册在linux.com下的域名。host -a linux.com则会显示这个主机的所有域名信息。   
                           
                          如何停止终端多个进程 代码:  
                           
                          以下是脚本:  
                            echo "系统当前用户"  
                            echo "---------------"  
                            who | awk '{print $2}'  
                            echo "---------------"  
                            echo "输入要杀死终端的终端号:"  
                            read $TTY  
                            kill -9 ${K}=`ps -t $TTY | grep [0-9] | awk '{print $1}'`  
                          <IFRAME name=google_ads_frame marginWidth=0 marginHeight=0 src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-3707276699544226&dt=1208528568953&lmt=1208528568&prev_slotnames=6441826526&output=html&slotname=4047345889&correlator=1208528568203&url=http%3A%2F%2Funix-cd.com%2Funixcd12%2Farticle_774.html&ref=http%3A%2F%2Funix-cd.com%2Funixcd12%2Fspecial_view.asp%3Fspid%3D26%26nsort%3D%26page%3D9&frm=0&cc=150&ga_vid=1272800452.1205929365&ga_sid=1208525577&ga_hid=54697320&ga_fc=true&flash=9.0.115.0&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameBorder=0 width=300 scrolling=no height=250 allowTransparency></IFRAME> <IFRAME name=google_ads_frame marginWidth=0 marginHeight=0 src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-3707276699544226&dt=1208528569125&lmt=1208528569&prev_slotnames=6441826526%2C4047345889&output=html&slotname=4047345889&correlator=1208528568203&url=http%3A%2F%2Funix-cd.com%2Funixcd12%2Farticle_774.html&ref=http%3A%2F%2Funix-cd.com%2Funixcd12%2Fspecial_view.asp%3Fspid%3D26%26nsort%3D%26page%3D9&frm=0&cc=150&ga_vid=1272800452.1205929365&ga_sid=1208525577&ga_hid=54697320&ga_fc=true&flash=9.0.115.0&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameBorder=0 width=300 scrolling=no height=250 allowTransparency></IFRAME>
                         | 
                       
                    
                   
                 | 
               
            
           
         |