---
disqus: ncumcl
---
# 奇怪但好用的 Linux 指令
###### tags: `MCL Notebook` `Linux`
- 統計整個資料夾的大小
```
$ du -hs [資料夾]
```
- 統計整個 project 寫了幾行
``` bash
# 只算 .c 檔
$ find [資料夾] -name '*.c' | xargs wc -l
# 只算 .c 和 .h 檔
# -o 表示 or
$ find [資料夾] -name '*.c' -o -name '*.h' | xargs wc -l
# 全部的檔案都算
$ find [資料夾] -name '*' | xargs wc -l
```
- 找關鍵字
```
# 針對單一檔按
$ cat [檔名] | grep [關鍵字]
# 針對整個資料夾
$ grep -rn [關鍵字(支援正規表示法)] [資料夾]
# 另一個搜尋工具
# 差別在使用的方法不同,這個使用多核心處理
# 如果不是吃在 IO 速度的話,這個會比較快
$ ag [關鍵字(支援正規表示法)] [資料夾]
```
- 快速刪除大量檔案 (可用於Kernel Code的```make clean```)
```shell=
# 先定義要刪除的資料夾:test/, 和一個空資料夾:blank/
$ rm -rf test/ #最慢
$ find ./ -type f -delete
$ perl -e 'for(<*>){((stat)[9]<(unlink))}'
$ rsync -a --delete blank/ test/ #最快,推薦使用
```
Ref: [Which is the fastest method to delete files in Linux](https://www.slashroot.in/which-is-the-fastest-method-to-delete-files-in-linux)
- 將整份文件倒過來印出
``` shell=
tac <filename>
sed -n '1!G;h;$p' <filename>
```
- drop 系統快取
``` bash
echo 3 > /proc/sys/vm/drop_caches
```
- 將只寫到記憶體,還未寫到儲存媒體資料的寫到儲存媒體中
``` bash
sync
```
# IO 相關的指令
## fio
example
```
fio --iodepth=512 --ioengine=libaio --direct=1 --group_reporting --numjobs=1 --bs=4k --name=randread --rw=randread --filename=/volume1/share1/data --size=4G --stonewall --time_based --runtime=60
```
可以參考教學[1](http://benjr.tw/269)[2](http://benjr.tw/96736),教的蠻仔細的
# Linux Mount Google Driver
## Install
``` bash
sudo apt update
sudo install firefox xdg-utils -y
sudo add-apt-repository ppa:alessandro-strada/ppa
sudo apt update
sudo apt-get install google-drive-ocamlfuse -y
```
## Mount
``` bash
google-drive-ocamlfuse ~/gdrive
# 之後會跳 firefox 到認證的網頁,認證完成即可
```
> [參考](http://www.webupd8.org/2013/09/mount-google-drive-in-linux-with-google.html#more)