簡體   English   中英

linux命令:顯示所有文件的內容

[英]linux command: show content of all files

我嘗試了以下兩個cmd以顯示當前目錄下所有文件的內容。 我想知道為什么一個有效,而另一個無效。

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

find . | xargs cat # works

cat只是一個示例,它可以是任何以文件名作為參數的cmd。

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

這是我PC上的一些觀察結果。

$ 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

對於可能會看到此問題的其他人,我們在評論中找到了問題。 郝的問題是ls是一個別名,導致將xargs傳遞給cat的問題。

使用'type ls',他們看到它是別名,並使用'\\ ls'刪除別名解決了該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM