Linux ‘fuser’ 命令常用示例


Linux 中的 fuser 實用程式是一個非常智慧的 Unix 實用程式。顧名思義,它提供了有關檔案使用者或當前正在使用檔案或目錄的程序的資訊。本文介紹了 Linux 中“fuser”命令的常用示例。

要獲取有關 fuser 的更多資訊,請使用以下命令:

$ fuser

示例輸出應如下所示:

Usage: fuser [-fMuvw] [-a|-s] [-4|-6] [-c|-m|-n SPACE] [-k [-i] [-SIGNAL]] NAME...
fuser -l
fuser -V
Show which processes use the named files, sockets, or filesystems.

-a,--all             display unused files too
-i,--interactive     ask before killing (ignored without -k)
-k,--kill            kill processes accessing the named file
-l,--list-signals    list available signal names
-m,--mount           show all processes using the named filesystems or block device
-M,--ismountpoint    fulfill request only if NAME is a mount point
-n,--namespace       SPACE search in this name space (file, udp, or tcp)
-s,--silent          silent operation
-SIGNAL              send this signal instead of SIGKILL
-u,--user            display user IDs
-v,--verbose         verbose output
-w,--writeonly       kill only processes with write access
-V,--version         display version information
-4,--ipv4            search IPv4 sockets only
-6,--ipv6            search IPv6 sockets only
-                    reset options

udp/tcp names: [local_port][,[rmt_host][,[rmt_port]]]

fuser 的用法

獲取程序 ID

要獲取正在使用當前目錄的程序 ID,請使用以下命令:

$ fuser .

示例輸出應如下所示:

/home/tutorialspoint: 2782c 2882c 2909c 2922c 2950c 2954c 2956c 2974c 
2984c 2986c 2993c 2994c 3003c 3004c 3011c 3018c 3034c 3053c 3068c 
3069c 3072c 3073c 3076c 3079c 3080c 3081c 3107c 3146c 3151c 3156c 
3157c 3164c 3321c 3361c 3368c 3369c 3440c 3502c 3786c 3859c 3866c

終止程序

要終止所有上述程序,請使用以下命令:

$ fuser -k .

以上命令將關閉所有程序並關閉 Linux 機器。

使用者名稱和程序 ID

要獲取 Linux 機器上的使用者名稱及其程序 ID,請使用以下命令:

$ fuser -u .

示例輸出應如下所示:

/home/tutorialspoint: 2782c(tutorialspoint) 2882c(tutorialspoint) 2909c(tutorialspoint) 
2922c(tutorialspoint) 2950c(tutorialspoint) 2954c(tutorialspoint) 2956c(tutorialspoint) 
2974c(tutorialspoint) 2984c(tutorialspoint) 2986c(tutorialspoint) 2993c(tutorialspoint) 
2994c(tutorialspoint) 3003c(tutorialspoint) 3004c(tutorialspoint) 3011c(tutorialspoint) 
3018c(tutorialspoint) 3034c(tutorialspoint) 3053c(tutorialspoint) 3068c(tutorialspoint) 
3069c(tutorialspoint) 3072c(tutorialspoint) 3073c(tutorialspoint) 3076c(tutorialspoint) 
3079c(tutorialspoint) 3080c(tutorialspoint) 3081c(tutorialspoint) 3107c(tutorialspoint) 
3146c(tutorialspoint) 3151c(tutorialspoint) 3156c(tutorialspoint)

已知訊號列表

要獲取當前程序的已知訊號列表,請使用以下命令:

$ fuser -l .

示例輸出應如下所示:

HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM
STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS
UNUSED

proc 檔案系統的位置

要查詢 proc 檔案系統的位置,請使用以下命令:

$ fuser /proc

示例輸出應如下所示:

/proc: 3373 3379

版本資訊

要獲取版本資訊,請使用以下命令:

$ fuser -V

示例輸出應如下所示:

fuser (PSmisc) 22.21
Copyright (C) 1993-2010 Werner Almesberger and Craig Small

PSmisc comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under
the terms of the GNU General Public License.
For more information about these matters, see the files named COPYING.

獲取當前目錄和當前程序

要獲取當前程序的當前執行目錄,請使用以下命令:

$ fuser -c ./

示例輸出應如下所示:

/home/tutorialspoint: 1rce 2rce 3rce 5rce 7rce 8rce 9rce 10rce 11rce 12rce 13rce 15rce 16rce 17rce 18rce 19rce 20rce 21rce 22rce 23rce 24rce 25rce 26rce 27rce 28rce 29rce 34rce 35rce 36rce 37rce 53rce 54rce 55rce

獲取程序 ID

要獲取當前使用者的程序 ID,請使用以下命令:

/home$ fuser -v tutorialspoint

以上命令中的 tutorials point 是當前使用者名稱。示例輸出應如下所示:

USER PID ACCESS COMMAND
/home/tutorialspoint:
tutorialspoint 2782 ..c.. upstart
tutorialspoint 2882 ..c.. window-stack-br
tutorialspoint 2909 ..c.. ibus-daemon
tutorialspoint 2922 ..c.. upstart-file-br
tutorialspoint 2950 ..c.. ibus-dconf
tutorialspoint 2954 ..c.. ibus-ui-gtk3
tutorialspoint 2956 ..c.. ibus-x11
tutorialspoint 2974 ..c.. bamfdaemon
tutorialspoint 2984 ..c.. hud-service
tutorialspoint 2986 ..c.. unity-settings-
tutorialspoint 2993 ..c.. at-spi-bus-laun
tutorialspoint 2994 ..c.. gnome-session-b
tutorialspoint 3003 ..c.. dbus-daemon
tutorialspoint 3004 ..c.. unity-panel-ser
....................................................................................

在以上文章中,我們學習了 Linux 中“fuser”命令的常用示例。在我們的下一篇文章中,我們將介紹更多基於 Linux 的技巧和提示。繼續關注!

更新於:2020年1月28日

瀏覽量:262

開啟您的職業生涯

完成課程獲得認證

開始學習
廣告