将 find 的输出重定向到文件时出现问题

发布于 2024-09-29 14:45:34 字数 271 浏览 1 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如梦亦如幻 2024-10-06 14:45:34

我要做的第一件事是使用单引号(有些 shell 会扩展通配符,但我不认为 bash 会这样做,至少默认情况下是这样),以及 find< 的第一个参数/code> 是一个目录,而不是文件列表:

find ~ -name '*.txt' -print > list_of_txt_files.list

除此之外,它可能需要很长时间,尽管我无法想象有人拥有那么多文本文件(你说你有很多,但它必须非常大才能减慢查找)。首先在没有重定向的情况下尝试一下,看看它输出什么:

find ~ -name '*.txt' -print

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 to find is a directory, not a list of files:

find ~ -name '*.txt' -print > list_of_txt_files.list

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:

find ~ -name '*.txt' -print
最后的乘客 2024-10-06 14:45:34

您可以使用 tee 将输出一起重定向到文件和控制台。

find ~ -name '*.txt' -print | tee result.log

这会将输出重定向到控制台和文件,因此您不必猜测 if 命令是否实际执行。

You can redirect output to a file and console together by using tee.

find ~ -name '*.txt' -print | tee result.log

This will redirect output to console and to a file and hence you don't have to guess whether if command is actually executing.

与君绝 2024-10-06 14:45:34

这对我有用

find . -name '*.zip' -exec echo {} \\; > zips.out

Here is what worked for me

find . -name '*.zip' -exec echo {} \\; > zips.out
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文