I am familiar with rename but I was curious does rename still apply for removing duplicate extensions??
Say I have a few files named:
How would you remove the the duplicate extension??
End result:
Remove File Extension Using the basename Command in Bash If you know the name of the extension, then you can use the basename command to remove the extension from the filename. The first command-Line argument of the basename command is the variable's name, and the extension name is the second argument.
In Unix-like operating systems such as Linux, you can use the mv command to rename a single file or directory. To rename multiple files, you can use the rename utility. To rename files recursively across subdirectories, you can use the find and rename commands together.
The double extension method is used to obtain a price index from a representative sample of the items in stock. The index is calculated by measuring the inventory sample at its current-year and base-year costs and comparing the two figures.
All replies Open File Explorer and click View tab, Options. In Folder Options dialog, move to View tab, untick Hide extensions for known file types option, OK. Then you will se file's extension after its name, remove it.
Assuming:
.jpg.jpg
:Then the following script will work:
#!/bin/bash
for file in *.jpg.jpg
do
mv "${file}" "${file%.jpg}"
done
Explanation:
${file%.jpg}
: This part is called Parameter Subsitution.
To use this script:
clean_de.sh
in that directorychmod +x clean_de.sh
./clean_de.sh
A Note of Warning:
As @gniourf_gniourf have pointed out, use the -n
option if your mv
supports it.
Otherwise - if you have a.jpg
and a.jpg.jpg
in the same directory, it will rename a.jpg.jpg
to a.jpg
and in the process override the already existing a.jpg
without warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With