1. 程式人生 > >linux學習記錄-命令替換-通配符-重定向-管道

linux學習記錄-命令替換-通配符-重定向-管道

linux

命令替換:$(command),`command`

touch ./file-$(date +%F-%H-%M_%S).txt


bash支持的引號有三種:

``:命令替換

"":弱引用,可以實現變量替換

‘‘:強引用,不完成變量替換


文件名通配 globbing

* 任意長度的任意字符

? 任意長度單個

[] 匹配指定範圍內的任意單個字符

[^] 匹配範圍外的


> 覆蓋

>> 追加輸出

-C 禁止對已經存在文件使用覆蓋重定向

強制覆蓋輸出,則使用>|

+C 關閉上述功能


2> 重定向錯誤輸出

2>> 追加方式

&> 重定向錯誤輸出或者標準輸出到同一個文件


< 輸入重定向 cat < /etc/fstab


tr ‘a-z‘ ‘A-Z‘ < /etc/fstab

cat /etc/fstab /etc/hosts

cat << EOF 手動輸入內容用EOF結束

cat >> /tmp/myfile.txt << EOF 輸入一部分內容存儲到myfile.txt中


管道

把一個命令的輸出當作另一個命令的輸入

echo "hello, world." | tr ‘a-z‘ ‘A-Z‘

cut -d: -f1 /etc/passwd | sort | tr ‘a-z‘ ‘A-Z‘

cat /etc/passwd | wc -l 統計文件行數

tee 輸出一份,再保存一份

echo "hello, world." | tee /tmp/hello.out


取文件第六行

head -6 /etc/inittab | tail -1

取倒數第九行,顯示用戶名和shell

tail -9 /etc/passwd | head -1 | cut -d: -f1,7 | tee /tmp/users




















linux學習記錄-命令替換-通配符-重定向-管道