1.清空文件的内容:
[root@tradetest ~]# >install.log
2.添加文件内容:
(1)vi (2)echo "I am chinese!" >[或>>] install.log
(3)[root@tradetest ~]# cat >install.log 然后输出内容,输完按Ctrl+D或Ctrl+C。
批量添加内容:
[root@tradetest ~]# cat >(或>>)install.log<<EOF 注:"EOF"可以是任意一对标签(我
试了任意一对字母,如a a)。
> I AM BOY
> I AM BOY
> I AM BOY
> EOF
[root@tradetest ~]# cat install.log
I AM BOY
I AM BOY
I AM BOY
[root@tradetest ~]#
2>&1 把标准错误重定向到标准输出(>&)
3.批量添加文件:
(1)touch 1.txt 2.txt ... (2)touch {1,2,3}.txt
(3)[root@tradetest ~]# for f in `seq 1000`;do touch $f.txt;done
4.复制:
cp -a 相当于 cp -pdr -p 保持属性 -d 若为链接文件则复制链接文件属性而非文档本身
-r 递归 -u 若目标文件存在,则目标文件比源文件旧时才复制。
5.过滤字符串:
[root@test ~]# cat test.txt
good boy
useradd
linux
[root@test ~]# sed -e '/linux/d' test.txt -e 编辑 d 删除
good boy
useradd
[root@test ~]# grep -v "linux" test.txt
good boy
useradd
[root@test ~]# sed -n /linux/p test.txt -n 取消默认输出 p 打印
linux
[root@test ~]# grep "linux" test.txt
linux
[root@test ~]# sed -n /[^linux]/p test.txt -n 同上
good boy
useradd
[root@test ~]# awk /[^linux]/ test.txt
good boy
useradd
[root@test ~]#
三剑客:grep,sed,awk
6.显示部分内部:20到30行