Linux常用指令

Linux常用指令

切換root權限

1
$ su -

新增檔案

1
$ touch test.sh

查本機對外IP

1
$ curl ipconfig.me

查看檔案

1
$ less test.sh

編輯檔案

1
$ vim test.sh

刪除檔案

1
$ rm -f test.sh

查看硬碟空間

1
$ df

複製檔案

1
$ cp -r /root/test.sh /root/test/test.sh

scp檔案從目前Server複製檔案至另一台Server(保留檔案時間與權限)

1
$ scp -p /root/test.sh [email protected]:/root/test.sh

取得Linux安裝的系統版本

1
$ uname -a

解壓縮.tar.gz

1
$ tar zxvf "FileName".tar.gz

新建立使用者,先登入root權限

1
$ useradd "username"

替使用者新增密碼

1
$ passwd "username"

Linux觀察系統資源常用指令

效能分析工具,能夠即時顯示系統中各個行程的資源佔用狀況

1
$ top

觀察系統啟動時間與工作負載

1
$ uptime

查看記憶體的使用狀態

1
$ free -h

查看特定process所使用Memory和CPU,依據使用記憶體排序

1
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | grep java

查看該使用者所使用process數量

1
ps -u "User" -L | wc -l

Linux網路常用指令

查詢網路卡狀態

1
$ ifconfig

查看網路傳送的路由情況

1
$ route

查看對方網路是否有通

1
$ ping www.google.com.tw

查詢或反查詢DNS

1
2
$ nslookup www.google.com.tw
$ nslookup 8.8.8.8

追蹤通訊包傳送的狀態

1
2
$ traceroute www.google.com.tw
$ traceroute 8.8.8.8

查詢Local IP

1
$ ip addr show

查詢硬體指令(CPU…等)

1
cat /proc/cpuinfo