查找读取或写入的文件

las*_*las 15 command-line files process

我想查看读取或写入哪些文件。

是否有任何程序或命令?我记得几年前我使用 Windows 时,我使用这种方法来寻找病毒和恶意软件的隐藏位置。

Ste*_*zzo 16

该程序是("List open files")lsof

请记住,某些进程是由超级用户root启动的,您可能需要将其放在sudo命令前面以获取有关此类进程打开文件的更多信息。

要缩小搜索范围,您可以使用grep特定的行,即:

lsof /dev/urandom | grep chrome
Run Code Online (Sandbox Code Playgroud)
  • 输出的FD(File Descriptor) 列为您提供有关程序打开文件的目的的信息(不一定是当前发生了什么):

    • r 表示文件已打开以供阅读

    • w 表示打开文件进行写入

    • u 表示该文件以读写方式打开


有关更多详细信息,请参阅手册页( man lsof)。此外,如果您需要查找任何文件和目录,Linux Filesystem Hierarchy Standard非常有用。


Kee*_*ook 8

作为一个完整的 over-kill 选项,但一个实时工作的选项,您可以使用 inotify:

sudo inotifywait -m -r /
Run Code Online (Sandbox Code Playgroud)

请注意,这会消耗大量内存,并且需要很长时间进行设置。正如联机帮助页所说:

   -r, --recursive
          Watch all subdirectories of any directories passed as arguments.
          Watches  will be set up recursively to an unlimited depth.  Sym?
          bolic links are not  traversed.   Newly  created  subdirectories
          will also be watched.

          Warning:  If  you use this option while watching the root direc?
          tory of a large tree, it may take quite a while until  all  ino?
          tify watches are established, and events will not be received in
          this time.  Also, since one inotify watch  will  be  established
          per subdirectory, it is possible that the maximum amount of ino?
          tify watches per user will be reached.  The default  maximum  is
          8192;  it  can  be  increased  by  writing  to /proc/sys/fs/ino?
          tify/max_user_watches.
Run Code Online (Sandbox Code Playgroud)

这也不会告诉您是哪个进程弄乱了文件,但它可能有助于识别发生的更改。使用“-e open”可能有助于在一个非常繁忙的系统上减少一些噪音。