You are not logged in.
I was looking to replace all of the quotes in file names in a directory with underscores. I seem to be having a problem doing so, though. Running the find command:
find . -name '*[\`\'\"]*' -exec sh -c "mv -i '$0' '${0//[\`\'\"]/_}'" {} \;
I get a > inviting me to continue the command. What am I doing wrong?
Last edited by gogi-goji (2010-01-03 02:19:13)
Offline
For just " and `
% for i (**/*) mv $i $(echo $i|sed 's|[`"]|_|')
Works great in zsh. For single quotes, no luck..
edit: Got it! but I have to do it by itself for some reason:
for i (**/*) mv $i $(echo $i|sed s/\'/_/)
Last edited by JohannesSM64 (2010-01-02 09:35:48)
Offline
Bash and perl, file under ugly:...
$ find . -name "*[\`\"']*"| perl -e 'foreach (<stdin>) {s/([`"\x27])/\\\1/g; print; s/\\[`"\x27]/_/g; print}'|xargs -n2 mv
I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.
Offline
I would like to suggest, if you prefer something else than command line, GPRename
find it here http://www.archlinux.org/packages/commu … /gprename/
Offline
prename my friend.
prename 's/"/_/g' */*
Offline
Bash and perl, file under ugly:...
$ find . -name "*[\`\"']*"| perl -e 'foreach (<stdin>) {s/([`"\x27])/\\\1/g; print; s/\\[`"\x27]/_/g; print}'|xargs -n2 mv
God, that's ugly as hell, but worked perfectly. Thank you!
Offline
tlvb wrote:Bash and perl, file under ugly:...
$ find . -name "*[\`\"']*"| perl -e 'foreach (<stdin>) {s/([`"\x27])/\\\1/g; print; s/\\[`"\x27]/_/g; print}'|xargs -n2 mv
God, that's ugly as hell, but worked perfectly. Thank you!
Mine is less ugly and works perfectly.
Offline
No, you don't want perl, or zsh, or all that bloat.
find . -name "*[\`\"']*" | while read i; do mv -i "$i" "${i//[\"\'\`]/_}"; done
I don't understand the -exec part of your code, but I'm 1000% sure it has to do with the (twisted) escaping.
Even if you get that line right, it will be f**king ugly. I've always hated all that eval crap, escaping being one of the reasons.
This silver ladybug at line 28...
Offline
@lolilolicon: yeah the -exec part does give another level of quotes, so you can run into trouble with scripts inside -exec.
I didn't know you could give {} as an argument after sh -c and $0, that solves the problem of not knowing which quotes to use around it in the -exec part.
$ find -mindepth 1 -exec sh -c 'mv -v --backup=t "$0" "$(echo "$0" | sed s/[\\x27\"\`]/___/g)"' {} \;
mv: `./a b' and `./a b' are the same file
`./\'' -> `./___'
`./\'"\'' -> `./_________'
mv: `./$0' and `./$0' are the same file
mv: `./a' and `./a' are the same file
mv: `./$(echo crash)' and `./$(echo crash)' are the same file
`./"' -> `./___' (backup: `./___.~1~')
`./\'\'\'' -> `./_________' (backup: `./_________.~1~')
Or with the other substitution method, it doesn't interpret \x27 (you could use $(echo -e \\x27) or you have to use ...'\\\''...
$ find -mindepth 1 -exec sh -c 'echo mv -v --backup=t "$0" "${0//['\\\''\"\`]/___}"' {} \;
$ find -mindepth 1 -exec sh -c 'echo mv -v --backup=t "$0" "${0//[$(echo -e \\x27)\"\`]/___}"' {} \;
mv -v --backup=t ./a b ./a b
mv -v --backup=t ./' ./___
mv -v --backup=t ./___ ./___
mv -v --backup=t ./'"' ./_________
mv -v --backup=t ./$0 ./$0
mv -v --backup=t ./___.~1~ ./___.~1~
mv -v --backup=t ./a ./a
mv -v --backup=t ./$(echo crash) ./$(echo crash)
mv -v --backup=t ./_________ ./_________
mv -v --backup=t ./" ./___
mv -v --backup=t ./''' ./_________
mv -v --backup=t ./_________.~1~ ./_________.~1~
Offline
Really clear presentation there!
or you have to use ...'\\\''...
Or, for a slightly more accurate expression: '...'\\\''...'
Using \'"'"' or \'\'' in place of '\\\'' will work too. So I think I got it too. At least the usage.
Thanks, Procyon
Last edited by lolilolicon (2010-01-04 11:34:22)
This silver ladybug at line 28...
Offline