You could use this command:
comm -12 <(find dir1 -type f -exec bash -c 'basename "${0%.*}"' {} \; | sort) <(find dir2 -type f -exec bash -c 'basename "${0%.*}"' {} \; | sort)
This uses find
to list all the files in each directory, then basename
and parameter substitution to strip off the directory names and file extensions. comm
compares the two lists.
Example:
$ tree
.
|-- dir1
| |-- test1.txt
| |-- test2.txt
| `-- test3.txt
`-- dir2
|-- test2.txt
`-- test4.txt
$ comm -12 <(find dir1 -type f -exec bash -c 'basename "${0%.*}"' {} \; | sort) <(find dir2 -type f -exec bash -c 'basename "${0%.*}"' {} \; | sort)
test2
$ comm -23 <(find dir1 -type f -exec bash -c 'basename "${0%.*}"' {} \; | sort) <(find dir2 -type f -exec bash -c 'basename "${0%.*}"' {} \; | sort)
test1
test3
$ comm -13 <(find dir1 -type f -exec bash -c 'basename "${0%.*}"' {} \; | sort) <(find dir2 -type f -exec bash -c 'basename "${0%.*}"' {} \; | sort)
test4
comm -12
will show all the filenames common to both directories. comm -23
will show all the filenames unique to dir1, comm -13
will show the filenames unique to dir2.