Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

fuser

Show which processes use a file, a folder, a mounted file system or a network port — and stop them if needed.

Level
Everyday Linux
Group
Processes and jobs
Needs root
For changes
Package
psmisc

What it does

fuser answers "who is using this?". The most common case is umount: target is busy: fuser -vm /mnt/usb lists the processes with files open on that file system. With -k it sends them a signal. It also works for ports: fuser 80/tcp prints the PID that owns TCP port 80.

The letter after each PID tells how the file is used: c = current folder, e = running program, f = open file, F = open for writing, r = root folder, m = memory-mapped.

How to write it

fuser [OPTION]... NAME...
fuser -k [-SIGNAL] [-i] NAME...

Options 17

Most used

Options

-v, --verbose
Show user, PID, access type and command.
-m, --mount NAME
All processes that use the file system NAME is on.
-M, --ismountpoint
Work only if NAME is a mount point.
-k, --kill
Kill the processes (default SIGKILL).
-SIGNAL
Use this signal with -k (-TERM, -HUP).
-i, --interactive
Ask before each kill.
-w
With -k: only processes that write.
-u, --user
Show the user of each process.
-n, --namespace SPACE
Name space: file, udp or tcp (fuser -n tcp 80).
-4, --ipv4 / -6, --ipv6
Only IPv4 / IPv6 sockets.
-a, --all
Also show files that nobody uses.
-s, --silent
No output; only the exit status.
-I, --inode
Compare by inode (for network file systems).
-l, --list-signals
List the signal names.
-c
Same as -m (POSIX).
-f
Ignored (POSIX).
-V, --version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Why does umount say "target is busy"?

    fuser -vm /mnt/usb
                         USER        PID ACCESS COMMAND
    /mnt/usb:            root     kernel mount /mnt/usb
                         student    4321 ..c.. bash

    The shell of student is inside the folder (c = current directory).

  2. 2Stop the processes, then unmount

    fuser -km -TERM /mnt/usb
    umount /mnt/usb
  3. 3Ask before every kill

    fuser -kim /srv/data
  4. 4Which process owns a port?

    fuser 80/tcp
    80/tcp:               1420
    fuser -v -n tcp 22
  5. 5Who has a log file open?

    fuser -v /var/log/messages
  6. 6Check in a script if a file is in use

    fuser -s /srv/import/data.csv && echo "still being written" || echo "free"
  7. 7Only processes that write to a file

    fuser -kw -TERM /srv/app/app.db
  8. 8Find users on an NFS mount before a server reboot

    fuser -vmu /mnt/shared
  9. 9Free a UDP port

    fuser -k 5353/udp
  10. 10Use the device name instead of the folder

    fuser -vm /dev/sdb1

    Same result as with the mount point; useful when you only know the device.

Watch out

  • fuser -k uses SIGKILL by default: no clean-up. Prefer -k -TERM first.
  • On / or /home, -km would kill almost everything. Always use -v first to look.

Tips to remember

Exit codes

0At least one process was found (or killed).
1No process uses the name, or an error.