首頁/ 汽車/ 正文

Linux中20個高階命令

41。 ifconfig命令

ifconfig

用於配置核心常駐網路介面。它用於在啟動時根據需要設定介面。

檢查活動網路介面

[rumenz@local ~]$ ifconfig eth0 Link encap:Ethernet HWaddr 40:2C:F4:EA:CF:0E inet addr:192。168。1。3 Bcast:192。168。1。255 Mask:255。255。255。0 inet6 addr: fe80::422c:f4ff:feea:cf0e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:163843 errors:0 dropped:0 overruns:0 frame:0 TX packets:124990 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:154389832 (147。2 MiB) TX bytes:65085817 (62。0 MiB) Interrupt:20 Memory:f7100000-f7120000 lo Link encap:Local Loopback inet addr:127。0。0。1 Mask:255。0。0。0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:78 errors:0 dropped:0 overruns:0 frame:0 TX packets:78 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:4186 (4。0 KiB) TX bytes:4186 (4。0 KiB)

檢查所有網路介面

使用

-a

顯示所有介面的詳細資訊

[rumenz@local ~]$ ifconfig -aeth0 Link encap:Ethernet HWaddr 40:2C:F4:EA:CF:0E inet addr:192。168。1。3 Bcast:192。168。1。255 Mask:255。255。255。0 inet6 addr: fe80::422c:f4ff:feea:cf0e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:163843 errors:0 dropped:0 overruns:0 frame:0 TX packets:124990 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:154389832 (147。2 MiB) TX bytes:65085817 (62。0 MiB) Interrupt:20 Memory:f7100000-f7120000 lo Link encap:Local Loopback inet addr:127。0。0。1 Mask:255。0。0。0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:78 errors:0 dropped:0 overruns:0 frame:0 TX packets:78 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:4186 (4。0 KiB) TX bytes:4186 (4。0 KiB) virbr0 Link encap:Ethernet HWaddr 0e:30:a3:3a:bf:03 inet addr:192。168。122。1 Bcast:192。168。122。255 Mask:255。255。255。0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0。0 B) TX bytes:0 (0。0 B)

禁用網絡卡

[rumenz@local ~]$ ifconfig eth0 down

啟用網絡卡

[rumenz@local ~]$ ifconfig eth0 up

為網絡卡分配 IP 地址

指定

192。168。1。12

作為網絡卡 eth0 的 IP 地址。

[rumenz@local ~]$ ifconfig eth0 192。168。1。12

更改網絡卡eth0的子網掩碼

[rumenz@local ~]$ ifconfig eth0 netmask 255。255。255。

更改網絡卡 eth0 的廣播地址

[rumenz@local ~]$ ifconfig eth0 broadcast 192。168。1。255

為網絡卡 eth0 分配 IP 地址、網路掩碼和廣播

[rumenz@local ~]$ ifconfig eth0 192。168。1。12 netmask 255。255。255。0 broadcast 192。168。1。255

Note

: 如果使用無線網路,則需要使用命令

iwconfig

。欲瞭解更多

ifconfig

命令示例和用法,請閱讀[15 個有用的

ifconfig

命令]。

42。 netstat命令

netstat

命令顯示各種網路相關資訊,如網路連線、路由表

列出所有網路埠

[rumenz@local ~]$ netstat -aActive UNIX domain sockets (servers and established)Proto RefCnt Flags Type State I-Node Pathunix 2 [ ACC ] STREAM LISTENING 741379 /run/user/user1/keyring-I5cn1c/gpgunix 2 [ ACC ] STREAM LISTENING 8965 /var/run/acpid。socketunix 2 [ ACC ] STREAM LISTENING 18584 /tmp/。X11-unix/X0unix 2 [ ACC ] STREAM LISTENING 741385 /run/user/user1/keyring-I5cn1c/sshunix 2 [ ACC ] STREAM LISTENING 741387 /run/user/user1/keyring-I5cn1c/pkcs11unix 2 [ ACC ] STREAM LISTENING 20242 @/tmp/dbus-ghtTjuPN46unix 2 [ ACC ] STREAM LISTENING 13332 /var/run/samba/winbindd_privileged/pipeunix 2 [ ACC ] STREAM LISTENING 13331 /tmp/。winbindd/pipeunix 2 [ ACC ] STREAM LISTENING 11030 /var/run/mysqld/mysqld。sockunix 2 [ ACC ] STREAM LISTENING 19308 /tmp/ssh-qnZadSgJAbqd/agent。3221unix 2 [ ACC ] STREAM LISTENING 436781 /tmp/HotShotsunix 2 [ ACC ] STREAM LISTENING 46110 /run/user/ravisaive/pulse/nativeunix 2 [ ACC ] STREAM LISTENING 19310 /tmp/gpg-zfE9YT/S。gpg-agent。。。。

列出所有 TCP 埠

[rumenz@local ~]$ netstat -atActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhost:mysql *:* LISTEN tcp 0 0 *:5901 *:* LISTEN tcp 0 0 *:5902 *:* LISTEN tcp 0 0 *:x11-1 *:* LISTEN tcp 0 0 *:x11-2 *:* LISTEN tcp 0 0 *:5938 *:* LISTEN tcp 0 0 localhost:5940 *:* LISTEN tcp 0 0 ravisaive-OptiPl:domain *:* LISTEN tcp 0 0 ravisaive-OptiPl:domain *:* LISTEN tcp 0 0 localhost:ipp *:* LISTEN tcp 0 0 ravisaive-OptiPle:48270 ec2-23-21-236-70。c:http ESTABLISHEDtcp 0 0 ravisaive-OptiPle:48272 ec2-23-21-236-70。c:http TIME_WAIT tcp 0 0 ravisaive-OptiPle:48421 bom03s01-in-f22。1:https ESTABLISHEDtcp 0 0 ravisaive-OptiPle:48269 ec2-23-21-236-70。c:http ESTABLISHEDtcp 0 0 ravisaive-OptiPle:39084 channel-ecmp-06-f:https ESTABLISHED。。。

顯示所有埠的統計資訊

[rumenz@local ~]$ netstat -sIp: 4994239 total packets received 0 forwarded 0 incoming packets discarded 4165741 incoming packets delivered 3248924 requests sent out 8 outgoing packets droppedIcmp: 29460 ICMP messages received 566 input ICMP message failed。 ICMP input histogram: destination unreachable: 98 redirects: 29362 2918 ICMP messages sent 0 ICMP messages failed ICMP output histogram: destination unreachable: 2918IcmpMsg: InType3: 98 InType5: 29362 OutType3: 2918Tcp: 94533 active connections openings 23 passive connection openings 5870 failed connection attempts 7194 connection resets received。。。。

如果你不想將主機、埠和使用者名稱解析為 netstat 的輸出。

[rumenz@local ~]$ netstat -an

你可能需要不斷獲取 netstat 的輸出,直到透過中斷指令(

ctrl+c

)。

[rumenz@local ~]$ netstat -c

43。 nslookup命令

一種網路實用程式,用於獲取有關 Internet 伺服器的資訊。顧名思義,該實用程式透過查詢來查詢域的名稱伺服器資訊

DNS

[rumenz@local ~]$ nslookup rumenz。com Server: 192。168。1。1 Address: 192。168。1。1#53 Non-authoritative answer: Name: rumenz。com Address: 50。16。67。239

查詢郵件交換記錄

[rumenz@local ~]$ nslookup -query=mx rumenz。com Server: 192。168。1。1 Address: 192。168。1。1#53 Non-authoritative answer: rumenz。com mail exchanger = 0 smtp。secureserver。net。 rumenz。com mail exchanger = 10 mailstore1。secureserver。net。 Authoritative answers can be found from:

查詢名稱伺服器

[rumenz@local ~]$ nslookup -type=ns rumenz。com Server: 192。168。1。1 Address: 192。168。1。1#53 Non-authoritative answer: rumenz。com nameserver = ns3404。com。 rumenz。com nameserver = ns3403。com。 Authoritative answers can be found from:

查詢 DNS 記錄

[rumenz@local ~]$ nslookup -type=any rumenz。com Server: 192。168。1。1 Address: 192。168。1。1#53 Non-authoritative answer: rumenz。com mail exchanger = 10 mailstore1。secureserver。net。 rumenz。com mail exchanger = 0 smtp。secureserver。net。 rumenz。com nameserver = ns06。domaincontrol。com。 rumenz。com nameserver = ns3404。com。 rumenz。com nameserver = ns3403。com。 rumenz。com nameserver = ns05。domaincontrol。com。 Authoritative answers can be found from:

查詢許可權開始

[rumenz@local ~]$ nslookup -type=soa rumenz。com Server: 192。168。1。1 Address: 192。168。1。1#53 Non-authoritative answer: rumenz。com origin = ns3403。hostgator。com mail addr = dnsadmin。gator1702。hostgator。com serial = 2012081102 refresh = 86400 retry = 7200 expire = 3600000 minimum = 86400 Authoritative answers can be found from:

查詢埠號

更改要連線的埠號

[rumenz@local ~]$ nslookup -port 56 rumenz。comServer: rumenz。comAddress: 50。16。76。239#53Name: 56Address: 14。13。253。12

44。 dig命令

dig

是一個查詢工具

DNS

nameservers 獲取有關主機地址、郵件交換、名稱伺服器和相關資訊的資訊。這個工具可以在任何 Linux (

Unix

) 或

Macintosh OS X

作業系統。最典型的用途

dig

是簡單地查詢單個主機。

[rumenz@local ~]$ dig rumenz。com; <<>> DiG 9。8。2rc1-RedHat-9。8。2-0。17。rc1。el6 <<>> rumenz。com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<

關閉註釋行

[rumenz@local ~]$ dig rumenz。com +nocomments ; <<>> DiG 9。8。2rc1-RedHat-9。8。2-0。17。rc1。el6 <<>> rumenz。com +nocomments ;; global options: +cmd ;rumenz。com。 IN A rumenz。com。 14400 IN A 40。216。66。239 ;; Query time: 418 msec ;; SERVER: 192。168。1。1#53(192。168。1。1) ;; WHEN: Sat Jun 29 13:53:22 2013 ;; MSG SIZE rcvd: 45

關閉來源段

[rumenz@local ~]$ dig rumenz。com +noauthority ; <<>> DiG 9。8。2rc1-RedHat-9。8。2-0。17。rc1。el6 <<>> rumenz。com +noauthority ;; global options: +cmd ;; Got answer: ;; ->>HEADER<

關閉附加段

[rumenz@local ~]$ dig rumenz。com +noadditional ; <<>> DiG 9。9。2-P1 <<>> rumenz。com +noadditional;; global options: +cmd;; Got answer:;; ->>HEADER<

關閉統計段

[rumenz@local ~]$ dig rumenz。com +nostats ; <<>> DiG 9。8。2rc1-RedHat-9。8。2-0。17。rc1。el6 <<>> rumenz。com +nostats ;; global options: +cmd ;; Got answer: ;; ->>HEADER<

關閉結果段

[rumenz@local ~]$ dig rumenz。com +noanswer ; <<>> DiG 9。8。2rc1-RedHat-9。8。2-0。17。rc1。el6 <<>> rumenz。com +noanswer ;; global options: +cmd ;; Got answer: ;; ->>HEADER<

一次禁用所有部分

[rumenz@local ~]$ dig rumenz。com +noall ; <<>> DiG 9。8。2rc1-RedHat-9。8。2-0。17。rc1。el6 <<>> rumenz。com +noall ;; global options: +cmd

45。 uptime命令

uptime命令能夠列印系統總共運行了多長時間和系統的平均負載

[rumenz@local ~]$ uptime14:37:10 up 4:21, 2 users, load average: 0。00, 0。00, 0。04

46。 wall命令

管理員最重要的命令之一,

wall

向使用他們登入的每個人傳送訊息

mesg

許可權設定為

yes

。該訊息可以作為引數給出

wall

,也可以傳送到 wall 的標準輸入。

[rumenz@local ~]$ wall “we will be going down for maintenance for one hour sharply at 03:30 pm”Broadcast message from root@localhost。localdomain (pts/0) (Sat Jun 29 14:44:02 2013): we will be going down for maintenance for one hour sharply at 03:30 pm

47。 mesg命令

讓你控制人們是否可以使用

write

命令,透過螢幕向你傳送文字。

mesg [n|y]n - prevents the message from others popping up on the screen。y – Allows messages to appear on your screen。

48。 write命令

讓你直接將文字傳送到另一臺 Linux 機器的螢幕,如果

mesg

y

[rumenz@local ~]$ write ravisaive

49。 talk命令

write

命令,

talk

命令可讓你與登入使用者交談。

[rumenz@local ~]$ talk ravisaive

Note

: 如果

talk

命令未安裝,你可以隨時

apt

yum

所需的包。

[rumenz@local ~]$ yum install talkOR[rumenz@local ~]$ apt-get install talk

50。 w命令

什麼命令

w

看起來你很有趣嗎?但實際上並非如此。這是一個命令,即使它只有一個字母長!命令

w

的組合

uptime

who

命令一個接一個地發出,按照這個順序。

[rumenz@local ~]$ w15:05:42 up 4:49, 3 users, load average: 0。02, 0。01, 0。00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT server tty7 :0 14:06 4:43m 1:42 0。08s pam: gdm-passwo server pts/0 :0。0 14:18 0。00s 0。23s 1。65s gnome-terminal server pts/1 :0。0 14:47 4:43 0。01s 0。01s bash

51。 rename命令

顧名思義,此命令重新命名檔案。rename 將透過替換檔名中的第一個匹配項來重新命名指定的檔案。

Give the file names a1, a2, a3, a4。。。。。1213

只需鍵入命令。

rename a1 a0 a? rename a1 a0 a??

52。 命令:top

顯示程序

CPU

。預設情況下,此命令會自動重新整理並繼續顯示

CPU

除非給出中斷指令,否則處理。

[rumenz@local ~]$ toptop - 14:06:45 up 10 days, 20:57, 2 users, load average: 0。10, 0。16, 0。21Tasks: 240 total, 1 running, 235 sleeping, 0 stopped, 4 zombie%Cpu(s): 2。0 us, 0。5 sy, 0。0 ni, 97。5 id, 0。0 wa, 0。0 hi, 0。0 si, 0。0 stKiB Mem: 2028240 total, 1777848 used, 250392 free, 81804 buffersKiB Swap: 3905532 total, 156748 used, 3748784 free, 381456 cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 23768 ravisaiv 20 0 1428m 571m 41m S 2。3 28。9 14:27。52 firefox 24182 ravisaiv 20 0 511m 132m 25m S 1。7 6。7 2:45。94 plugin-containe 26929 ravisaiv 20 0 5344 1432 972 R 0。7 0。1 0:00。07 top 24875 ravisaiv 20 0 263m 14m 10m S 0。3 0。7 0:02。76 lxterminal 1 root 20 0 3896 1928 1228 S 0。0 0。1 0:01。62 init 2 root 20 0 0 0 0 S 0。0 0。0 0:00。06 kthreadd 3 root 20 0 0 0 0 S 0。0 0。0 0:17。28 ksoftirqd/0 5 root 0 -20 0 0 0 S 0。0 0。0 0:00。00 kworker/0:0H 7 root 0 -20 0 0 0 S 0。0 0。0 0:00。00 kworker/u:0H 8 root rt 0 0 0 0 S 0。0 0。0 0:00。12 migration/0 9 root 20 0 0 0 0 S 0。0 0。0 0:00。00 rcu_bh 10 root 20 0 0 0 0 S 0。0 0。0 0:26。94 rcu_sched 11 root rt 0 0 0 0 S 0。0 0。0 0:01。95 watchdog/0 12 root rt 0 0 0 0 S 0。0 0。0 0:02。00 watchdog/1 13 root 20 0 0 0 0 S 0。0 0。0 0:17。80 ksoftirqd/1 14 root rt 0 0 0 0 S 0。0 0。0 0:00。12 migration/1 16 root 0 -20 0 0 0 S 0。0 0。0 0:00。00 kworker/1:0H 17 root 0 -20 0 0 0 S 0。0 0。0 0:00。00 cpuset 18 root 0 -20 0 0 0 S 0。0 0。0 0:00。00 khelper 19 root 20 0 0 0 0 S 0。0 0。0 0:00。00 kdevtmpfs 20 root 0 -20 0 0 0 S 0。0 0。0 0:00。00 netns 21 root 20 0 0 0 0 S 0。0 0。0 0:00。04 bdi-default 22 root 0 -20 0 0 0 S 0。0 0。0 0:00。00 kintegrityd 23 root 0 -20 0 0 0 S 0。0 0。0 0:00。00 kblockd 24 root 0 -20 0 0 0 S 0。0 0。0 0:00。00 ata_sff

53。 mkfs。ext4命令

此命令建立一個新的

ext4

指定裝置上的檔案系統,如果在此命令後跟隨錯誤的裝置,整個塊將被擦除和格式化,因此建議不要執行此命令,除非並且直到你明白你在做什麼。

Mkfs。ext4 /dev/sda1 (sda1 block will be formatted)mkfs。ext4 /dev/sdb1 (sdb1 block will be formatted)

54。 命令:vi/emacs/nano

vi

emacs

nano

是 Linux 中一些最常用的編輯器。它們通常用於編輯文字、配置、檔案。

vi 編輯器

[rumenz@local ~]$ touch a。txt (creates a text file a。txt) [rumenz@local ~]$ vi a。txt (open a。txt with vi editor)

[按

i

進入插入模式,否則你將無法輸入任何內容]

echo “Hello” (your text here for the file)

alt+x

(退出插入模式,記得在最後一個字母之間保留一些空格。

ctrl+x

命令或你的最後一句話將被刪除)。

:wq!

(儲存檔案,用當前文字,記住

是覆蓋)。

nano編輯器

[rumenz@local ~]$ nano a。txt (open a。txt file to be edited with nano)

edit, with the content, required

ctrl +x(關閉編輯器)。它將顯示輸出為:

Save modified buffer (ANSWERING “No” WILL DESTROY CHANGES) ? Y Yes N No ^C Cancel

點選

y

到 yes 並輸入檔名,你就完成了。

55。 命令:rsync

Rsync

複製檔案並有一個

-P

切換進度條。所以如果你安裝了 rsync,你可以使用一個簡單的別名。

alias cp=‘rsync -aP’

現在嘗試在終端中複製一個大檔案並檢視包含剩餘專案的輸出,類似於進度條。

此外,保持和維護備份是系統管理員需要執行的最重要和最無聊的工作之一。Rsync 是一個非常好的工具(存在,還有其他幾個)用於在終端中建立和維護備份。

[rumenz@local ~]$ rsync -zvr IMG_5267\ copy\=33\ copy\=ok。jpg ~/Desktop/ sending incremental file list IMG_5267 copy=33 copy=ok。jpg sent 2883830 bytes received 31 bytes 5767722。00 bytes/sec total size is 2882771 speedup is 1。00

Note

-z

用於壓縮,-v 用於詳細,-r 用於遞迴。

56。 free命令

跟蹤記憶體和資源與管理員執行的任何其他任務一樣重要,並且

free

命令來拯救這裡。

記憶體使用現狀

[rumenz@local ~]$ free total used free shared buffers cachedMem: 2028240 1788272 239968 0 69468 363716-/+ buffers/cache: 1355088 673152Swap: 3905532 157076 3748456

> 以 KB、MB 或 GB 為單位的調諧輸出

[rumenz@local ~]$ free -b total used free shared buffers cachedMem: 2076917760 1838272512 238645248 0 71348224 372670464-/+ buffers/cache: 1394253824 682663936Swap: 3999264768 160845824 3838418944

[rumenz@local ~]$ free -k total used free shared buffers cachedMem: 2028240 1801484 226756 0 69948 363704-/+ buffers/cache: 1367832 660408Swap: 3905532 157076 3748456

[rumenz@local ~]$ free -m total used free shared buffers cachedMem: 1980 1762 218 0 68 355-/+ buffers/cache: 1338 641Swap: 3813 153 3660

[rumenz@local ~]$ free -g total used free shared buffers cachedMem: 1 1 0 0 0 0-/+ buffers/cache: 1 0Swap: 3 0 3

人類可讀格式展示

[rumenz@local ~]$ free -h total used free shared buffers cachedMem: 1。9G 1。7G 208M 0B 68M 355M-/+ buffers/cache: 1。3G 632MSwap: 3。7G 153M 3。6G

定期檢查輸出

[rumenz@local ~]$ free -s 3 total used free shared buffers cachedMem: 2028240 1824096 204144 0 70708 364180-/+ buffers/cache: 1389208 639032Swap: 3905532 157076 3748456 total used free shared buffers cachedMem: 2028240 1824192 204048 0 70716 364212-/+ buffers/cache: 1389264 638976Swap: 3905532 157076 3748456

57。 mysqldump命令

你應該已經從該命令的名稱中瞭解了該命令的實際含義。

mysqldump

命令將所有或特定的資料庫資料轉儲(備份)到給定的檔案中。例如,

[rumenz@local ~]$ mysqldump -u root -p ——all-databases > /home/server/Desktop/backupfile。sql

Note

mysqldump

需要執行 mysql 並正確密碼進行授權。我們已經介紹了一些有用的

mysqldump

使用 mysqldump命令進行資料庫備份的命令

58。 mkpasswd命令

製作指定長度的難以猜測的隨機密碼。

[rumenz@local ~]$ mkpasswd -l 10zI4+Ybqfx9

[rumenz@local ~]$ mkpasswd -l 20 w0Pr7aqKk&hmbmqdrlmk

Note

-l 10

生成一個隨機密碼

10

字元而

-l 20

生成字元密碼

20

,它可以設定為任何以獲得所需的結果。此命令非常有用,通常以指令碼語言實現以生成隨機密碼。你可能需要

yum

apt

expect‘ 包來使用這個命令。

[root@rumenz ~]# yum install expect OR[root@rumenz ~]# apt-get install expect

59。 paste命令

使用行合併兩個或多個文字檔案

[rumenz@local ~] cat rumenz1。txt #rumenz1。txt檔案的內容 123[rumenz@local ~] cat rumenz2。txt #rumenz2。txt 檔案的內容 4[rumenz@local ~] cat rumenz3。txt #rumenz3。txt檔案的內容 56[rumenz@local ~] paste rumenz1。txt rumenz2。txt rumenz3。txt 123456

60。 lsof命令

lsof

代表

list open files

並顯示你的系統當前開啟的所有檔案。找出哪些程序使用某個檔案或顯示單個程序的所有檔案非常有用。

[rumenz@local ~]$ lsof COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAMEinit 1 root cwd DIR 8,1 4096 2 /init 1 root rtd DIR 8,1 4096 2 /init 1 root txt REG 8,1 227432 395571 /sbin/init。。。

相關文章

頂部