# 指令集

## Linux

### 清空檔案

#### 利用重定向

```shell
true > [目標檔案]
```

```shell
truncate -s 0 [目標檔案]
```

### 查看檔案

<pre class="language-shell"><code class="lang-shell"><strong>more [目標檔案]
</strong>less [目標檔案]
cat [目標檔案]
tacf [目標檔案]

grep:
Ex. grep [-acinv] [--color=auto] '搜尋字符串' [目標檔案]
選項與參數：
-a ：將 binary 文件以 text 文件的方式搜尋數據
-c ：計算找到 '搜尋字符串' 的次數
-i ：忽略大小寫的不同，所以大小寫視為相同
-n ：順便輸出行號
-v ：反向選擇，亦即顯示出沒有 '搜尋字符串' 內容的那一行！
--color=auto ：可以將找到的關鍵詞部分加上顏色的顯示喔！
</code></pre>

```shell
複製檔案: cp [來源檔案] [目標檔案] ex. cp aaa.log bbb.log  將aaa.log 複製一份並且叫做bbb.log
刪除檔案: rm [目標檔案]  ex. rm aaa.log
強制刪除檔案或目錄: rm -f [file]
前往到檔案指定行數: vi +[行數] [目標檔案]  或是 vim +[行數] [目標檔案]
前往到檔案指定行數: vi +/[搜尋字串] [目標檔案]
離開檢視檔案: :q > enter
安裝vim: apt-get install vim
改變檔案權限: chmod [權限] [目標檔案] Ex. chmod 777 xxx.txt
查詢grep 第一筆資料: grep -n 'xxxxx' [目標檔案] | head -1
查詢grep 匹配多個字串 grep -E 'xxx001|xxx002' [目標檔案]
```

### 背景執行

```shell
只輸出錯誤信息到日志文件
nohup java -jar ddd.jar >/dev/null 2>ddd.log &

什麽信息也不要
nohup java -jar ddd.jar >/dev/null 2>&1 &


Linux的3中重定向

0:表示標準輸入
1:標準輸出,在一般使用時，默認的是標準輸出
2:標準錯誤信息輸出

可以用來指定需要重定向的標準輸入或輸出。
例如，將某個程序的錯誤信息輸出到log文件中：./program 2>log。
這樣標準輸出還是在屏幕上，但是錯誤信息會輸出到log文件中。
另外，也可以實現0，1，2之間的重定向。2>&1：將錯誤信息重定向到標準輸出。


關於/dev/null文件
Linux下還有一個特殊的文件/dev/null，它就像一個無底洞，所有重定向到它的信息都會消失得無影無蹤。
這一點非常有用，當我們不需要回顯程序的所有信息時，就可以將輸出重定向到/dev/null。
 
// 背景執行
nohup java -Xms64m -Xmx128m -jar WebStorageSystem_Backstage.jar --spring.profiles.active=prod --server.port=8081 > /dev/null 2>&1 & echo $!>pidFile

// 直接執行
java -Xms64m -Xmx128m -jar WebStorageSystem_Backstage.jar --spring.profiles.active=prod --server.port=8081
```

## Mac

```shell
查看本機ip:
ifconfig | grep "inet " | grep -v 127.0.0.1
查看本機已使用的port
lsof -n -i | grep LISTEN

查看集群redis:
ps -ef|grep redis

ps -ef |grep -v grep |grep [目標程式]

啟動ngrok
ngrok http 8081
ngrok http 8080

ngrok http -subdomain=inconshreveable 8080

* Command（或 Cmd）鍵 ⌘
* Shift 鍵 ⇧
* Option（或 Alt）鍵 ⌥
* Control（或 Ctrl）鍵 ⌃
* Caps Lock 鍵 ⇪
* Fn 鍵

查看db table: ⌘ + F6
Format code: ⌥ + ⌘ + L
排除沒用的import: ctr +  ⌥  + O
File search: ⌘  + ⇧ + O    或是 ⌘  + O 
上一步: ⌘  + [
下一步: ⌘  + ]
移動行: ⌘  + ⇧ + 方向鍵(上下)
刪除一行: ⌘  + delete
複製一行: ⌘  + D
往前刪除: delete
往後刪除: fn + delete
Settings: ⌘  + ,
Project settings: ⌘  + ;
截圖:Cmd + Ctrl + Shift + 4
顯示隱藏檔案:Cmd + Shift + >
背景執行: nohup [目標檔案] &
查看port佔用狀況: sudo lsof -i:8080
查除proesses: kill -9 xxxx
```

尚未完成


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xu-min-chang.gitbook.io/caster-develop-note/zhi-ling-ji.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
