You are not logged in.
I am trying to remove all double spaces from directory names in a particular path.
I have tried this:
find . -type d -exec rename "s/\s\+/ /g" {} \;But it is not doing the trick. Any suggestions?
Last edited by shoelesshunter (2021-03-23 11:03:08)
Offline
this seems to work
find . -type d -name "* *" -exec rename -v " " " " {} +remove the "-v" if you dont want verbose output
Offline
rename will rename the specified files by replacing the first occurrence of expression in their name by replacement.
this will change all double spaces to single spaces
find . -type d -name "* *" | xargs -i sh -c 'v="{}"; printf -v singlespace "$(echo $v | sed "s: : :g")"; mv "$v" "$singlespace"'EDIT
Uses bash global substitution
find . -type d -name "* *" | xargs -i sh -c 'v="{}"; mv "$v" "${v// / }"'Last edited by ponyrider (2021-03-23 02:37:37)
Offline
I am trying to remove all double spaces from directory names in a particular path.
I have tried this:
find . -type d -exec rename "s/\s\+/ /g" {} \;But it is not doing the trick. Any suggestions?
I notice you're trying to pass a regular expression as an argument to /usr/bin/rename, the crippled coreutils binary that only supports string literal replacements. Perhaps you meant to use /usr/bin/perl-rename, the superior program which lets you use perl-compatible regular expressions when renaming things?
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
An alternative if you like (neo)vi(m), vidir from moreutils. ![]()
Tho methinks it should work with any text editor.
Last edited by GaKu999 (2021-03-23 03:17:34)
Offline
thanks vidir did the trick.
Offline