I'm looking for a simple bash script that I can execute that will strip the first 5 chars of each folder name in a given folder.
Any ideas?
I'm looking for a simple bash script that I can execute that will strip the first 5 chars of each folder name in a given folder.
Any ideas?
something like
maybe? remove the -n option when you've got the match working rightCode:find . -type d -exec rename -nv 's/.{5}//' {} \;
You can add a -maxdepth to the find if you don't want it to descend recursively, or just
to just rename directories directly below the current dirCode:rename -nv 's/.{5}//' */
Last edited by steeldriver; September 5th, 2012 at 02:23 PM.
That munges the beginning of the paths!
Here's a variant:
Edit: thanks steeldriver, it's now corrected.Code:find /some/path/ -type d -exec rename -nv 's/\/[^\/]{5}([^\/]*)$/\/$1/' {} \;
Last edited by Lars Noodén; September 5th, 2012 at 03:22 PM. Reason: catching the tail end of the directory name explicitly
oops you're right - thanks for the correction Lars!
EDIT: I think the regex might need something to explicitly catch the trailing part though?
Code:'s/\/[^\/]{5}([^\/]*)$/\/$1/'
Last edited by steeldriver; September 5th, 2012 at 03:15 PM.
Thanks, I will try this later
Bookmarks