# [CMD101] Command Line 超新手入門 ###### tags: `Lidemy`,`CLI` [TOC] ## 環境設置 * Windows(git-bash) 安裝 Git 的時候,會一併安裝 git-bash 在 Windows 上面操作 command line 指令時可以使用 git-bash。 Git 官網:https://git-scm.com/ * Windows(Cmder) 或是安裝 [Cmder](http://cmder.net/) 可參考保哥的文章: [介紹好用工具:Cmder ( 具有 Linux 溫度的 Windows 命令提示字元工具 )](https://blog.miniasp.com/post/2015/09/27/Useful-tool-Cmder) * Mac (iTerm2) 在 Mac 上面則是安裝 iTerm2 可參考(1): [[心得] iTerm2 + zsh,打造更好的工作環境](http://huli.logdown.com/posts/402147-iterm2-zsh-better-environment) 可參考(2): [超簡單!十分鐘打造漂亮又好用的 zsh command line 環境](https://medium.com/statementdog-engineering/prettify-your-zsh-command-line-prompt-3ca2acc967f) <br> <br> ## 最基本的四個指令 :bulb: [Unix 與 MS-DOS 指令對照表](https://github.com/shyangs/blog/issues/8) <br> ### pwd * **`pwd`** (print working directory) 印出所在位置 <br> ### ls * **`ls`** (list) 列出目前所在資料夾的檔案清單 * **`ls -a`** 列出目前所在資料夾的隱藏檔案列表 * **`ls -l`** 使用長格式 (long format) 列出目前所在資料夾的 ***詳細*** 檔案列表 * **`ls -al`** 列出目前所在資料夾的 ***詳細*** 檔案清單 (包含隱藏檔案)。列出的項目除了檔名,還有權限、擁有者、檔案大小、最後修改日期時間 <br> ### cd * **`cd`** (change directory) 切換資料夾 * **`cd ..`** 回到上一層資料夾位置 * **`cd ~`** 預設 /Users/XXX 資料夾位置 :::info :bulb: 輸入資料夾名稱時,可善用tab鍵,只要打出開頭幾個字母,就會自動補齊完整資料夾名稱。 ::: <br> ### man :pushpin: ==這個指令 windows 不支援== 可改用 help 代替部分功能 * **`man`** (manual) 指令使用手冊 * **`clear`** (clear) 畫面清除 * **`q`** (quit) 離開 <br> <br> ## 檔案操作相關指令 ### touch * **`touch + 檔名`** 檔案不存在時: 建立新檔案 檔案存在時: 更改檔案時間為目前時間 <br> ### rm * **`rm`** (remove) 刪除檔案 * **`rmdir`** (remove directory) 刪除資料夾 * **`rm -r`** & **`rm -R`** (remove root) 刪除資料夾(及底下所有檔案) * **`rm -f`** (remove forcely) 強制移除 :pushpin: ==小心使用== <br> ### mkdir * **`mkdir`** (make directory) 建立資料夾 <br> ### mv * **`mv`** (move) 移動檔案或是改名 * **`mv 檔名 資料夾`** 移動檔案至某資料夾 * **`mv 檔名 ..`** 移動檔案至上一層資料夾 * **`mv 檔名 不存在的檔名`** 更改檔案名稱 <br> ### cp * **`cp`** (copy) 複製檔案 * **`cp 檔名 不存在的檔名`** 複製檔案成為新的檔案 * **`cp -r 資料夾 不存在的資料夾`** 複製檔案成為新的資料夾 <br> ### cat * **`cat 檔名`** 將檔案內容列出 <br> <br> ## 把你困在裡面一輩子的編輯器:Vim * **`vim`** 或 **`vi`** 文字編輯器 * **`vim 檔名`** 編輯某檔案 * **`i`** (insert) 編輯模式 * **按esc鍵** 跳出編輯模式,回到普通模式,無法插入文字 * **`:q`** (quit) 離開 * **`:wq`** (write quit) 寫完後,存檔離開 <br> <br> ## 其他好用指令 ### grep * **`grep`** 抓取關鍵字 * **`grep 關鍵字 檔名`** 抓取某檔案中含有關鍵字的段落 <br> ### wget * **`wget`** 下載檔案 * **`wget 網址`** 下載(該網址的)檔案 <br> ### curl * **`curl`** 送出 request,測試api * **`curl [api]`** 送出 request,show 出 response * **`curl -I [api]`** 擷取header資訊 <br> <br> ## 指令的組合技:pipe 與 redirection ### redirection * **`>`** 重新導向 input output * **`>>`** 重新導向 input output * **`ls -al > list_result`** 將詳細列表輸出到檔名為 list_result的檔案中,並覆蓋掉原先的內容 * **`ls -al >> list_result`** 將詳細列表輸出到檔名為 list_result的檔案中,加在原先的內容後面 <br> ### pipe * **`|`** 把左邊指令的輸出,變成右邊指令的輸入 <br> <br> ## 補充資料 * [Linux Command 命令列指令與基本操作入門教學](https://blog.techbridge.cc/2017/12/23/linux-commnd-line-tutorial/) * [[第一週] Command Line 基本指令與操作](https://medium.com/@miahsuwork/%E7%AC%AC%E4%B8%80%E9%80%B1-command-line-%E5%9F%BA%E6%9C%AC%E6%8C%87%E4%BB%A4%E8%88%87%E6%93%8D%E4%BD%9C-f4da8bcfdfa)
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.