What is the unix command to find files that are in one directly buy not another directory? I only care about file names.
Thanks.
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*'
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.
ls dir1 dir3 dir5
. If that’s not what you’re looking for, please clarify your question.