LoginSignup
1

More than 5 years have passed since last update.

複数ディレクトリにまたがる重複したファイル名を表示する

Last updated at Posted at 2018-10-08

こうなってる

$ tree
.
├── dir_a
│   ├── xxx
│   └── yyy
└── dir_b
    ├── yyy
    └── zzz

重複しているファイル名(yyy)を表示

$ {ls dir_a && ls dir_b} | sort | uniq -d
yyy

コメントでもっとスマートいただきました

GNU findであればprintfのオプションできれいにできる。
gfindはMacOSだと brew install findutils で入る。

$ gfind . -maxdepth 2 -type f -printf '%f\n' | sort | uniq -d
yyy

さらにGNU findじゃなくても動く方法教えてもらいました

すごい、このままだと無限に方法教えてもらえるぞ……!

$ find . -maxdepth 2 -type f -exec basename {} \; | sort | uniq -d

ありがとうございます。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1