我需要隐藏所有被拒绝的消息:
find . > files_and_folders
当这样的信息出现时,我正在做实验。我需要收集所有的文件夹和文件,它没有出现。
是否可以将权限级别直接指向files_and_folders文件?
如何同时隐藏错误?
我需要隐藏所有被拒绝的消息:
find . > files_and_folders
当这样的信息出现时,我正在做实验。我需要收集所有的文件夹和文件,它没有出现。
是否可以将权限级别直接指向files_and_folders文件?
如何同时隐藏错误?
当前回答
use
sudo find / -name file.txt
这很愚蠢(因为你提升了搜索),也不安全,但写起来要短得多。
其他回答
重定向标准错误。例如,如果你在unix机器上使用bash,你可以像这样将标准错误重定向到/dev/null:
find . 2>/dev/null >files_and_folders
为了在整个文件系统中搜索某些文件,例如主机,除了会导致各种错误的/proc树,我使用以下方法:
# find / -path /proc ! -prune -o -name hosts -type f
/etc/hosts
注意:因为-prune始终为真,所以必须对其求反,以避免在输出中看到行/proc。我试过了!-readable方法,并发现它返回/proc下当前用户可以读取的所有内容。所以"OR"条件并不是你所期望的。
我从find手册页给出的示例开始,参见-prune选项。
这些错误被打印到标准错误输出(fd 2)。要过滤它们,只需将所有错误重定向到/dev/null:
find . 2>/dev/null > some_file
或者首先连接stderr和stdout,然后grep出那些特定的错误:
find . 2>&1 | grep -v 'Permission denied' > some_file
-=适用于苹果操作系统=-
使用别名创建一个新命令:只需添加~/。bash_profile线:
alias search='find / -name $file 2>/dev/null'
在新的终端窗口中,你可以调用它:
$ file=<filename or mask>; search
例如: $ file =等;搜索
如果你想从根目录“/”开始搜索,你可能会看到如下输出:
find: /./proc/1731/fdinfo: Permission denied
find: /./proc/2032/task/2032/fd: Permission denied
这是因为许可。要解决这个问题:
可以使用sudo命令: Sudo find /。- name“toBeSearched.file”
它要求超级用户的密码,当输入密码时,你会看到你真正想要的结果。如果您没有使用sudo命令的权限,也就是说您没有超级用户的密码,请先请求系统管理员将您添加到sudoers文件中。
You can use redirect the Standard Error Output from (Generally Display/Screen) to some file and avoid seeing the error messages on the screen! redirect to a special file /dev/null : find /. -name 'toBeSearched.file' 2>/dev/null You can use redirect the Standard Error Output from (Generally Display/Screen) to Standard output (Generally Display/Screen), then pipe with grep command with -v "invert" parameter to not to see the output lines which has 'Permission denied' word pairs: find /. -name 'toBeSearched.file' 2>&1 | grep -v 'Permission denied'