You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行find命令查找文件时出现'./proc/xxxx'不存在错误的原因与解决办法

Why You're Seeing Those find Errors & How to Fix Them

Hey there, let's break down what's happening here and how to fix this annoying issue.

What's Causing the Errors?

Those find: './proc/XXXX': No such file or directory errors are totally expected when your find command traverses directories that include /proc. Here's the breakdown:

  • /proc is a virtual filesystem that dynamically creates directories for every running process (each directory name matches a process ID, or PID).
  • When find starts scanning /proc, it might list a process directory (like ./proc/12049), but by the time it tries to access that directory, the process has already exited. The OS deletes the proc directory for terminated processes immediately, so find can't locate it anymore—hence the error.

Since you're hunting for backup files, you almost certainly don't need anything from /proc anyway—it stores runtime process info, not persistent data you'd want to back up.

Fixes to Try

1. Explicitly Skip the /proc Directory

This is the cleanest solution because it stops find from even trying to traverse /proc in the first place. Modify your command like this:

find . -path ./proc -prune -o -name "$tar_file_name" -type f -print0 | xargs -0
  • -path ./proc -prune tells find to skip the ./proc directory and all its contents.
  • The -o (or) ensures your original search conditions (-name "$tar_file_name" ...) still apply to all other directories.
  • Always wrap $tar_file_name in double quotes to handle filenames with spaces or special characters.

2. Suppress Error Output

If you just want to hide the errors without adjusting the traversal (a quick fix, though not the most elegant), redirect error messages to /dev/null:

find . -name "$tar_file_name" -type f -print0 2>/dev/null | xargs -0

This sends all error logs to the "bit bucket" so you don't see them, though find will still attempt to scan /proc in the background.

3. Restrict to the Current Filesystem

Use the -xdev (or -mount, depending on your find version) option to make find only traverse the current filesystem. Since /proc is a separate virtual filesystem, this will automatically exclude it (along with other virtual filesystems like /sys or /dev):

find . -xdev -name "$tar_file_name" -type f -print0 | xargs -0

This is a great option if you want to avoid all non-persistent virtual filesystems in one go.


内容的提问来源于stack exchange,提问作者Heisenberg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:20:05