我有兩個目錄'dir1'和'dir2',我想輸出這兩個目錄的所有內容。所以,我使用bash命令'xargs'僅通過一個命令行來創建它。命令是「echo'1 2'| xargs -d''-I @ -t sh -c'cat dir @/*'」,但結果很奇怪。關於xargs和通配符的技巧
[[email protected] /data1/walter]$ echo '1 2' | xargs -d ' ' -I @ -t sh -c 'cat [email protected]/*'
sh -c cat dir1/* <<<< This output is normal
1 <<<< This is all content in dir1
sh -c cat dir2
/* <<<< these two lines are odd, it looks like xargs insert a '\n' between 'dir2' and '/*'
cat: dir2: Is a directory <<<< as a result, 'cat' can't receive argument 'dir2'
sh: line 1: /bin: is a directory <<<< and command line '/*' is error
嘗試使用find dir *。你可以訪問find的man頁面來控制/格式化你想要的輸出方式。 – Pratham 2014-09-02 12:48:57