How am I able to search for duplicate files that are zipped and unzipped, with the same name?
I understand I can do the initial search with the below however, not sure how to pipe in some duplicate file terms...
find / -iname \*.zip
How am I able to search for duplicate files that are zipped and unzipped, with the same name?
I understand I can do the initial search with the below however, not sure how to pipe in some duplicate file terms...
find / -iname \*.zip
Assuming that you want to find all .zip
files in or below the current directory and check whether there's something with the same name but without the .zip
filename suffix:
find . -type f -iname '*.zip' -exec sh -c '
for a do
n="${a%.zip}"
[ -e "$n" ] && printf "%s\n" "$n"
done' sh {} +
With a directory containing
file
file.zip
file2.zip
file3
file3.zip
the above command would output
./file
./file3
This is done by looking for all .zip
files, and for all found files run a short shell script that strips the extension off each name in turn and checks whether that new name exists or not.
Alternatively, an slightly shorter,
find . -iname '*.zip' -exec sh -c '[ -e "${0%.zip}" ]' {} ';' -print
This also uses a helper shell script, but it's just testing for the existence of the filename without the .zip
suffix. If a suffix-less name exists, the zip file's pathname is outputted.
Also possibly relevant: