diff two directories, but ignore the extensions
diff <(ls -1 ./dir1 | sed s/.wav//g) <( ls -1 ./dir2 | sed s/.mp3//g)
list directory and place each file on a separate line
ls -1
remove the file extension
sed s/.wav//g
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.
With zsh
:
diff -u <(cd dir1 && printf '%s\n' **/*(D:r)) \
<(cd dir2 && printf '%s\n' **/*(D:r))
(D)
to include dot-files (hidden files), :r
to get the root name (remove extension).
Using globbing guarantees a consistent sort order.
(that assumes file names don't have newline characters).