1、查看文件夾大小:
du -s filename,結果以字節爲單位顯示
du -sh filename,結果以MB爲單位顯示
2、創建多級目錄
mkdir -p file1/file2/file3/...
3、在編譯腳本中使用郵件通知
echo "img has ready" | mail -s "project img" [email protected] [email protected] [email protected]
4、顯示文本開始/結尾幾行內容:
head -n 10 file.txt //顯示file.txt開頭10行內容
tail -n 10 file.txt //顯示結尾10行內容
持續輸出命令行內容:tail -f command-line
5、awk查找文本中特定字符串
file:version.txt
文本:version="v1.5.4.20170715"
獲取版本號:cat version.txt | grep "version" | awk -F '"' '{print $2}' //以雙引號爲分隔符,第2個域即爲版本號
5、當前目錄快速搜索文件
find . -iname "filename"
6.sed中引用變量
sed -i '3s/'"$old_wk"'/'"$wk"'/' $currentPath/build/tools/buildinfo.sh
變量必須用單引號包含雙引號
7.獲取系統日期及年月日
date +%y%m%d
y、m、d大小寫不同,顯示格式不同
8.獲取shell腳本所在目錄
currentPath=$(cd $(dirname $0);pwd)
9.shell中的郵件通知
echo -e "content" | mail -s "subject" Email-address
10.過濾固定字符串前後的內容,比如想要找到文件test.txt中包含”music“字符串上下5行的內容:
cat test.txt | grep -A 5 -B 5 "music"
-A是指列出music字符所在的行後面5行內容(after),-B是指music字符所在行前面5行的內容(before)