筆記、Command Line Interface


Posted by s103071049 on 2021-04-17

| 早期的作業系統無圖型化介面(GUI),所以會透過純文字 Command Line Interface 去操控電腦。CLI 指令為另一種操控電腦的方式,有些功能透過CLI比較快。

一、基本指令

1) Print Working Directory (PWD)

pwd 印出所在位置

2) LiSt (LS)

ls 印出資料夾底下檔案



3) Change Directory (CD)

cd 切換資料夾


補充說明
(1) cd / go to the root directory
(2) cd ~ go to the user directory

4) Manual (man)

man 使用說明書

windows 上面的話是沒有這個指令可以用

二、檔案操作相關指令

1) touch

touch 建立檔案或更改時間

  • 建立檔案指令 : touch 不存在檔案
  • 更改時間指令 : touch 已存在檔案 檔案內容不變,僅更改最後時間。

2) ReMove (rm)

rm 刪除檔案

  • 刪除檔案指令 : rm 檔案名
  • 刪除資料夾 : rmdir 資料夾名 or rm -r 資料夾名 (-r 會把這個資料夾底下的所有東西都刪除)
    -

3) MaKe DIRectory (mkdir)

mkdir 建立資料夾

  • tab 鍵會快速帶入還沒打完的字

4) Move (MV)

mv 移動檔案或改名

  • 絕對路徑 vs 相對路徑
    1 絕對路徑 : /(slash)開頭
    2 相對路徑
  • 移動檔名指令 : move 要移動的檔案 要移動到的地方,可以用cd , ls , ..檢視檔案移動的路徑。
  • 改名指令 : move 要移動的檔案 要移動到的地方要移動的地方為不存在,此時電腦會將檔案移動到那個不存在的地方,原本的檔案就不見了,以不存在地方的檔名做取代。

5) Copy (CP)

cp 複製檔案

  • 複製檔案的指令 : cp 要複製的檔案 複製後的檔案
  • 複製資料夾的指令 : -r cp 要複製的檔案 複製後的檔案
    要操控的對象是資料夾,就在前面加上-r <對照 : rm指令>

三、文字編輯器

  • 用途: 看檔案內容、簡單修改(刪減)檔案、連server做文字編輯

vim , vi

  • 文字編輯指令 :vim 編輯的檔案名稱
  • 於文字編輯器內按 i : INSERT模式,可以自由打字
  • 於文字編輯器內按 esc : 普通模式,可複製、刪除,但不能插入文字。
  • 於文字編輯器內輸入 :q 與 enter : 離開文字編輯器
  • 於文字編輯器內輸入 :wq : 寫完檔後離開

連接檔案 cat

  • cat : 只放一個參數時,會列印出檔案裡所有的內容 <參照vim、看檔案內容>

分頁式印出檔案 less

  • 分頁式印出檔案的指令 : less 檔案名

四、其他指令

grep 抓取關鍵字

wget 下載檔案/網頁原始碼

  • 非內鍵指令(指令是可以安裝,其背後原理為一個個程式)
  • 下載檔案/網頁原始碼指令 : wget 下載檔案的網址,可用ls檢視下載的檔案、用start將下載的檔案打開
    下載網頁原始碼

curl 送出request

  • 用途 : 測試API
  • curl指令 : curl api網址,會將它的response秀出來; curl -I api網址,會將與http有關的header秀出來

date 印出現在時間

Table of Process 印出所有 Process

  • top指令 : top
  • 用途 : 檢視電腦狀況
    Top is a Linux process that shows a list of processes running on the system and what levels of resources are being used. This application provides all processes running, the CPU and Memory consumed and with several switches available you can see things like the location of the executable that is running.
    Unfortunately, they don’t make a TOP executable ported for Microsoft Windows but don’t despair. You can use Power Shell to script a simple TOP style display that operates just like TOP on a Linux system.

tracert xxx網址

  • 用途 : from home router to xxx server

echo 印出字串 <參照 五、指令的組合技-redirection>

五、指令的組合技

redirection 重新導向 > input output

  • 指令 : 輸出 >(箭頭=重新導向) 某個地方
  • 指令 : echo,會印出你打的東西 >會把後面檔案的內容全部蓋掉
  • 指令 : echo,會印出你打的東西 >>相當於append

    (結論) >會將內容蓋掉,>>等於新增

pipe | 串接指令

  • 串接指令 : pipe | 將左邊指令的輸出,變成右邊指令的輸入
  • RMK : 可以用很多個pipe(|),將指令接起來

總結、指令只是以另一種方式,操控電腦

參考資料

  • 程式導師計畫第五期 [CMD101]

#command-line指令







Related Posts

JS30 Day 19 筆記

JS30 Day 19 筆記

平滑捲動效果  Smooth Scrolling

平滑捲動效果 Smooth Scrolling

JAVA筆記_Lambda

JAVA筆記_Lambda


Comments