هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
On Linux "everything is a file", so lsof sees a lot: normal files, folders, libraries, devices, pipes and network connections. Admins use it to find who keeps a mount busy, which program listens on a port, why disk space is not freed after deleting a big log (+L1), or which files a suspicious process has open.
Selections are joined with OR by default; add -a to join them with AND (lsof -a -u apache -i). Run it as root to see the files of all users.
طريقة الكتابة
lsof [OPTION]... [--] [FILE]...الخيارات 33
الأكثر استخدامًا
Select what to show
Output
-t- Print only PIDs (for
kill $(lsof -t …)).
Speed and safety
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 11
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1Who keeps a mount busy?
lsof +f -- /mnt/usb COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 4321 student cwd DIR 8,1 4096 1 /mnt/usb less 4402 student 4r REG 8,1 10240 12 /mnt/usb/report.txt2Which program listens on a port?
lsof -nP -iTCP:443 -sTCP:LISTEN COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 1420 root 6u IPv6 23511 0t0 TCP *:443 (LISTEN)3All network connections of one user
lsof -a -nP -u apache -i4Disk full, but du shows less? Find deleted files that are still open
lsof -nP +L1 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME java 2210 app 7w REG 253,0 8589934592 0 1312 /var/log/app/app.log (deleted)8 GiB still used by PID 2210. Restart the app (or truncate via /proc/2210/fd/7) to free the space.
5Files of one process
lsof -p 1420 | head lsof -p 1420 -d txt,mem6Who has a file open?
lsof /var/log/messages7All open files under a folder tree
lsof +D /srv/app8Kill everything that uses a folder
kill $(lsof -t +D /srv/old)9Established connections to a database server
lsof -nP -iTCP@192.168.122.30:5432 -sTCP:ESTABLISHED10Look at a suspicious process (DevSecOps / forensics)
lsof -nP -p 6666 ls -l /proc/6666/exeLook for network connections to unknown hosts and for files in /tmp or /dev/shm.
11UNIX sockets of a service
lsof -U -c sshd
لا يوجد شيء يطابق هذا الفلتر.
انتبه
- Without root you see only your own processes' files.
lsofcan be slow on systems with NFS mounts that do not answer; use-bor-S 5.lsof +Dreads the whole tree — slow on big folders.
نصائح للحفظ
-nPmakes every network listing much faster.- For only ports,
ss -tlpnis faster; use lsof when you also need files.
رموز الخروج
0 | Something was found and listed. |
1 | Nothing was found, or an error. |