什麼是 Command Line (CLI)?


Posted by YongChenSu on 2020-12-06

什麼是 CLI?

CLI 是命令列介面 (Command-Line Interface),是與電腦互動的指令。
GUI 是圖形化介面 (Graphical User Interface)。

而任何第三方所開發的 GUI,最終也是透過 CLI 指令。

CLI 常用指令有哪些?

windows 作業系統為例,常用的指令如下:

指令 說明
cd 切換目錄
man 指令使用手冊
cd .. 往上一層目錄移動
cd -al 往上一層目錄移動
pwd 取得目前所在位置
ls 列出目前檔案列表
touch 新增檔案
ehco 印出你所打的東西
ehco index.html 新增 index.html 檔案
> 重新導向
ehco "Hello" > index.html 新增內容為 Hello 的 index.html 檔案
>> 新增並取代內容
echo "append to last" >> index.html 新增內容到檔案
ehco 印出你所打的東西
mkdir 新增目錄
cp 複製檔案
mv 移動檔案
rm 刪除檔案
cat 印出檔案內容
clear 清除畫面上的內容
grep 抓取關鍵字
wget 下載檔案
curl 送出 request
(pipe) 將左邊指令的輸出作為右邊指令的輸入

為什麼無法在 VSCode 上使用 touch 指令新增檔案?

然而,VSCode 預設無法使用 touch,故要先安裝 git,重新設定使 VSCode 使用 git bash,設定的方法可參考這篇文章:VSCode 入門-終端機與殼層

可直接在 Terminal 上輸入其他 Terminal 的名稱,例如:powershellbashcmd,即可直接切換 Terminal。

指令練習

  • ls

再複習一次

  • ls:列出目前檔案列表
  • ls -a:列出包含小數點開頭的檔案 (.gitignore)
  • ls -l:列出檔案完整資訊
  • pipe

    在 windows 系統上要選擇 runtime,故指令變成

      cat index.txt | env node index.js
    

    將前面檔案的輸出做為 | 後面檔案的輸入

      cat isPrime.txt | grep 5 > store.txt
    

    將 isPrime.txt 裡的檔案內容,抓取關鍵字 5,然後將結果儲存於 store.txt 裡面。

參考資源


#程式導師實驗計畫第四期 #前端 #CLI







Related Posts

ClearDB id 連續遞增問題

ClearDB id 連續遞增問題

軍事訓練役如何改變了我

軍事訓練役如何改變了我

[CSS] box model/ display/ position

[CSS] box model/ display/ position


Comments