你们知道什么是Linux命令么这个非常高深的运用技术将由我来非常讲解,Linux命令NB在哪呢,下面我来进入讲述Linux命令的无限领域。
Linux命令cat – concatenate files and print on the standard output把文件连接后输出到屏幕上,其实就是查看文件内容。 SYNOPSIScat [OPTION] [FILEDESCRIPTIONConcatenate FILE(s), or standard input, to standard output. -A,show-allequivalent to -vET –等同与参数-vET -b,number-nonblanknumber nonblank output lines –对空白行不编号,与-n有相似。 -e,equivalent to -vE –等同与参数-vE -E,show-ends display $ at end of each line –每行以$符号为行结尾 -n,number number all output lines –由1开始对所有输出的行数编号 -s,squeeze-blank never more than one single blank line –当遇到连续2行以上的空白行,只保留一行空白行 -t,equivalent to -vT -T,show-tabsdisplay TAB characters as ^I -u,(ignored) -v,show-nonprintinguse ^ and M- notation, except for LFD and TAB
Linux命令练习: [root@CentOS4 ok_008]# cat mytestHello world! Hello world 1 Hello world 2 hello world 3 [root@CentOS4 ok_008]# cat -n mytest Hello world! Hello world 1 Hello world 2 hello world 3 [root@CentOS4 ok_008]# cat -b mytest 1Hello world! 2Hello world 1 3Hello world 2 4hello world 3从以上Linux命令 我们可以验证 -n与 -b的差异。 [root@CentOS4 ok_008]# cat -b -E mytest 1Hello world!$ 2Hello world 1$ 3Hello world 2$ 4hello world 3$ 每行以$符号为行结尾
现在想合并mytest和oktest两个文件的内容成一个新的文件NewTest.txt[root@CentOS4 ok_008]# ls -ltotal 24-rw-r–r– 1 root root 59 Sep 18 19:48 mytestdrwxr-xr-x 3 root root 4096 Sep 13 22:51 ok-rw-r–r– 1 root root 21 Sep 17 20:45 oktest[root@CentOS4 ok_008]# cat mytest oktest >> newtest.txt[root@CentOS4 ok_008]# ls -ltotal 32-rw-r–r– 1 root root 59 Sep 18 19:48 mytest-rw-r–r– 1 root root 80 Sep 18 19:53 newtest.txtdrwxr-xr-x 3 root root 4096 Sep 13 22:51 ok-rw-r–r– 1 root root 21 Sep 17 20:45 oktest查看新的文件newtest.txt的内容:[root@CentOS4 ok_008]# cat -b newtest.txt 1 Hello world! 2 Hello world 1 3 Hello world 2 4 hello world 3 5 this is a test file.
合并两个文件的内容[root@CentOS4 ok_008]# cat mytest oktest > newtest1.txt[root@CentOS4 ok_008]# ls -ltotal 40 -rw-r–r– 1 root root 59 Sep 18 19:48 mytest -rw-r–r– 1 root root 80 Sep 18 19:56 newtest1.txt -rw-r–r– 1 root root 80 Sep 18 19:53 newtest.txt drwxr-xr-x 3 root root 4096 Sep 13 22:51 ok -rw-r–r– 1 root root 21 Sep 17 20:45 oktest
[root@CentOS4 ok_008]# cat -b newtest1.txt 1 Hello world! 2 Hello world 1 3 Hello world 2 4 hello world 3 5 this is a test file.
我们仔细会发现cat mytest oktest > newtest1.txt 和 cat mytest oktest >> newtest.txt 返回的结果在这里相同。其实根据《Linux常用命令 全集》的例子:cat -n textfile1 > textfile2 把 textfile1 的档案内容加上行号后输入 textfile2 这个档案里cat -b textfile1 textfile2 >> textfile3 把 textfile1 和 textfile2 的档案内容加上行号(空白行不加)之后将内容附可以看出两个Linux命令 的差异,这里就不多写例子。
Linux命令清空某个文件的内容: [root@CentOS4 ok_008]# cat /dev/null > mytest [root@CentOS4 ok_008]# cat -b mytest [root@CentOS4 ok_008]# ls -l total 52 -rw-r–r– 1 root root 0 Sep 18 20:05 mytest -rw-r–r– 1 root root 80 Sep 18 19:56 newtest1.txt -rw-r–r– 1 root root 93 Sep 18 20:01 newtest3.txt -rw-r–r– 1 root root 93 Sep 18 20:01 newtest4.txt -rw-r–r– 1 root root 80 Sep 18 19:53 newtest.txt drwxr-xr-x 3 root root 4096 Sep 13 22:51 ok -rw-r–r– 1 root root 34 Sep 18 20:00 oktest –明天找一下资料为什么要使用cat /dev/null > mytest能清空文件内容。
Linux命令创建一个新的文件: [root@CentOS4 ok_008]# cat >new.txt –按 CTRL + C 结束录入 [root@CentOS4 ok_008]# ls -l total 56 -rw-r–r– 1 root root 0 Sep 18 20:05 mytest -rw-r–r– 1 root root 80 Sep 18 19:56 newtest1.txt -rw-r–r– 1 root root 93 Sep 18 20:01 newtest3.txt -rw-r–r– 1 root root 93 Sep 18 20:01 newtest4.txt -rw-r–r– 1 root root 80 Sep 18 19:53 newtest.txt -rw-r–r– 1 root root 0 Sep 18 20:07 new.txt drwxr-xr-x 3 root root 4096 Sep 13 22:51 ok -rw-r–r– 1 root root 34 Sep 18 20:00 oktest Linux命令温习以前的rmLinux命令 把一些刚才临时建立的文件(如newtest1.txt,newtest3.txt,newtest4.txt,newtest.txt,new.txt)删除掉:
[root@CentOS4 ok_008]# rm newtest1.txt newttest3.txt newtest4.txt newtest.txt rm: remove regular file `newtest1.txt’? y rm: cannot lstat `newttest3.txt’: No such file or directory rm: remove regular file `newtest4.txt’? y rm: remove regular file `newtest.txt’? y [root@CentOS4 ok_008]# rm newtest3.txt rm: remove regular file `newtest3.txt’? y [root@CentOS4 ok_008]# ls -l total 24 -rw-r–r– 1 root root 0 Sep 18 20:05 mytest -rw-r–r– 1 root root 0 Sep 18 20:07 new.txt drwxr-xr-x 3 root root 4096 Sep 13 22:51 ok -rw-r–r– 1 root root 34 Sep 18 20:00 oktest [root@CentOS4 ok_008]# rm newt.txt rm: cannot lstat `newt.txt’: No such file or directory [root@CentOS4 ok_008]# rm new.txt rm: remove regular empty file `new.txt’? y [root@CentOS4 ok_008]# ls -l total 20 -rw-r–r– 1 root root 0 Sep 18 20:05 mytest drwxr-xr-x 3 root root 4096 Sep 13 22:51 ok -rw-r–r– 1 root root 34 Sep 18 20:00 oktest 今天就学到这里,休息一下,呵呵。 以上介绍Linux命令应用。