将 find 的输出重定向到文件时出现问题
我正在尝试将 find 命令的结果放入 unix bash shell 上的文本文件中
使用:
find ~/* -name "*.txt" -print > list_of_txt_files.list
但是 list_of_txt_files.list 保持为空,我必须终止 find 命令才能返回命令提示符。我的主目录中有许多 txt 文件
或者,如何从命令行将 find 命令的结果保存到文本文件。我认为这应该有效
I am trying to put the result of a find command to a text file on a unix bash shell
Using:
find ~/* -name "*.txt" -print > list_of_txt_files.list
However the list_of_txt_files.list stays empty and I have to kill the find to have it return the command prompt. I do have many txt files in my home directory
Alternatively How do I save the result of a find command to a text file from the commandline. I thought that this should work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我要做的第一件事是使用单引号(有些 shell 会扩展通配符,但我不认为
bash
会这样做,至少默认情况下是这样),以及find< 的第一个参数/code> 是一个目录,而不是文件列表:
除此之外,它可能需要很长时间,尽管我无法想象有人拥有那么多文本文件(你说你有很多,但它必须非常大才能减慢
查找
)。首先在没有重定向的情况下尝试一下,看看它输出什么:The first thing I would do is use single quotes (some shells will expand the wildcards, though I don't think
bash
does, at least by default), and the first argument tofind
is a directory, not a list of files:Beyond that, it may just be taking a long time, though I can't imagine anyone having that many text files (you say you have a lot but it would have to be pretty massive to slow down
find
). Try it first without the redirection and see what it outputs:您可以使用 tee 将输出一起重定向到文件和控制台。
这会将输出重定向到控制台和文件,因此您不必猜测 if 命令是否实际执行。
You can redirect output to a file and console together by using tee.
This will redirect output to console and to a file and hence you don't have to guess whether if command is actually executing.
这对我有用
Here is what worked for me