Mass file renaming
i'm looking for how to rename files in mass quantity. basically i am completely moving from windows (ntfs) to CentOs (ext4). in windows i used to give spaces in between file names, now i want to replace spaces with "-" or "_", so that i get the full file name when i hit tab in terminal.
i've searched google and also looked into "similar threads" of LQ, but could not find answer for my specific requirement. either they are for particular directory or have a pattern/incremental in nature, for example renaming *.jpeg files, file1*.jpg file123.jpg etc. i'm looking for solutions based on "find" command. for example: Code:
# find /dc/cbt/ -type f -iname "*bind*" Code:
# find /dc/cbt/ -type f -iname "*bind*" | sed "s/ /_/ig" | tr "[:upper:]" "[:lower:]" |
How about something like this?
Code:
while read -r name; do You may also look at the manpage of rename command, which is quite a useful tool for mass renaming |
Code:
#!/bin/bash edit: too slow |
Finally...
Thanks millgates & suicidaleggroll. I tried both, and both works great!!! :hattip:
while trying, i realised that certain files have multiple spaces. so i changed a little. i think when both scripts are translated to machine language, they will be same. Code:
#!/bin/bash Code:
#!/bin/bash |
As an alternative to sed you could use bash extglob:
Code:
shopt -s extglob |
Quote:
|
Re shopt = shell options ie amend the way the shell works.
See http://linux.die.net/man/1/bash and search for shell builtin commands, then shopt, then extglob within that. Its about 80% of the way down that page or google for examples etc. |
Thanks.
|
All times are GMT -5. The time now is 04:12 AM. |