# One-liner Commands

1\. 建立多個目錄

```shell
mkdir -p -v /home/josevnz/tmp/{dir1,anotherdir,similardir}
```

2\. 搜尋取代關鍵字

```shell
# With sed<br></br>sed -i 's#ORIGINAL_VALLUE#NEW_VALUE#g' myfile1 myfile2<br></br><br></br># With perl<br></br>perl -p -i -e 's#ORIGINAL#NEW_VALUE#' myfile1 myfile2
```

3\. 臨時以網頁方式分享特定目錄

```shell
# Python is required<br></br>cd $mydir && python3 -m http.server 8888
```

4\. 臨時寫一個多行的檔案

```shell
cat<<DOC>/my/new/file<br></br>Line1<br></br>Line2<br></br>A $VARIABLE<br></br>DOC
```

或 Ctrl + D 結束離開

```shell
cat > testfile<br></br>This is a test<br></br>multiple lines<br></br>and here we go
```

5\. 在指定目錄裡搜尋包含特定關鍵字的檔案

```shell
# With grep<br></br>grep -R 'import' --include='*.java' --color MySourceCodeDir<br></br><br></br># With find<br></br>find MySourceCodeDir/ -name '*.java' -type f -print| xargs \<br></br>grep --color 'import
```

6\. 用 watch 監控記憶體使用

```shell
watch -n 5 -d '/bin/free -m'
```

7\. 更新所有的 Git 套件庫

```shell
for i in */.git; do cd $(dirname $i); git pull; cd ..; done
```