Linux命令: show content of all files

标签 linux find ls xargs

我尝试了以下两个cmd来显示当前目录下所有文件的内容。我想知道为什么一个有效,另一个无效。

ls | xargs cat # does not work, No such file or directory

find . | xargs cat # works

cat 只是一个示例,它可以是任何以文件名作为参数的 cmd。

---------------------------------更新---------------------------------

以下是我的电脑上的一些观察结果。

$ echo 1 > test1.txt
$ echo 2 > test2.txt
$ echo 3 > test3.txt

$ ls
test1.txt  test2.txt  test3.txt

$ ls *.txt | xargs cat
cat: test1.txt: No such file or directory
cat: test2.txt: No such file or directory
cat: test3.txt: No such file or directory

$ find .  -name '*.txt' | xargs cat
2
1
3

最佳答案

对于其他可能看到此内容的人,我们在评论中发现了该问题。 hao 的问题是 ls 是一个别名,导致将 xargs 管道传输到 cat 时出现问题。

使用“type ls”,他们发现它是别名,使用“\ls”删除别名解决了问题。

关于Linux命令: show content of all files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31997536/

相关文章:

c - 如何使用指针从数组中删除字段?

linux - Debian 未找到 Wall 命令

Linux 中的 Java Tesseract 错误导致 JVM 中出现 SIGSEGV

search - 在 IntelliJ 全局搜索中从搜索结果中排除评论?

bash - 删除除最后一场比赛以外的所有比赛

mongodb - 从Grails更新MongoDB文档

设置提示和 ls --color 后 linux vi 搞砸了

linux - 如何使用带有多个分隔符的 IFS?

C sys/stat.h 并非 stat 结构的每个字段都被初始化

linux - 使用 ls 进行管道传输时,grep 命令在 solaris 中不起作用