Shell脚本编程
2017-09-05 09:19
169 查看
if语句
ifcondition1thencommand1elifcondition2thencommand2elsecommandNfi
for语句
forvarinitem1item2...itemNdocommand1command2...commandNdone
while语句
whileconditiondocommanddone
case语句
case值in模式1)command1command2...commandN;;模式2)command1command2...commandN;;esac
参数处理 | 说明 |
---|---|
$# | 传递到脚本的参数个数 |
$* | 以一个单字符串显示所有向脚本传递的参数。如"$*"用「"」括起来的情况、以"$1$2…$n"的形式输出所有参数。 |
$$ | 脚本运行的当前进程ID号 |
$! | 后台运行的最后一个进程的ID号 |
$@ | 与$*相同,但是使用时加引号,并在引号中返回每个参数。如"$@"用「"」括起来的情况、以"$1""$2"…"$n"的形式输出所有参数。 |
$- | 显示Shell使用的当前选项,与 |
$? | 显示最后命令的退出状态。0表示没有错误,其他任何值表明有错误。 |
n>file | 将文件描述符为n的文件重定向到file。 |
n>>file | 将文件描述符为n的文件以追加的方式重定向到file。 |
命令 | 功能 | 其他 |
---|---|---|
ps-ef | -ADisplayinformationaboutotherusers'processes,includingthosewithoutcontrollingterminals.-aDisplayinformationaboutotherusers'processesaswellasyourown.Thiswillskipanyprocesseswhichdonothaveacontrollingterminal,unlessthe-xoptionisalsospecified.-CChangethewaytheCPUpercentageiscalculatedbyusinga``raw''CPUcalculationthatignores``resident''time(thisnormallyhasnoeffect).-cChangethe``command''columnoutputtojustcontaintheexecutablename,ratherthanthefullcommandline.-dLike-A,butexcludessessionleaders.-EDisplaytheenvironmentaswell.Thisdoesnotreflectchangesintheenvironmentafterprocesslaunch.-eIdenticalto-A.-fDisplaytheuid,pid,parentpid,recentCPUusage,processstarttime,controllingtty,elapsedCPUusage,andtheassociatedcommand.Ifthe-uoptionisalsoused,displaytheusernameratherthenthenumericuid.When-oor-Oisusedtoaddtothedisplayfollowing-f,thecommandfieldisnottruncatedasseverelyasitisinotherformats.-GDisplayinformationaboutprocesseswhicharerunningwiththespecifiedrealgroupIDs.-gDisplayinformationaboutprocesseswiththespecifiedprocessgroupleaders.-hRepeattheinformationheaderasoftenasnecessarytoguaranteeoneheaderperpageofinformation.-jPrintinformationassociatedwiththefollowingkeywords:user,pid,ppid,pgid,sess,jobc,state,tt,time,and | ps--processstatus |
lsof-i | lsoffilename显示打开指定文件的所有进程lsof-a表示两个参数都必须满足时才显示结果lsof-cstring显示COMMAND列中包含指定字符的进程所有打开的文件lsof-uusername显示所属user进程打开的文件lsof-ggid显示归属gid的进程情况lsof+d/DIR/显示目录下被进程打开的文件lsof+D/DIR/同上,但是会搜索目录下的所有目录,时间相对较长lsof-dFD显示指定文件描述符的进程lsof-n不将IP转换为hostname,缺省是不加上-n参数lsof-i用以显示符合条件的进程情况lsof-i[46][protocol][@hostname|hostaddr][:service|port]46-->IPv4orIPv6protocol-->TCPorUDPhostname-->Internethostnamehostaddr-->IPv4地址service-->/etc/service中的servicename(可以不只一个)port-->端口号(可以不只一个)例如:查看22端口现在运行的情况#lsof-i:22COMMANDPIDUSERFDTYPEDEVICESIZENODENAMEsshd1409root3uIPv65678TCP*:ssh(LISTEN) | lsof-listopenfiles |
相关文章推荐
- 三种Shell脚本编程中避免SFTP输入密码的方法
- shell脚本编程四 ——shell字符串处理
- Shell脚本编程详解
- shell脚本编程(一)
- Shell脚本编程30分钟入门
- Shell脚本编程学习入门 02
- 第二节:思维导图学习Shell脚本编程之命令之美
- Shell脚本编程的常识
- Shell脚本编程——了解你的Linux系统必须掌握的20个命令
- Shell脚本编程——监控系统内存之free
- shell脚本语言编程进阶实战
- shell脚本编程
- 高级shell脚本编程之重定向、环境变量、shell函数、echo命令用法
- shell脚本编程-特殊字符
- Shell脚本编程——数组(array)
- shell脚本编程之case语句学习笔记
- linux之基础shell脚本编程1 基础变量赋值
- shell脚本编程讲解2
- Linux命令行与Shell脚本编程[学习笔记1]
- Linux下shell脚本编程之正则表达式