N個你可能不曾用過的Linux命令

N個你可能不曾用過的Linux命令

N個你可能不曾用過的Linux命令


資料來源: https://mp.weixin.qq.com/s?__biz=MzIwNTc4NTEwOQ==&mid=2247487971&idx=2&sn=9681f579dba483e2361aeb49fa079962&chksm=972ac099a05d498ff4c901a927bf8d1e067a08cc5055810846beb53422e828bd1df588381abd&scene=126&sessionid=1585181458&key=d1ea58609fa1095895e8e7c3c94fe4ac13483228c82e90f966d4886ee71fe746b11afcb77f7933b596a9930a75f809e1053014784aabff34757d45f6169e5edad1b2f99c6d989642685b1cf52c4c54d4&ascene=1&uin=MjIwODk2NDgxNw%3D%3D&devicetype=Windows+10&version=62080079&lang=zh_TW&exportkey=AvqlSHiLcZiovp8Co%2FS8l4s%3D&pass_ticket=gwuYjl12SVj0uTB9Wc%2BvBkx7KJvIo%2BdbFW8R3UxwJwOqHqbIz07uuIa4yFs7KuQK


1)pgrep[查詢程式/進程 ID]

pgrep名字前有個p,我們可以猜到這和進展相關,又是grep,當然這是進程相關的grep命令。不過,這個命令主要是用作推進ID的

$ pgrep -u hchen
22441
22444

等同

ps -ef | egrep  ^hchen  | awk  {print $2}

2)pstree[查詢程式/進程的樹狀圖]
這個命令可以以樹形的方式列出進展

[hchen@RHELSVR5 ~]$ pstree
init-+-acpid
     |-auditd-+-python
     |        `-{auditd}
     |-automount---4*[{automount}]
     |-backup.sh---sleep
     |-dbus-daemon
     |-events/0
     |-events/1
     |-hald---hald-runner---hald-addon-acpi
     |-httpd---10*[httpd]
     |-irqbalance
     |-khelper
     |-klogd
     |-ksoftirqd/0
     |-ksoftirqd/1
     |-kthread-+-aio/0
     |         |-aio/1
     |         |-ata/0
     |         |-ata/1
     |         |-ata_aux
     |         |-cqueue/0
     |         |-cqueue/1
     |         |-kacpid
     |         |-kauditd
     |         |-kblockd/0
     |         |-kblockd/1
     |         |-kedac
     |         |-khubd
     |         |-6*[kjournald]
     |         |-kmirrord
     |         |-kpsmoused
     |         |-kseriod
     |         |-kswapd0
     |         |-2*[pdflush]
     |         |-scsi_eh_0
     |         |-scsi_eh_1
     |         |-xenbus
     |         `-xenwatch
     |-migration/0
     |-migration/1
     |-6*[mingetty]
     |-3*[multilog]
     |-mysqld_safe---mysqld---9*[{mysqld}]
     |-smartd
     |-sshd---sshd---sshd---bash---pstree
     |-svscanboot---svscan-+-3*[supervise---run]
     |                     |-supervise---qmail-send-+-qmail-clean
     |                     |                        |-qmail-lspawn
     |                     |                        `-qmail-rspawn
     |                     `-2*[supervise---tcpserver]
     |-syslogd
     |-udevd
     |-watchdog/0
     |-watchdog/1
     `-xinetd

3)分割檔案 & 合併檔案
split -b 50m 檔名 LF_
cat LF_* >檔名

[hchen@RHELSVR5 applebak]# ls -l largefile.tar.gz
-rw-r--r-- 1 hchen hchen 436774774 04-17 02:00 largefile.tar.gz

[hchen@RHELSVR5 applebak]# split -b 50m largefile.tar.gz LF_

[hchen@RHELSVR5]# ls -l LF_*
-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_aa
-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ab
-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ac
-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ad
-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ae
-rw-r--r-- 1 hchen hchen 52428800 05-10 18:35 LF_af
-rw-r--r-- 1 hchen hchen 52428800 05-10 18:35 LF_ag
-rw-r--r-- 1 hchen hchen 52428800 05-10 18:35 LF_ah
-rw-r--r-- 1 hchen hchen 17344374 05-10 18:35 LF_ai

[hchen@RHELSVR5]#  cat LF_* >largefile.tar.gz

4)ldd[查詢 動態連結檔]
這個命令可以知道你的一個單一文件所使用了動態鏈接庫。

[hchen@RHELSVR5 ~]# ldd /usr/bin/java
        linux-gate.so.1 =>  (0x00cd9000)
        libgij.so.7rh => /usr/lib/libgij.so.7rh (0x00ed3000)
        libgcj.so.7rh => /usr/lib/libgcj.so.7rh (0x00ed6000)
        libpthread.so.0 => /lib/i686/nosegneg/libpthread.so.0 (0x00110000)
        librt.so.1 => /lib/i686/nosegneg/librt.so.1 (0x009c8000)
        libdl.so.2 => /lib/libdl.so.2 (0x008b5000)
        libz.so.1 => /usr/lib/libz.so.1 (0x00bee000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00aa7000)
        libc.so.6 => /lib/i686/nosegneg/libc.so.6 (0x0022f000)
        libm.so.6 => /lib/i686/nosegneg/libm.so.6 (0x00127000)
        /lib/ld-linux.so.2 (0x00214000)


5)lsof [列出 特定 人/程式… 所開啟的文件]
可以列出打開了的文件。

[root@RHELSVR5 ~]# lsof | grep TCP
httpd       548    apache    4u     IPv6   14300967    TCP *:http (LISTEN)
httpd       548    apache    6u     IPv6   14300972    TCP *:https (LISTEN)
httpd       561    apache    4u     IPv6   14300967    TCP *:http (LISTEN)
httpd       561    apache    6u     IPv6   14300972    TCP *:https (LISTEN)
sshd       1764      root    3u     IPv6       4993    TCP *:ssh (LISTEN)
tcpserver  8965      root    3u     IPv4  153795500    TCP *:pop3 (LISTEN)
mysqld    10202     mysql   10u     IPv4   73819697    TCP *:mysql (LISTEN)
sshd      10735      root    3u     IPv6  160731956    TCP 210.51.0.232:ssh->123.117.239.68:31810 (ESTABLISHED)
sshd      10767     hchen    3u     IPv6  160731956    TCP 210.51.0.232:ssh->123.117.239.68:31810 (ESTABLISHED)
vsftpd    11095      root    3u     IPv4  152157957    TCP *:ftp (LISTEN)

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *