Session and utilities

The fuser command

Says which processes are using a file, a folder, a file system or a port.

Syntax

fuser [opciones] archivo... | fuser -n tcp puertoTry it in the terminal →

Most useful options

-aAlso shows files that no process is using.
-sSilent: writes nothing. Useful with if to know only whether something uses the file.
-uAppends the owner of each process next to its PID.
-vVerbose output in a ps-like format, with user, PID, access type and command.
-m <nombre>Finds all processes using files on that mounted file system. Useful before unmounting a USB stick.
-MOnly works if the name is a mount point. It prevents working on a folder by mistake.
-n tcp | udpSearches by TCP or UDP port instead of by file.
-kSends a signal to the processes using the file. By default it is SIGKILL, which does not let them close cleanly.

Copy-ready examples

$ printf 'x\n' > f.txt && fuser f.txtasks who is using the file just created. If nobody uses it, it prints nothing.
$ fuser -a f.txtshows the file even if no process is using it.
$ fuser -v -n tcp 8080which processes use TCP port 8080, in detailed format.
$ fuser -m /media/usbprocesses using something on that mounted file system, before unmounting it.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
Specified filename f.txt does not exist.The name does not exist in the folder you are in, or it is misspelled.List the folder with ls and pass the exact path.
Specified filename /media/usb has no mountpoint.You used -M with a path that is not a mount point. That option only accepts mount points.Remove -M or give the real mount point, found with findmnt.

Typical mistakes

  • Without root, fuser cannot see the file descriptors of other users: it may return an empty result even though processes are using the file.
  • With -k, the default signal is SIGKILL. Add -i to be asked before each process is killed, or choose another signal with -SIGNAL.
  • PIDs go to standard output and everything else (names, access letters) to standard error. With a pipe you lose the file name.

Differences from similar commands

  • lsof: lists each file a process has open. fuser only says which processes use a file or port, with their PIDs.
  • ss: shows network sockets and their process. For ports, fuser -n tcp searches directly by number.

Security

fuser -k terminates processes that may belong to other users if you have permission. Before killing anything, list the PIDs with fuser -v and confirm what they are.

Related commands

FAQ

What do the access letters mean?

c is the current directory, e an executable, f an open file, F a file open for writing, r the root directory and m a memory-mapped file. With -v you see them in the ACCESS column.

How do I use fuser inside a script?

With -s inside an if: it returns zero if at least one process uses the file, and non-zero if nobody does or there is an error.

Can I use fuser to check a port that is not mine?

Yes, but without root it may not show other users' processes. Closing one requires permission over that process.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course