➜ ~ cat test.txt This is firt line! This is second line! This is third line! This is fourth line!
将test.txt的内容输入到test01.txt中
1 2 3 4 5 6
➜ ~ cat test.txt > test01.txt ➜ ~ cat test01.txt This is firt line! This is second line! This is third line! This is fourth line!
带行号输出
1 2 3 4 5
➜ ~ cat -n test.txt 1 This is firt line! 2 This is second line! 3 This is third line! 4 This is fourth line!
将两个文件内容合并,再写入到第三个文件中
1 2 3 4 5 6 7 8 9 10
➜ ~ cat test.txt test01.txt >> test02.txt ➜ ~ cat test02.txt This is firt line! This is second line! This is third line! This is fourth line! This is firt line! This is second line! This is third line! This is fourth line!
Linux ln(英文全拼:link files)命令是一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同步的链接。这有点像 Windows 环境下的快捷方式。介绍命令前了解一下软链接,硬链接具体是什么。
硬链接 Hard Link
在 Linux 系统中,每个文件对应一个 inode,文件的内容在存储在 inode 指向的 data block 中。要读取该文件的内容,需要通过文件所在的目录中记录的文件名找到文件的 inode 号,然后通过 inode 找到存储文件内容的 data block。当然多个文件名可以指向同一个inode。
. #buffer 中 当前行 $ #最后一行 n #第 n 行,行的范围是 [0,$] - or ^ #前一行 -n or ^n #前 n 行 + or +n #后一行及后n行 , or % #全部行,等同于 1,$ ; #当前行到最后一行 .,$ /re/#下一个包含正则 re 的行 ?re? #上一个包含正则 re 的行
dominic@hanhan:~$ ed # 进入编辑模式 This is a test text! # 输入文本 . # 结束输入命令 This is a test text! # 回显当前行 n # 显示行号命令 1 This is a test text! # 回显当前行并显示行号 c # 改变行命令 This is changed text! # 输入更改后的内容 . # 结束输入命令 n # 显示行号命令 1 This is changed text! # 回显当前行并显示行号 i # 在首行插入命令 This isfirst line! # 输入插入内容 . # 结束输入命令 + # 后一行命令 This is changed text! # 回显后一行 d # 删除当前行 . # 回显当前行命令 This is firt line! # 回显当前行 a This issecond line! This isthird line! This isfourth line! w test.txt # 写入并保存文件 q # 退出编辑器
dominic@hanhan:~$ cat test.txt # 查看内容 This isfirst line!s This issecond line! This isthird line! This isfourth line!