[CMD101] Command Line 超新手入門


Posted by Torai on 2021-04-21

pwd              #Print Working Directory 印出當前路徑
ls               #LiSt 印出路徑下的檔案
cd <path>        #Change Directory 切換路徑到path資料夾
cd ..            #回到上一層
cd ~ <Downloads> # ~ 代表 Users/user/
clear            #把畫面清空

touch <file>     #建立檔案或更改時間
rm <file>        #ReMove file 刪除資料夾可用 rmdir dir 或是 rm -r dir
mkdir <dirname>  #MaKe DIRectory
mv <file> <file_or_directory> #MoVe 移動檔案或者改名

cp <source> <goal>    #CoPy 複製檔案
cp -r <source> <goal> #複製資料夾

vim <file>          #用vim文字編輯器打開檔案
cat <file1> <file2> #接連印出兩個檔案的內容,也可只輸入一個檔案當作印出內容
less <file>         #分頁式印出檔案,按 q 離開

grep <string> <file> #搜尋字元
wget <url>           #由網址下載檔案
open <file>          #打開檔案
curl <url>           #送出 request

#redirection `>`
echo "123" > 123.txt #將內容輸出到 123.txt 之中,會蓋掉原有內容,若沒有檔案則會新增一個。
echo "append to the end of the file" >> 123.txt #將輸出內容附加到 123.txt 之中,若沒有檔案則會新增

#pipe `|`
#將前項的輸出結果當作後項的參數輸入
cat hello | grep o > result

which <command>     #印出此指令的執行檔位置
ping <ip>           #丟一個封包過去伺服器,紀錄來回所花的時間
nslookup google.com #查詢 google 的 ip 位置

#查詢功能與說明
man <command>
info <command>
<command> --help #windows 用這個或 /?

top  #table of processes
date #print current date

Vim

i 進入編輯模式,可以打字。
Esc 進入普通模式。
簡單說明

String Handling

#搜尋字串,搜到則印出一整行 -E 則使用 RegExp
grep "match_pattern" file_name

#在一整行中印出特定欄位
# -F '"' 可把分隔符改成"
awk {‘print $欄位 $欄位 $欄位 ….’}

#剪出特定的片段
# https://en.wikipedia.org/wiki/Cut_(Unix)
cut [-b list] [-c list] [-f list] [-n] [-d delim] [-s] [file]

#把 pen 取代成 pencil
sed -e 's/pen/pencil/'

#note







Related Posts

將陣列裡面物件的一樣屬性整理一起

將陣列裡面物件的一樣屬性整理一起

W17_直播檢討

W17_直播檢討

菜比八寫後端(2) - MySQL語法

菜比八寫後端(2) - MySQL語法


Comments