batch renaming folders
I got a directory of folders named "No 35" No 36" "No 128" etc. I just want to take out the "No" part so they're just named the number. I'd alos like to add something before the number line "unit_" so the folder are named "unit_35" unit_36" etc..
|
Have a look at this:
Code:
while read THISDIR; do mv "$THISDIR" "${THISDIR/No /unit_}"; done < <( ls -bd No* ) This: ls -bd No* makes sure that only files that start with No are listed (the -d prevents ls from going any deeper). The -b part escapes special characters (the spaces in your case). Example run: Code:
$ ls -l |
You could simplify things a bit
Code:
for i in No*; do mv "$i" "${i/No /unit_}"; done |
Just in case you have files that start No
Code:
for i in No*/; do mv "$i" "${i/No /unit_}"; done |
@suicidaleggroll: Old habits die hard.... For whatever reason I always overlook globbing directly into the for loop.
@goltoof: Both methods work, but I would use suicidaleggroll's method if I where you (simpler/more elegant). |
I'm not really good with the command line and use the bulk rename application to do this. It's an xfce application and gives you a before (file name as is) and after (file name after hitting apply) option which makes it easy for even the most simple minded to use. If you are on Gnome, it may pull in a lot of dependencies, but it's worth it, in my view.
|
All times are GMT -5. The time now is 01:09 PM. |