Mars Li
RD.TW
Published in
3 min readSep 16, 2019

--

工程師常用的 Linux Command

來源

筆記

【工作目錄內常用】

// 顯示當前工作目錄路徑
pwd - Print Working Directory
// 列出當前路徑所有內容
ls - List
// 在terminal上查看某個文件全部內容
cat - concatenate and print files
範例:cat meta.json
// 在terminal上查看某個文件倒數幾行內容
tail - print TAIL(from last)
範例(預設倒數10行):tail meta.json
範例(設定倒數20行):tail -n 20 meta.json
// 操作tar壓縮檔案
tar
範例(壓縮檔案):tar -cvf temp.tar temp.json
範例(查看壓縮檔案內容):tar -tvf temp.tar
範例(解壓縮):tar -xvf temp.tar
// 查看指令解釋
whatis
範例(查看cd解釋):whatis cd
(查看後如果要離開按q)

【檔案相關指令】

// 創建資料夾
mkdir - Make Directory
// 刪除檔案 rm
範例(刪除檔案):rm
範例(不提示刪除檔案):rm -f
範例(刪除文件夾內容):rm -r
範例(慎用:強制刪除文件夾底下所有檔案):rm -rf
// 複製檔案資料夾 cp
範例(複製檔案):cp /user1/from.txt /user2/desktop/to.txt
範例(複製資料夾):cp -r /from/user /to/
// 搬移檔案資料夾 mv
範例(搬移檔案且更名):mv /from/filename.txt /to/newfile.txt
範例(搬移檔案):mv filename.txt /to/
範例(搬移特定格式檔案):mv /from/*.txt /to/
範例(更名檔案): mv filename.txt newfile.txt
範例(搬移資料夾):mv /from/dirname/ /to/dir_name/

【網路相關指令】

// 通過發送數據包ping遠程主機(伺服器),常用與檢測網絡連接和伺服器狀態。
ping
範例(ping Google.com):ping google.com
(停止可以按control+c)
// 查IP
ifconfig en0

【系統相關指令】

// 顯示系統重要資訊
uname -a
// 查看現在用戶佔用最高CPU的所有process
top -u
// 殺死process
範例(依照進程PID殺死process):kill 1314
範例(強制依照進程PID殺死process):kill -9 1314
範例(依照進程名稱殺死process):kill firefox

--

--