LS两个文件夹并排

时间:2017-05-22 19:41:54

标签: bash paste ls

如何并排粘贴两个文件夹的内容,使输出看起来像

some_command dir1 dir2

dir1_file1 dir2_file1
dir1_file2 dir2_file2
dir1_file3 dir2_file3
dir1_file4 dir2_file4

3 个答案:

答案 0 :(得分:1)

查看gnu diff实用程序并结合进程替换:

$ diff -y <(ls ./tmp) <(ls ./tmp2)
20161201.csv                              <
20161202.csv                              <
aa.txt                              aa.txt
a.txt                               a.txt
bb.txt                              bb.txt
bsd.bsd                             bsd.bsd
b.txt                               b.txt

$ diff -y --suppress-common-lines <(ls ./tmp) <(ls ./tmp2)
20161201.csv                              <
20161202.csv                              <

有关更多选项,请参阅man diff

答案 1 :(得分:1)

您可以使用sdiff并排查看两个目录,如下所示:

$ sdiff <(ls -1 dir1) <(ls -1 dir2)

两个目录之间的任何差异都将以<>反映出来,具体取决于比较的哪一侧缺少特定的文件/子目录。

示例

$ sdiff <(ls -1 dir1) <(ls -1 dir2)
alison_krauss                                                   alison_krauss
Bach - Brandenburg Concertos                                  <
band_of_horses                                                  band_of_horses
Barenaked Ladies                                              <
big_star                                                        big_star
bob_seger                                                       bob_seger

答案 2 :(得分:0)

您可以使用3个命令执行此操作:

ls -1 dir1 > file1
ls -1 dir2 > file2
pr -m -t file1 file2