Linux look命令用于查询单词。
look指令用于英文单字的查询。您仅需给予它欲查询的字首字符串,它会显示所有开头字符串符合该条件的单字。
look [-adf][-t<字尾字符串>][字首字符串][字典文件]
参数说明:
为了查找在testfile文件中以字母L开头的所有的行,可以输入如下命令:
look L testfile
原文件testfile中的内容如下:
$ cat testfile #查看testfile 文件内容 HELLO LINUX! Linux is a free unix-type opterating system. This is a linux testfile! Linux test
在testfile文件中使用look命令查找以"L"开头的单词,结果如下:
$ look L testfile #查找以“L”开头的单词 Linux is a free unix-type opterating system. #第二行以“L”开头,列出全句 Linux test #第四行以“L”开头,列出全句
Linux join命令用于将两个文件中,指定栏位内容相同的行连接起来。
找出两个文件中,指定栏位内容相同的行,并加以合并,再输出到标准输出设备。
join [-i][-a<1或2>][-e<字符串>][-o<格式>][-t<字符>][-v<1或2>][-1<栏位>][-2<栏位>][--help][--version][文件1][文件2]
参数:
连接两个文件。
为了清楚地了解join命令,首先通过cat命令显示文件testfile_1和 testfile_2 的内容。
然后以默认的方式比较两个文件,将两个文件中指定字段的内容相同的行连接起来,在终端中输入命令:
join testfile_1 testfile_2
首先查看testfile_1、testfile_2 中的文件内容:
$ cat testfile_1 #testfile_1文件中的内容 Hello 95 #例如,本例中第一列为姓名,第二列为数额 Linux 85 test 30 cmd@hdd-desktop:~$ cat testfile_2 #testfile_2文件中的内容 Hello 2005 #例如,本例中第一列为姓名,第二列为年份 Linux 2009 test 2006
然后使用join命令,将两个文件连接,结果如下:
$ join testfile_1 testfile_2 #连接testfile_1、testfile_2中的内容 Hello 95 2005 #连接后显示的内容 Linux 85 2009 test 30 2006
文件1与文件2的位置对输出到标准输出的结果是有影响的。例如将命令中的两个文件互换,即输入如下命令:
join testfile_2 testfile_1
最终在标准输出的输出结果将发生变化,如下所示:
$ join testfile_2 testfile_1 #改变文件顺序连接两个文件 Hello 2005 95 #连接后显示的内容 Linux 2009 85 test 2006 30
Linux joe命令用于编辑文本文件。
Joe是一个功能强大的全屏幕文本编辑程序。操作的复杂度要比Pico高一点,但是功能较为齐全。Joe一次可开启多个文件,每个文件各放在一个编辑区内,并可在文件之间执行剪贴的动作。
joe [-asis][-beep][-csmode][-dopadding][-exask][-force][-help][-keepup][-lightoff][-arking][-mid][-nobackups][-nonotice][-nosta][-noxon][-orphan][-backpath<目录>][-columns<栏位>][-lines<行数>][-pg<行数>][-skiptop<行数>][-autoindent crlf linums overwrite rdonly wordwrap][+<行数>][-indentc<缩排字符>][-istep<缩排字符数>][-keymap<按键配置文件>][-lmargin<栏数>][-rmargin<栏数>][-tab<栏数>][要编辑的文件]</p>
参数:
利用joe命令编辑文本文件。例如利用joe编辑C 语言源代码main.c,使用如下命令:
joe main.c
与jed类似,joe编辑器中C语言的语法也以彩色的方式显示。效果如下:
I A main.c (c) Row 1 Col 1 12:28 Ctrl-K H for help #上排从左至右分别为打开的文件名、光标所在行列数、现在时间、显示操作说明 /*-*- linux-c-*-*/ #编辑区 #include <linux/mm.h> #include <linux/sysctl.h> #include <linux/nsproxy.h> static struct list_head * net_ctl_header_lookup(struct ctl_table_root *root, struct nsproxy *namespaces) { return &namespaces->net_ns->sysctl_table_headers; } static struct ctl_table_root net_sysctl_root = { .lookup = net_ctl_header_lookup, }; static int sysctl_net_init(struct net *net) { INIT_LIST_HEAD(&net->sysctl_table_headers); return 0; } ** Joe's Own Editor v3.5 ** (utf-8) ** Copyright . 2006 ** #joe编辑区的版本及版权信息
joe编辑器有一些常用的组合键,例如可以通过Ctrl+K+H 寻求联机帮助,首先按Ctrl+K组合键,再输入字母H,即可调出帮助菜单,通过该帮助信息可以方便地获知如何对joe 编辑器进行操作。
Linux jed命令用于编辑文本文件。
Jed是以Slang所写成的程序,适合用来编辑程序原始代码。
jed [-2n][-batch][-f<函数>][-g<行数>][-i<文件>][-I<文件>][-s<字符串>][文件]
参数:
jed主要用于编辑程序的源码,编辑源码时将以彩色高亮的方式显示程序的语法。例如使用jed编辑一个C语言的源代码文件,可使用如下命令:
jed main.c #用jed编辑器打开main.c 文件
输出结果如下:
F10 key ==> File Edit Mode Search Buffers Windows System Help #编辑器菜单 /*-*- linux-c-*-*/ #编辑区 #include <linux/mm.h> #include <linux/sysctl.h> #include <linux/nsproxy.h> static struct list_head * net_ctl_header_lookup(struct ctl_table_root *root, struct nsproxy *namespaces) { return &namespaces->net_ns->sysctl_table_headers; } static struct ctl_table_root net_sysctl_root = { .lookup = net_ctl_header_lookup, }; static int sysctl_net_init(struct net *net) { INIT_LIST_HEAD(&net->sysctl_table_headers); return 0; } -----+(Jed 0.99.18U) Emacs: main.c (C) All 6:06pm----------------------------- #从左到右分别为jed版本编号、当前是模拟emacs编辑器、打开的文件名、现在的时间 loading /usr/share/jed/lib/modeinfo.slc
Linux ispell命令用于拼写检查程序。
ispell预设会使用/usr/lib/ispell/english.hash字典文件来检查文本文件。若在检查的文件中找到字典没有的词汇,ispell会建议使用的词汇,或是让你将新的词汇加入个人字典。
ispell [-aAbBClmMnNPStVx][-d<字典文件>][-L<行数>][-p<字典文件>][-w<非字母字符>][-W<字符串长度>][要检查的文件]
参数:
检查文件的拼写。例如,检查testfile文件,可使用如下命令:
ispell testfile
如果文件中出现可疑词汇,则第一个出现的可疑词汇以高亮显示,并在屏幕下方给出词汇的修改意见,以及ispell的操作命令。如下所示:
netwrks File: testfile Linux netwrks are becoming more and more common, but security is often an overlooked issue. Unfortunately 0: networks [SP] <number> R)epl A)ccept I)nsert L)ookup U)ncap Q)uit e(X)it or ? for help
本例中,检查出netwrks 错误,并提示纠正信息,此时输入"0",即使用networks 来纠正错误,同时继续显示下一个错误,直到所有的错误显示完毕。
通过以上实例我们可以发现,文件testfile中有拼写错误,对该文件进行修改后需备份文件。此时使用如下命令:
ispell-b testfile #检查拼写错误的同时,备份文件
如果文件已经无拼写错误,则不显示任何信息,通过ls命令我们也可以查看到当前文件目录下产生了文件testfile的备份文件testfile.bak。查看结果如下所示:
$ ls #以列表的形式查看当前目录下的文件 examples.desktop testfile_1 testfile.bak xx01 模板图片 音乐 testfile testfile1 testfile_2 xx00 公共的视频文档桌面
其中,testfile.bak 文件就是刚才命令生成的备份文件,内容与原来的testfile 文件内容是一样的。
Linux grep 命令用于查找文件里符合条件的字符串。
grep 指令用于查找内容包含指定的范本样式的文件,如果发现某文件的内容符合所指定的范本样式,预设 grep 指令会把含有范本样式的那一列显示出来。若不指定任何文件名称,或是所给予的文件名为 -,则 grep 指令会从标准输入设备读取数据。
grep [-abcEFGhHilLnqrsvVwxy][-A<显示行数>][-B<显示列数>][-C<显示列数>][-d<进行动作>][-e<范本样式>][-f<范本文件>][--help][范本样式][文件或目录...]
参数:
1、在当前目录中,查找后缀有 file 字样的文件中包含 test 字符串的文件,并打印出该字符串的行。此时,可以使用如下命令:
grep test *file
结果如下所示:
$ grep test test* #查找前缀有“test”的文件包含“test”字符串的文件 testfile1:This a Linux testfile! #列出testfile1 文件中包含test字符的行 testfile_2:This is a linux testfile! #列出testfile_2 文件中包含test字符的行 testfile_2:Linux test #列出testfile_2 文件中包含test字符的行
2、以递归的方式查找符合条件的文件。例如,查找指定目录/etc/acpi 及其子目录(如果存在子目录的话)下所有文件中包含字符串"update"的文件,并打印出该字符串所在行的内容,使用的命令为:
grep -r update /etc/acpi
输出结果如下:
$ grep -r update /etc/acpi #以递归的方式查找“etc/acpi” #下包含“update”的文件 /etc/acpi/ac.d/85-anacron.sh:# (Things like the slocate updatedb cause a lot of IO.) Rather than /etc/acpi/resume.d/85-anacron.sh:# (Things like the slocate updatedb cause a lot of IO.) Rather than /etc/acpi/events/thinkpad-cmos:action=/usr/sbin/thinkpad-keys--update
3、反向查找。前面各个例子是查找并打印出符合条件的行,通过"-v"参数可以打印出不符合条件行的内容。
查找文件名中包含 test 的文件中不包含test 的行,此时,使用的命令为:
grep -v test *test*
结果如下所示:
$ grep-v test* #查找文件名中包含test 的文件中不包含test 的行 testfile1:helLinux! testfile1:Linis a free Unix-type operating system. testfile1:Lin testfile_1:HELLO LINUX! testfile_1:LINUX IS A FREE UNIX-TYPE OPTERATING SYSTEM. testfile_1:THIS IS A LINUX TESTFILE! testfile_2:HELLO LINUX! testfile_2:Linux is a free unix-type opterating system.
Linux fold命令用于限制文件列宽。
fold指令会从指定的文件里读取内容,将超过限定列宽的列加入增列字符后,输出到标准输出设备。若不指定任何文件名称,或是所给予的文件名为"-",则fold指令会从标准输入设备读取数据。
fold [-bs][-w<每列行数>][--help][--version][文件...]
参数:
将一个名为testfile 的文件的行折叠成宽度为30,可使用如下命令:
fold -w 30 testfile
为了对比,先将testfile文件输出如下:
$ cat testfile #查看testfile 中的内容 Linux networks are becoming more and more common, but security is often an overlooked issue. Unfortunately, in today’s environment all networks are potential hacker targets, from top-secret military research networks to small home LANs. Linux Network Security focuses on securing Linux in a networked environment, where the security of the entire network needs to be considered rather than just isolated machines. It uses a mix of theory and practical techniques to teach administrators how to install and use security applications, as well as how the applications work and why they are necessary.
然后使用fold命令折叠显示:
$ fold -w 30 testfile #行折叠成宽度为30,显示testfile 文件 Linux networks are becoming mo re and more common, but securi ty is often an overlooked issu e. Unfortunately, in today’s environment all networks are potential hacker targets, from top-secret military research networks to small home LANs. Linux Network Security focuses on securing Linux in a networ ked environment, where the sec urity of the entire network ne eds to be considered rather th an just isolated machines. It uses a mix of theory and pract ical techniques to teach admin istrators how to install and u se security applications, as w ell as how the applications wo rk and why they are necessary
Linux fmt命令用于编排文本文件。
fmt指令会从指定的文件里读取内容,将其依照指定格式重新编排后,输出到标准输出设备。若指定的文件名为"-",则fmt指令会从标准输入设备读取数据。
fmt [-cstu][-p<列起始字符串>][-w<每列字符数>][--help][--version][文件...]
参数说明:
重排指定文件。如文件testfile共5 行文字,可以通过命令对该文件格式进行重排,其命令为:
fmt testfile
输出结果如下:
$ fmt testfile #重排testfile 文件 hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile! Linux Linux
将文件testfile重新排成85 个字符一行,并在标准输出设备上输出,其命令应该为:
fmt -w 85 testfile
为了对比,先使用cat 命令查看文件内容:
$ cat testfile #查看testfile 文件的内容 hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile! Linux Linux
使用fmt命令重排之后,输出结果如下:
$ fmt -w 85 testfile #指定重排宽度为85个字符 hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile! Linux Linux
Linux ex命令用于在Ex模式下启动vim文本编辑器。
ex执行效果如同vi -E,使用语法及参数可参照vi指令,如要从Ex模式回到普通模式,则在vim中输入":vi"或":visual"指令即可。
ex [选项][参数]
参数说明:
在ex 指令后输入文件名按回车键后,即可进入ex 编辑模式,如编辑testfile文件,使用的命令格式如下:
ex testfile
输出的信息如下:
"testfile" 5L, 95C
"testfile"表示文件名,5L表示5 行,95 表示字节数
进入ex 模式。输入"visual"回到正常模式
它的操作与vim 中是一样的,此时如果在":"后输入"visual"后按回车键,将进入到vi 指令全屏界面;如果输入"q",则退出编辑器。