linux考试复习资料

上传人:第*** 文档编号:32689006 上传时间:2018-02-12 格式:DOC 页数:16 大小:107KB
返回 下载 相关 举报
linux考试复习资料_第1页
第1页 / 共16页
linux考试复习资料_第2页
第2页 / 共16页
linux考试复习资料_第3页
第3页 / 共16页
linux考试复习资料_第4页
第4页 / 共16页
linux考试复习资料_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《linux考试复习资料》由会员分享,可在线阅读,更多相关《linux考试复习资料(16页珍藏版)》请在金锄头文库上搜索。

1、1. 常用的文件和目录命令:拷贝、剪切、粘贴;书 P94-95$ cp - i test1.c /usr/cpp/test2.c 将文件 test1.c 拷贝到/usr/cpp 这个目录下,并改名为 test2.c。cp /etc/aaa.gz /tmp 将文件从/etc/aaa.gz 拷贝到/tmp 目录下cp rf /etc/aaa.gz /tmp 将/etc 目录下 aaa.gz 文件拷贝到 /tmp 不提示确认 cp r /home/test /home 将/home 下的 test 目录及 test 下的文件全部复制到 /home 下cp 执行复制粘贴mv 执行剪切粘贴2.ls -l

2、a 所列文件列表具体解释权限 硬连接数 所有者 所有属组 大小 最后修改日期 文件名文件名 以”.”开头的是隐藏文件 3.写一条命令,删除某个目录下的所有文件和子目录书 P95rm -rf /home/ivenyl 删除/home/ivenyl 目录下所有文件且不提示4.写一段 shell 程序,删除指定目录下的所有文件和子目录。住:必须使用 for in 语句如:my_delete xxx例:删除/home/test(包括 test)目录for name in /home/test do rm -rf $namedone5.写一段 shell 程序,打印指定目录下的所有文件和子目录。注:必须

3、使用 for in 语句如:my_display xxx例for name in /home/test do ls la $namedone6.统计文件字数、行数、字节数的命令。书 P96例如: $ wc - lcw awk.sh行数 字数 字节数 文件名 省略任选项-lcw,wc 命令的执行结果与上面一样7.写一条命令统计某个文件前 20 行的字数。$head 20 test.c |wc w 显示 test.c 文件前 20 行并统计字数8.写一条命令统计某个文件倒数 3 行的字节数。$tail 3 test.c|wc c 显示 test.c 文件后 3 行字节数9.各种查找命令,重点是 g

4、rep。书 P102grep 用法:1、grep -l boss * 显示所有包含 boss 的文件名。2、grep -n boss file 在匹配行之前加行号。3、grep -i boss file 显示匹配行, boss 不区分大小写。4、grep -v boss file 显示所有不匹配行。5、grep -q boss file 找到匹配行,但不显示,但可以检查 grep 的退出状态。(0 为匹配成功)6、grep -c boss file 只显示匹配行数(包括 0)。7、grep $boss file 扩展变量 boss 的值再执行命令。8、ps -ef|grep *user1 搜索

5、 user1 的命令,即使它前面有零个或多个空格。9、ps -e|grep -E grant_server|commsvr|tcpsvr|dainfo 查找多个字符串的匹配(grep -E 相当于 egrep)grep 用法详解:grep 与正则表达式首先要记住的是: 正则表达式与通配符不一样,它们表示的含义并不相同!正则表达式只是一种表示法,只要工具支持这种表示法,那么该工具就可以处理正则表达式的字符串。vim、grep 、awk 、sed 都支持正则表达式,也正是因为由于它们支持正则,才显得它们强大;在以前上班的公司里,由于公司是基于 web 的服务型网站(nginx),对正则的需求比较大

6、,所以也花了点时间研究正则,特与大家分享下:1 基础正则表达式grep 工具,以前介绍过。grep -acinv 搜索内容串 filename-a 以文本文件方式搜索-c 计算找到的符合行的次数-i 忽略大小写-n 顺便输出行号-v 反向选择,即找 没有搜索字符串的行其中搜索串可以是正则表达式!1搜索有 the 的行,并输出行号$grep -n the regular_express.txt搜索没有 the 的行,并输出行号$grep -nv the regular_express.txt2 利用搜索集合字符 表示其中的某一个字符 ,例如ade 表示 a 或 d 或 ewoodyxiaoc:/

7、tmp$ grep -n taest regular_express.txt 8:I cant finish the test.9:Oh! the soup taste good!可以用符号做内的前缀,表示除 内的字符之外的字符。比如搜索 oo 前没有 g 的字符串所在的行. 使用 goo 作搜索字符串woodyxiaoc:/tmp$ grep -n goo regular_express.txt 2:apple is my favorite food.3:Football game is not use feet only.18:google is the best tools for se

8、arch keyword.19:goooooogle yes! 内可以用范围表示,比如a-z 表示小写字母,0-9 表示 09 的数字, A-Z 则是大写字母们。a-zA-Z0-9表示所有数字与英文字符。 当然也可以配合来排除字符。搜索包含数字的行woodyxiaoc:/tmp$ grep -n 0-9 regular_express.txt 5:However ,this dress is about $ 3183 dollars.15:You are the best is menu you are the no.1.行首与行尾字符 $. 表示行的开头,$表示行的结尾( 不是字符,是位置)

9、那么$ 就表示空行 ,因为只有行首和行尾。这里与里面使用的 意义不同。它表示后面的串是在行的开头。比如搜索 the 在开头的行woodyxiaoc:/tmp$ grep -n the regular_express.txt 12:the symbol * is represented as star.搜索以小写字母开头的行woodyxiaoc:/tmp$ grep -n a-z regular_express.txt 2:apple is my favorite food.4:this dress doesnt fit me.10:motorcycle is cheap than car.12

10、:the symbol * is represented as star.18:google is the best tools for search keyword.19:goooooogle yes!20:go! go! Lets go.woodyxiaoc:/tmp$ 搜索开头不是英文字母的行woodyxiaoc:/tmp$ grep -n a-zA-Z regular_express.txt 1:Open Source is a good mechanism to develop programs.21:#I am VBirdwoodyxiaoc:/tmp$ $表示它前面的串是在行的结

11、尾,比如 . 表示 . 在一行的结尾搜索末尾是.的行woodyxiaoc:/tmp$ grep -n .$ regular_express.txt /. 是正则表达式的特殊符号,所以要用转义1:Open Source is a good mechanism to develop programs.2:apple is my favorite food.3:Football game is not use feet only.4:this dress doesnt fit me.5:However ,this dress is about $ 3183 dollars.6:GNU is free

12、 air not free beer.注意在 MS 的系统下生成的文本文件,换行会加上一个 M 字符。所以最后的字符会是隐藏的M ,在处理 Windows下面的文本时要特别注意!可以用 cat dos_file | tr -d r unix_file 来删除M 符号。 M=r那么$ 就表示只有行首行尾的空行拉!搜索空行woodyxiaoc:/tmp$ grep -n $ regular_express.txt 22:23:woodyxiaoc:/tmp$ 搜索非空行woodyxiaoc:/tmp$ grep -vn $ regular_express.txt 1:Open Source is

13、a good mechanism to develop programs.2:apple is my favorite food.3:Football game is not use feet only.4:this dress doesnt fit me.任意一个字符. 与重复字符 *在 bash 中* 代表通配符,用来代表任意个字符,但是在正则表达式中,他含义不同,*表示有 0 个或多个 某个字符。例如 oo*, 表示第一个 o 一定存在,第二个 o 可以有一个或多个,也可以没有,因此代表至少一个 o.点. 代表一个任意字符,必须存在。 g?d 可以用 g.d 表示。 good ,gxxd

14、 ,gabd .都符合。woodyxiaoc:/tmp$ grep -n g.d regular_express.txt 1:Open Source is a good mechanism to develop programs.9:Oh! the soup taste good!16:The world is the same with glad.woodyxiaoc:/tmp$ 搜索两个 o 以上的字符串woodyxiaoc:/tmp$ grep -n ooo* regular_express.txt /前两个 o 一定存在,第三个 o 可没有,也可有多个。1:Open Source is

15、 a good mechanism to develop programs.2:apple is my favorite food.3:Football game is not use feet only.9:Oh! the soup taste good!18:google is the best tools for search keyword.19:goooooogle yes!搜索 g 开头和结尾,中间是至少一个 o 的字符串,即 gog, goog.gooog.等woodyxiaoc:/tmp$ grep -n goo*g regular_express.txt 18:google is the best tools for search keyword.19:goooooogle yes!搜索 g 开头和结尾的字符串在的行woodyxiaoc:/tmp$ grep -n g.*g regular_express.txt / .*表示 0 个或多个任意字符1:Open Source is a good mechanism to develop programs.14:The gd software is a l

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 职业教育

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号