0

What is the unix command to find files that are in one directly buy not another directory? I only care about file names.

Thanks.

1
  • Well, I can say ls dir1 dir3 dir5. If that’s not what you’re looking for, please clarify your question. Feb 26, 2013 at 22:39

2 Answers 2

1

I'm assuming you want to do this search from a higher level directory. If so, you can use the -path option with find.

For example, given the directory structure below

+---dir1/test1.txt
  |
  |--dir2/test1.txt

to find files matching 'test*' in dir1 use

find -path '*dir1*' -iname 'test*'
0

To compare two directories, you can use this:

diff <(cd "$dir1"; find | sort) <(cd "$dir2"; find | sort)

To do this only one way, and produce a list of files, try this:

diff <(cd "$dir1"; find | sort) <(cd "$dir2"; find | sort) \
| grep '< ./' | sed "s,< ./,$dir1/,"

For this to work properly, neither $dir1 nor $dir2 should include the trailing slash.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .