Frequently Used Examples of ‘Fuser’ Command in Linux

LinuxUnixSoftware & Coding

The fuser utility in Linux is a very smart Unix utility. As the name suggests, it offers knowledge about file user or the process that is currently utilizing the file or directory. This article explains about – Frequently used examples of ‘fuser’ Command in Linux.

To get the more information about fuser, use the following command –

$ fuser

The sample output should be like this –

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]]]

Usage of fuser

Getting the process ID

To get the process ID that is using the current directory, use the following command –

$ fuser .

The sample output should be like this –

/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

Killing processes

To kill all above processes, use the following command –

$ fuser -k .

The above command closes all the processes and shutdown the Linux machine.

Username with process ID’s

To get the username with process ID’s of Linux Machine, use the following command –

$ fuser -u .

The sample output should be like this –

/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)

List of Known signals

To get the list of known signals of current process, use the following command –

$ fuser -l .

The sample output should be like this –

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

Location of the proc file system

To find the location of the proc file system, use the following command –

$ fuser /proc

The sample output should be like this –

/proc: 3373 3379

Version information

To get the version information, use the following command –

$ fuser -V

The sample output should be like this –

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.

Getting current directories and current process

To get the current running directories of current process, use the following command –

$ fuser -c ./

The sample output should be like this –

/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

Getting the processID’s

To get the processID’s of current user, use the following command –

/home$ fuser -v tutorialspoint

The above command tutorials point is a current user name. The sample output should be like this –

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
....................................................................................

In the above article, we have learnt – Frequently used examples of ‘fuser’ Command in Linux. In our next articles, we will come up with more Linux based tricks and tips. Keep reading!

raja
Published on 28-Jan-2020 16:46:57
Advertisements