How to bulk delete zip files without extention in linux
Solution 1:
In my Kubuntu the following command:
file -b --mime-type path/to/some/zip
returns:
application/zip
I can use it to detect all zip files in the current directory (with subdirectries). The command is:
find . -type f -exec sh -c '
for f do
file -b --mime-type "$f" | grep -q "^application/zip$" && {
printf "%s\n" "$f"
# rm "$f"
}
done
' find-sh {} +
If the result looks sane, uncomment rm "$f"
(delete #
) to actually remove the files.
Notes:
-
Neither
-b
nor--mime-type
are portable options offile
. If yourfile
does not support them then check what barefile path/to/some/zip
prints. It may be:path/to/some/zip: Zip archive data, …
Where
…
denotes additional information. If I needed to rely on this output then mygrep
command would be:grep -q ": Zip archive data"
but it would (possibly) falsely detect files with this very string in the name. Anyway, adjust your
grep
to what yourfile
prints. -
find-sh
is explained here: What is the second sh insh -c 'some shell code' sh
? -
The command does not care about filenames (in Linux what you call "extension" is just a part of filename). It answers the question you asked in the body of the post ("How can I delete all files that are zip files?"), not the title ("How to bulk delete zip files without extension").