How to bulk rename files and remove additional characters after extension in linux
If you want to rename the existing files, please try:
#!/bin/bash
for f in *mp4$'\r'; do
mv -- "$f" "${f%$'\r'}"
done
It assumes the *mp4 files are located in the same directory. If you want to fix the filenames in the current directory recursively, please try:
#!/bin/bash
shopt -s globstar
for f in **/*mp4$'\r'; do
mv -- "$f" "${f%$'\r'}"
done
BTW if you want to fix the filenames downloading from now on, modify your awk
command as:
awk '{url=$1; $1="";{sub(/ /,""); sub(/\r$/, "");out=url" -O \""$0"\""}; print out}' file.txt | xargs -L 1 wget
It removes the trailing CR characters out of the names in file.txt
then passes the corrected filenames to wget
.