I have hundreds of jpg files in different folders like this:
Basically, I need to remove the SPACES. I already know the command to change the spaces into underscores:
$ rename "s/ /_/g" *
But I do not need the underscores in this case. I just need to remove the space. I tried the following, but it didn't work:
$ rename "s/ //g" *
Any help would be appreciated.
s/[[:space:]]//g; – as before, the s command removes all whitespace from the text in the current pattern space.
Use sed 's/^ *//g', to remove the leading white spaces. There is another way to remove whitespaces using `sed` command. The following commands removed the spaces from the variable, $Var by using `sed` command and [[:space:]].
The following would work in case it was really a space.
$ rename "s/ //g" *
Try
$ rename "s/\s+//g" *
\s
is a whitespace character, belonging to the set of [ \t\r\n]
.
You could do something like this:
IFS="\n" for file in *.jpg; do mv "$file" "${file//[[:space:]]}" done
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