One-liner Commands

1. 建立多個目錄 
 mkdir -p -v /home/josevnz/tmp/{dir1,anotherdir,similardir} 
 2. 搜尋取代關鍵字 
 # With sed sed -i 's#ORIGINAL_VALLUE#NEW_VALUE#g' myfile1 myfile2 # With perl perl -p -i -e 's#ORIGINAL#NEW_VALUE#' myfile1 myfile2 
 3. 臨時以網頁方式分享特定目錄 
 # Python is required cd $mydir && python3 -m http.server 8888 
 4. 臨時寫一個多行的檔案 
 cat<<DOC>/my/new/file Line1 Line2 A $VARIABLE DOC 
 或 Ctrl + D 結束離開 
 cat > testfile This is a test multiple lines and here we go 
 5. 在指定目錄裡搜尋包含特定關鍵字的檔案 
 # With grep grep -R 'import' --include='*.java' --color MySourceCodeDir # With find find MySourceCodeDir/ -name '*.java' -type f -print| xargs \ grep --color 'import 
 6. 用 watch 監控記憶體使用 
 watch -n 5 -d '/bin/free -m' 
 7. 更新所有的 Git 套件庫 
 for i in */.git; do cd $(dirname $i); git pull; cd ..; done