List files opened recursively in a folder #113

Open
opened 2026-11-26 14:33:43 +01:00 by Benjamin_Loison · 7 comments
Owner
Would help tracking progress of [Benjamin_Loison/Improve_websites_thanks_to_open_source/issues/1769](https://codeberg.org/Benjamin_Loison/Improve_websites_thanks_to_open_source/issues/1769).
Author
Owner

For reference: lsof.

For reference: `lsof`.
Author
Owner
inotifywait --recursive --monitor baidu/

does not help if already started opening files.

```bash inotifywait --recursive --monitor baidu/ ``` does not help if already started opening files.
Author
Owner

DuckDuckGo and Google search Linux list open files recursively.

The Super User question 860064:

lsof --help
Output:
lsof: illegal option character: -
lsof: -e not followed by a file system path: "lp"
lsof 4.99.4
 latest revision: https://github.com/lsof-org/lsof
 latest FAQ: https://github.com/lsof-org/lsof/blob/master/00FAQ
 latest (non-formatted) man page: https://github.com/lsof-org/lsof/blob/master/Lsof.8
 usage: [-?abhHKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-E] [+|-e s] [+|-f[gG]]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
 [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.
  -?|-h list help          -a AND selections (OR)     -b avoid kernel blocks
  -c c  cmd c ^c /c/[bix]  +c w  COMMAND width (9)    +d s  dir s files
  -d s  select by FD set   +D D  dir D tree *SLOW?*   +|-e s  exempt s *RISKY*
  -i select IPv[46] files  -K [i] list|(i)gn tasKs    -l list UID numbers
  -n no host names         -N select NFS files        -o list file offset
  -O no overhead *RISKY*   -P no port names           -Q allow failed search
  -R list paRent PID       -s list file size          -t terse listing
  -T disable TCP/TPI info  -U select Unix socket      -v list version info
  -V verbose search        +|-w  Warnings (+)         -X skip TCP&UDP* files
  -Z Z  context [Z]        -H human readable size     -- end option scan
  -E display endpoint info              +E display endpoint info and files
  +f|-f  +filesystem or -file names     +|-f[gG] flaGs 
  -F [f] select fields; -F? for help  
  +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)
                                        +m [m] use|create mount supplement
  +|-M   portMap registration (-)       -o o   o 0t offset digits (8)
  -p s   exclude(^)|select PIDs         -S [t] t second stat timeout (15)
  -T fqs TCP/TPI Fl,Q,St (s) info
  -g [s] exclude(^)|select and print process group IDs
  -i i   select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]
  +|-r [t[m<fmt>]] repeat every t seconds (15);  + until no files, - forever.
       An optional suffix to t is m<fmt>; m must separate t from <fmt> and
      <fmt> is an strftime(3) format for the marker line.
  -s p:s  exclude(^)|select protocol (p = TCP|UDP) states by name(s).
  -u s   exclude(^)|select login|UID set s
  -x [fl] cross over +d|+D File systems or symbolic Links
  names  select named files or files on named file systems
Anyone can list all files; /dev warnings disabled; kernel ID check disabled.
DuckDuckGo and Google search *Linux list open files recursively*. [The Super User question 860064](https://superuser.com/q/860064): ```bash lsof --help ``` <details> <summary>Output:</summary> ``` lsof: illegal option character: - lsof: -e not followed by a file system path: "lp" lsof 4.99.4 latest revision: https://github.com/lsof-org/lsof latest FAQ: https://github.com/lsof-org/lsof/blob/master/00FAQ latest (non-formatted) man page: https://github.com/lsof-org/lsof/blob/master/Lsof.8 usage: [-?abhHKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-E] [+|-e s] [+|-f[gG]] [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s] [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names] Defaults in parentheses; comma-separated set (s) items; dash-separated ranges. -?|-h list help -a AND selections (OR) -b avoid kernel blocks -c c cmd c ^c /c/[bix] +c w COMMAND width (9) +d s dir s files -d s select by FD set +D D dir D tree *SLOW?* +|-e s exempt s *RISKY* -i select IPv[46] files -K [i] list|(i)gn tasKs -l list UID numbers -n no host names -N select NFS files -o list file offset -O no overhead *RISKY* -P no port names -Q allow failed search -R list paRent PID -s list file size -t terse listing -T disable TCP/TPI info -U select Unix socket -v list version info -V verbose search +|-w Warnings (+) -X skip TCP&UDP* files -Z Z context [Z] -H human readable size -- end option scan -E display endpoint info +E display endpoint info and files +f|-f +filesystem or -file names +|-f[gG] flaGs -F [f] select fields; -F? for help +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0) +m [m] use|create mount supplement +|-M portMap registration (-) -o o o 0t offset digits (8) -p s exclude(^)|select PIDs -S [t] t second stat timeout (15) -T fqs TCP/TPI Fl,Q,St (s) info -g [s] exclude(^)|select and print process group IDs -i i select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list] +|-r [t[m<fmt>]] repeat every t seconds (15); + until no files, - forever. An optional suffix to t is m<fmt>; m must separate t from <fmt> and <fmt> is an strftime(3) format for the marker line. -s p:s exclude(^)|select protocol (p = TCP|UDP) states by name(s). -u s exclude(^)|select login|UID set s -x [fl] cross over +d|+D File systems or symbolic Links names select named files or files on named file systems Anyone can list all files; /dev warnings disabled; kernel ID check disabled. ``` </details>
Author
Owner
lsof -h
Output:
lsof 4.99.4
 latest revision: https://github.com/lsof-org/lsof
 latest FAQ: https://github.com/lsof-org/lsof/blob/master/00FAQ
 latest (non-formatted) man page: https://github.com/lsof-org/lsof/blob/master/Lsof.8
 usage: [-?abhHKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-E] [+|-e s] [+|-f[gG]]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
 [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.
  -?|-h list help          -a AND selections (OR)     -b avoid kernel blocks
  -c c  cmd c ^c /c/[bix]  +c w  COMMAND width (9)    +d s  dir s files
  -d s  select by FD set   +D D  dir D tree *SLOW?*   +|-e s  exempt s *RISKY*
  -i select IPv[46] files  -K [i] list|(i)gn tasKs    -l list UID numbers
  -n no host names         -N select NFS files        -o list file offset
  -O no overhead *RISKY*   -P no port names           -Q allow failed search
  -R list paRent PID       -s list file size          -t terse listing
  -T disable TCP/TPI info  -U select Unix socket      -v list version info
  -V verbose search        +|-w  Warnings (+)         -X skip TCP&UDP* files
  -Z Z  context [Z]        -H human readable size     -- end option scan
  -E display endpoint info              +E display endpoint info and files
  +f|-f  +filesystem or -file names     +|-f[gG] flaGs 
  -F [f] select fields; -F? for help  
  +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)
                                        +m [m] use|create mount supplement
  +|-M   portMap registration (-)       -o o   o 0t offset digits (8)
  -p s   exclude(^)|select PIDs         -S [t] t second stat timeout (15)
  -T fqs TCP/TPI Fl,Q,St (s) info
  -g [s] exclude(^)|select and print process group IDs
  -i i   select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]
  +|-r [t[m<fmt>]] repeat every t seconds (15);  + until no files, - forever.
       An optional suffix to t is m<fmt>; m must separate t from <fmt> and
      <fmt> is an strftime(3) format for the marker line.
  -s p:s  exclude(^)|select protocol (p = TCP|UDP) states by name(s).
  -u s   exclude(^)|select login|UID set s
  -x [fl] cross over +d|+D File systems or symbolic Links
  names  select named files or files on named file systems
Anyone can list all files; /dev warnings disabled; kernel ID check disabled.
```bash lsof -h ``` <details> <summary>Output:</summary> ``` lsof 4.99.4 latest revision: https://github.com/lsof-org/lsof latest FAQ: https://github.com/lsof-org/lsof/blob/master/00FAQ latest (non-formatted) man page: https://github.com/lsof-org/lsof/blob/master/Lsof.8 usage: [-?abhHKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-E] [+|-e s] [+|-f[gG]] [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s] [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names] Defaults in parentheses; comma-separated set (s) items; dash-separated ranges. -?|-h list help -a AND selections (OR) -b avoid kernel blocks -c c cmd c ^c /c/[bix] +c w COMMAND width (9) +d s dir s files -d s select by FD set +D D dir D tree *SLOW?* +|-e s exempt s *RISKY* -i select IPv[46] files -K [i] list|(i)gn tasKs -l list UID numbers -n no host names -N select NFS files -o list file offset -O no overhead *RISKY* -P no port names -Q allow failed search -R list paRent PID -s list file size -t terse listing -T disable TCP/TPI info -U select Unix socket -v list version info -V verbose search +|-w Warnings (+) -X skip TCP&UDP* files -Z Z context [Z] -H human readable size -- end option scan -E display endpoint info +E display endpoint info and files +f|-f +filesystem or -file names +|-f[gG] flaGs -F [f] select fields; -F? for help +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0) +m [m] use|create mount supplement +|-M portMap registration (-) -o o o 0t offset digits (8) -p s exclude(^)|select PIDs -S [t] t second stat timeout (15) -T fqs TCP/TPI Fl,Q,St (s) info -g [s] exclude(^)|select and print process group IDs -i i select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list] +|-r [t[m<fmt>]] repeat every t seconds (15); + until no files, - forever. An optional suffix to t is m<fmt>; m must separate t from <fmt> and <fmt> is an strftime(3) format for the marker line. -s p:s exclude(^)|select protocol (p = TCP|UDP) states by name(s). -u s exclude(^)|select login|UID set s -x [fl] cross over +d|+D File systems or symbolic Links names select named files or files on named file systems Anyone can list all files; /dev warnings disabled; kernel ID check disabled. ``` </details>
Author
Owner

DuckDuckGo and Google search lsof dump.

DuckDuckGo and Google search *lsof dump*.
Author
Owner

Mistral: conv_01a21814ba2d706182a2fadeb463b53b

On Debian 13 how to list currently opened files?

GLM 5.3 Think and Search:

On Debian 13 (Trixie), the main tools for listing open files are lsof and the /proc filesystem. Here's a rundown:

1. lsof (LiSt Open Files)

Install it if needed (it's usually not pre-installed on minimal systems):

sudo apt update
sudo apt install lsof

Common usage:

lsof                          # all open files (run as root for the full picture)
sudo lsof                     # everything, including other users' processes
lsof /var/log/syslog          # who has this specific file open?
lsof -u username              # open files of a specific user
lsof -p 1234                  # open files of a specific PID
lsof -c nginx                 # open files of processes named "nginx"
lsof +D /var/www              # open files under a directory
lsof -i                       # internet/network sockets
lsof -i :22                   # who's listening on/using port 22
lsof -i tcp                   # TCP sockets only
lsof -U                       # Unix domain sockets

Note: on Debian 13 you can also use sudo lsof -nP -i (skip DNS/port-name lookups for faster output).

2. /proc filesystem (no extra tools needed)

ls -l /proc/*/fd              # all file descriptors of all processes
ls -l /proc/<PID>/fd          # open files of one process

The /proc/<PID>/fd directory contains symlinks to every open file/socket/pipe for that process.

3. fuser (from psmisc)

Shows which processes use a given file or filesystem:

fuser -v /var/log/syslog      # verbose: which PIDs/users use this file
fuser -vm /mnt/data           # all processes using files under a mount point

4. ss for sockets (replaces the old netstat)

ss -tulpn                     # all listening TCP/UDP sockets with PIDs

Common use cases

  • "Can I unmount this disk? What's holding it?" → lsof +f -- /mnt/disk or fuser -vm /mnt/disk
  • "Why can't I delete this file? Disk space not freed?" → sudo lsof | grep deleted (shows deleted-but-still-open files)
  • "Which process is on port 8080?" → sudo lsof -i :8080 or ss -tlnp | grep 8080

For most day-to-day work, sudo lsof is the one command you need.

Mistral: `conv_01a21814ba2d706182a2fadeb463b53b` > On Debian 13 how to list currently opened files? <details> <summary>GLM 5.3 <i>Think</i> and <i>Search</i>:</summary> On Debian 13 (Trixie), the main tools for listing open files are **`lsof`** and the **`/proc` filesystem**. Here's a rundown: ## 1. `lsof` (LiSt Open Files) Install it if needed (it's usually not pre-installed on minimal systems): ```bash sudo apt update sudo apt install lsof ``` Common usage: ```bash lsof # all open files (run as root for the full picture) sudo lsof # everything, including other users' processes lsof /var/log/syslog # who has this specific file open? lsof -u username # open files of a specific user lsof -p 1234 # open files of a specific PID lsof -c nginx # open files of processes named "nginx" lsof +D /var/www # open files under a directory lsof -i # internet/network sockets lsof -i :22 # who's listening on/using port 22 lsof -i tcp # TCP sockets only lsof -U # Unix domain sockets ``` Note: on Debian 13 you can also use `sudo lsof -nP -i` (skip DNS/port-name lookups for faster output). ## 2. `/proc` filesystem (no extra tools needed) ```bash ls -l /proc/*/fd # all file descriptors of all processes ls -l /proc/<PID>/fd # open files of one process ``` The `/proc/<PID>/fd` directory contains symlinks to every open file/socket/pipe for that process. ## 3. `fuser` (from `psmisc`) Shows which processes use a given file or filesystem: ```bash fuser -v /var/log/syslog # verbose: which PIDs/users use this file fuser -vm /mnt/data # all processes using files under a mount point ``` ## 4. `ss` for sockets (replaces the old `netstat`) ```bash ss -tulpn # all listening TCP/UDP sockets with PIDs ``` ## Common use cases - **"Can I unmount this disk? What's holding it?"** → `lsof +f -- /mnt/disk` or `fuser -vm /mnt/disk` - **"Why can't I delete this file? Disk space not freed?"** → `sudo lsof | grep deleted` (shows deleted-but-still-open files) - **"Which process is on port 8080?"** → `sudo lsof -i :8080` or `ss -tlnp | grep 8080` For most day-to-day work, `sudo lsof` is the one command you need. </details>
Author
Owner
lsof a/
Output:
COMMAND    PID            USER  FD   TYPE DEVICE SIZE/OFF   NODE NAME
bash    289579 benjamin_loison cwd    DIR  253,0     4096 262999 a
vim     289822 benjamin_loison cwd    DIR  253,0     4096 262999 a
lsof +D a/
Output:
COMMAND    PID            USER  FD   TYPE DEVICE SIZE/OFF   NODE NAME
bash    289579 benjamin_loison cwd    DIR  253,0     4096 262999 a
vim     289822 benjamin_loison cwd    DIR  253,0     4096 262999 a
vim     289822 benjamin_loison   4u   REG  253,0    12288 263047 a/.b.swp
```bash lsof a/ ``` <details> <summary>Output:</summary> ``` COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 289579 benjamin_loison cwd DIR 253,0 4096 262999 a vim 289822 benjamin_loison cwd DIR 253,0 4096 262999 a ``` </details> ```bash lsof +D a/ ``` <details> <summary>Output:</summary> ``` COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 289579 benjamin_loison cwd DIR 253,0 4096 262999 a vim 289822 benjamin_loison cwd DIR 253,0 4096 262999 a vim 289822 benjamin_loison 4u REG 253,0 12288 263047 a/.b.swp ``` </details>
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Benjamin_Loison/linux#113