NARTONIC
NARTONIC

Reputation: 472

Change spaces with underscore in filename

I have a multiples files with space, and I want replace this for a underscore with command line (Mac)

xxx xxx.jpg -> xxx_xxx.jpg

It's possible with only line command?

Upvotes: 7

Views: 5429

Answers (1)

123
123

Reputation: 11216

For all files in current directory

for i in *;do mv "$i" "${i// /_}";done

If you only want to match files with spaces (to prevent tons of error messages when it tries to move files into themselves) though you could use extended glob

shopt -s extglob
for i in +(* *);do mv "$i" "${i// /_}";done

Upvotes: 22

Related Questions