Skip to content

[ CMD101 ] - Command Line 入門 #23

@zuppachu

Description

@zuppachu

基本指令

  1. pwd : Print Working Directory 印出我在哪

  2. ls : LiSt 印出所在資料夾的所有檔案
    ls -al:把隱藏的檔案也列出來

  3. cd: Chang Directory 切換資料夾
    cd ciao : 去名叫 ciao 的資料夾
    cd .. : 跳回前一層資料夾
    cd ~/Downloads/test/ciao : ~/資料夾路徑

  4. man : MANual 使用說明書
    q 離開

  5. clear :清空

操作指令

  • touch : 建立檔案或是更改時間

  • mkdir : MaKe DIRectory 建立資料夾

  • rm : ReMove 刪除資料
    rmdir : 刪除資料夾
    rm -r : rm -r text 刪除名叫 text 得資料夾
    rm -f <file> : 強制刪除檔案

  • mv : MoVe 移動檔案或是改檔名
    mv text.text hello : 將 text.txt 檔一到 hello 資料夾內
    mv text.txt .. : 將 text.txt 移動上一層資料夾
    mv test.txt 123 : 如果沒有 123 資料夾,則是將 text.txt 改名為 123.txt

  • cp : CoPy 複製檔案
    cp hello hello2 : 將 hello 複製一份,且命名為 hello2
    cp -r 資料夾1 資料夾2 : 複製資料夾要用 cp -r

  • grep : 抓取關鍵字
    grep zero ciao : 從 ciao 檔案內抓出 zero 關鍵字

  • wget : 下載檔案
    wegt 圖片連結網址 :下載圖片
    open 檔案名稱 :打開檔案
    wget 網頁網址 : 下載網頁原始碼
    cat 網頁原始碼檔案 :看網頁原始碼內容
    grep 2 網頁原始碼檔案 : 將網頁原始碼檔案中的 2 找出來

  • curl :送出 request
    curl API 網頁網址:用 get 方把 response 秀出來
    curl -I (大寫 i) : 擷取 header 資訊

  • date : 日期時間

  • top : Table Of Processes 印出所有的 process

  • cat : CATenate 連結檔案 或是 把檔案內容顯示出來 (按 q 離開)

  • less : 分頁是顯示檔案內容 (按 q 離開)

指令組合技

> :會把原本檔案的內容覆蓋掉

>> :在原檔案內新增內容

| : Pipe 左邊的指令輸出 右邊指令輸入

cat hello | grep o 
// 輸出 hello  檔的內容,將 o 找出來
grep o hello
// 將 hello 檔內的 o 找出來
兩個是一樣的
cat hello | grep o > result 
// 輸出 hello 檔內容,然後將 o 找出來後,再將結果導入到 result 檔案內
(如果沒有 result 檔,會自己新建一個檔)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions