如何在 Linux 命令行上只读取可读文件?不显示不可读文件的权限错误
所以我在学习 Linux 课程时很难解决这个问题。我需要提出一个用户可以执行的命令来显示文件夹中所有可读文件的字数,而不显示任何错误消息。我确信这很简单,但我可以在任何地方找到它。
So I am in a Linux course and having trouble figuring out this question. I need to come up with a command that a user can execute to display word counts for all readable files in a folder, without displaying any error messages. I'm sure this is simple but I can find it anywhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
find /home/jon/ -maxdepth 1 -read -type f -exec wc -w {} \;
您可以将
find
与-type f
一起使用code> 仅适用于文件,-maxdepth 1
以便find
不会在子目录中搜索,-read
因此它只搜索可读文件和wc -w
到计算文件中的单词数:要显示
wc -w
是正确的:来自 人发现:
find /home/jon/ -maxdepth 1 -readable -type f -exec wc -w {} \;
You can use
find
with-type f
for files only,-maxdepth 1
so thatfind
doesn't search in sub-directories,-readable
so it only searches readable files andwc -w
to count the words in the files:To show that the
wc -w
is correct:From man find: