الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

fuser

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

المستوى
لينكس اليومي
المجموعة
العمليات والمهام
يحتاج root
للتغييرات
الحزمة
psmisc

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

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

الخيارات 17

الأكثر استخدامًا

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.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع 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.

انتبه

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

نصائح للحفظ

رموز الخروج

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

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man fuser