You are not logged in.

#1 2011-10-05 02:13:55

rayj
Member
Registered: 2011-09-02
Posts: 10

find -exec bashing issues...

Hello everyone!

I'm loving this Arch install. Things have never worked more solidly since my move to linux a few years ago.

However, I'm stumped with this relatively find -exec script that used to work on default debian/ubuntu:

find . -name "* *" -exec rename 's/\ /_/g' {} \;

It keeps telling me find needs a path declared...and rename doesn't like the arguements. I'm just running it from the location I want to comb for spaces in filenames. Maybe I'm not remembering the syntax properly? Or is 's/\ /_/g' {} \; actually a bit of Perl, and that isn't utilized by bash? Excuse me here, I'm pretty new to the more scripty commands...

Offline

#2 2011-10-05 02:21:58

steve_v
Member
Registered: 2006-02-11
Posts: 80

Re: find -exec bashing issues...

man rename

Offline

#3 2011-10-05 02:24:33

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: find -exec bashing issues...

Not sure if you're referring to the right rename, I've seen quite a bit confusion as there's also a popular perl rename.

Try

nospace () {
  for i in *; do
    OLDNAME="$i"
    NEWNAME=$(echo "$i" | tr ' ' '_' | tr A-Z a-z | sed 's/_-_/-/g')
    mv -v -- "$OLDNAME" "$NEWNAME"
  done;
}

Adjust as needed.

Last edited by karol (2011-10-05 02:28:29)

Offline

#4 2011-10-05 05:01:14

rayj
Member
Registered: 2011-09-02
Posts: 10

Re: find -exec bashing issues...

Thanks for the input! I'm still learning the bash, obviously, and most of what I'm doing is still by rote. I know less about perl, so I'm going to hit the books for a bit.

Offline

Board footer

Powered by FluxBB