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


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

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


to find files matching 'test*' in dir1 use

find -path '*dir1*' -iname 'test*'
| improve this answer | |

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.