Clueless on how to remove spaces from all .jpg's beneath a folder
OK, I have a folder, that has multiple subfolders (which have subfolders of their own) containing a variety of different files. What I need to do is remove all the spaces from the filenames of .jpg files only in all those folders.
Please tell me there is a way to do this with some fancy command way above my skillset. |
Quote:
Create a myscript.sh Code:
#!/bin/bash Now run Code:
find <my folder> -iname '*.jpg' -exec <full path to myscript.sh> {} + |
Remove or substitute by _ or something else?
You could use find. Code:
find . -type f -name '* *'.[jJ][pP][gG] | while read file; do mv "$file" "${file// /}"; done |
thanks guys. i92, that looks similar to something i've seen someone else do before, so i might go with that. I'd just like to remove the spaces, don't need to substitute an underscore. so do i just use the top line of your last post? can you explain what the part after "do" does, i'm confused.
|
rj098,
if you want to do it in auto fashion you will need a script and run it. certainly this requires workable knowledge of bash scripting. you can get similar script here click this. Or click this it will also give you another idea. there is a good scripting guide click here. hope it helps. good luck. |
Quote:
Code:
find . -type f -name '* *'.[jJ][pP][gG] | while read file; do echo mv "$file" "${file// /}"; done Quote:
The part that is less clear to you is probably this: Code:
"${file// /}" Code:
${variable//substring_to_substitute/new_substring} Code:
${variable/substring_to_substitute/new_substring} http://www.linuxjournal.com/article/8919 There is much more about this in the bash manual page, look for the section called "EXPANSION". |
Quote:
2. replace 'absolute_path_to_the_top_directory' by the absolute path to your top folder 3. save and make the shell script executable, then run the script it will just echo what it's doing. If it looks ok you can run it for real by uncommenting the line # mv "$f" "$nf" and removing this line echo "mv \"$f\" \"$nf\"" I assume you have write permission in those folders Code:
##### copy and paste below this line ##### |
Quote:
A closing bracket missing though Code:
find . -name '* *'.[jJ][pP][gG] | while read file; do echo mv "$file" "${file// /}"; done |
Good catch, catkin ;)
/me goes fixing posts above yet again :p |
Very cool! i like that it gets all occurances and not just the first occurance of a space. Thanks to everybody, this is going to help me out BIG TIME.
|
so where you have the . at the beginning of the line, i should put in my full path to the root folder of where i want the magic to happen, or should i just cd /full/path then run it exactly as you have it written?
|
Either way will work, anyway, until you remove the "echo" it's safe to run it, and you can see what will it do. You could as well use a relative path (in fact, "." itself is a relative path).
ps. When running interactively I preffer to cd to the dir, because that way the paths are shorter and the output is less confusing, but besides that it's a merely cosmetic thing. |
ok, thanks, i'll probably just cd to the folder i want it to start at and run it with the . then
many thanks to everyone! |
CORRECT>find . -name '* *'.[jJ][pP][gG] | while read file; od echo mv "$file" "${file// /}"; done (y|n|e|a)?
it said that when i typed in the command, do i just type y and let it rip? |
Quote:
Code:
echo $0 |
All times are GMT -5. The time now is 02:43 PM. |