Try   HackMD

終端機指令 (Mac)

介紹終端機的指令用法之前,先來認識一下 GUI 和 CLI 這兩個名稱什麼?

✐ GUI v.s. CLI 比一比

可以看到的視覺化介面去做出指令的介面就是 GUI ,而用文字方式去下指令的方式是 CLI:

  • Graphical User Interface 圖形使用者介面:透過看得到的介面操作電腦,更直觀。

  • Command Line Interface 命令列介面:用文字跟電腦溝通

    • 有些功能只能使用文字!

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

✐ 如何呼叫 Command Line Interface

Mac 和 Window 兩者的呼叫指令不一樣,這篇文章主要介紹 Mac 的終端機指令:

  • Mac: Terminal.app
  • Window: 命令提示字元 cmd.exe

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

✐ 路徑指令:基本指令介紹(Mac)

pwd

Print Working Directory
印出現在位置在哪裡

ls

  • List Segment 印出該資料夾下的所有檔案
  • ls 後面可以接參數
    • ls -l 會出現更多資訊:檔案最後被編輯的日期、檔名、檔案大小

cd

  • Change Directory 切換資料夾
  • cd 資料夾名稱
    • 資料夾名稱也可以直接從外部拉入
  • cd .. 兩個點點代表:回到上一層
  • cd / 一個斜線代表:回到根目錄,電腦最根部的地方
  • cd ~ home 目錄
  • 當目錄有空白或特殊符號([],!,$,&,*,;,|,)時,得用\來將它格開。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 路徑的部分,除了可使用絕對外,也可用~,來表示當前的用戶資料夾,就不用再打/User/XXX/
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

✐ 資料夾 directory 指令:

mkdir

  • make diretory 新增資料夾

rmdir

  • remove 刪除資料

使用時要謹慎,刪除就找不到!

mv

  • move
  • mv 要移動的檔案 移動到的地方移動資料夾或檔案
  • mv 要更改名稱的檔案 改成此檔名 可當改名

✐ 檔案 file 指令:

touch

  • 碰一下檔案,造成最後更改日期為當前時間
  • 碰一下的檔案不存在時,會建立一個該檔名的檔案,可當建立檔案

➤ rm`

  • remove 刪除資料

使用時要謹慎,刪除就找不到!

cp

  • copy 複製檔案
  • cp 原本檔案名稱 要複製過去的檔案名稱

✐ 執行:

➤ sudo`

  • super user do

執行該指令時,需要使用電腦中的最高權限,也就是root帳戶,所以會要求輸入密碼

man

  • MANual 使用說明
    • ex: man ls 對 ls 指令的說明書
    • 看完按 q鍵跳出

✐ 其他

grep

  • 抓取關鍵字
  • grep 關鍵字 檔案名稱

echo

  • 在 terminal 印出字串

➤ date`

  • 在 terminal 印出現在時間
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

top

  • Table Of Processes 印出所有 Process
    • Process:顯示即時的系統負載狀態
  • 可以用於指令稿中,輸出各種系統資訊

cat

  • CATenate
    • 連接檔案
    • 在 terminal 將檔案內容整個顯示出來

➤ less`

  • 分頁式在 terminal 上印出檔案內容

➤ pipe: |

利用 |,將前面指令輸出變成後面輸入

➤ redirect: >

重新導向

小結語

作為習慣使用介面的我來說,其實在下 CLI 的指令時,深怕一不小心下錯指令,亂複製也會造成自己也不知道的問題出現,這邊是統整曾用過的指令,至少有點認知可以避免出現不知所措的情況。

參考:

tags: 前端筆記

最後,親愛的大家!我需要你的大聲鼓勵 ٩(⚙ᴗ⚙)۶

如果覺得這篇文章對你有幫助,請給我個一個小小的鼓勵 ❤ 讓我知道,這會成為我寫下去很大的動力。
對了,我還有其他文章,如果有興趣也來逛逛吧!
(文章中如有覺得不妥之處、錯誤內容,也可以透過聯絡我,我會儘速改善,感謝!)

☞ YoJanni 珍妮 2021 正在設計轉職前端的路上,希望大家在學習的路上能夠一起成長
☞ 聯絡我