Mass renaming directories
Hehe, hi it's me again...
So I have a load of directories which I've accidently put .tar on the end of them. Code:
n01443537.tar n01828970.tar n02093859.tar n02115913.tar n02480495.tar n02879718.tar n03272562.tar n03710637.tar n03961711.tar n04310018.tar n04599235.tar I would like to rename all of them to remove the .tar extension. Has anyone got any ideas of how to do this? [there's a LOT of them] |
cd to the top level directory you want (e.g. /, /root, /usr)
Run: Code:
for dir in $(find . -type d -name "*.tar") The above only changes directories and not valid files with .tar extensions due to the initial find command. |
Only thing I'd change in MensaWater's answer is the string replace. Echoing and piping to sed is a bit cumbersome when it can be done natively in bash
Code:
newdir=${olddir/.tar/} |
Quote:
Quote:
|
Brilliant, thank you
|
Quote:
Of course I did Google this first. But it was tricky to remove the .tar extension from the files- that was the bit I didn't understand. There are no examples of removing the end of the directory name, as far as I could understand. And the provided solutions worked wonders. I didn't believe any other details were necessary. |
Quote:
Quote:
|
If you ever fancy a GUI approach, I've found pyRenamer to be a useful wee utility.
To change directory names, remember to use View->Show Options and then select "Directories" in the options. In this case, using Original file name pattern {X}.tar and Renamed file name pattern {1} gets the job done. |
Quote:
Yielded this as its first link :- http://stackoverflow.com/questions/9...ension-in-bash And as far as I can tell, it tells you exactly how to remove the unwanted portion (just like suicidaleggroll's example) |
Quote:
Code:
for dir in $(find . -type d -name "*.tar") |
Quote:
Quote:
There are two kinds of admins in the world. Those who have made mistakes and those who lie about having made mistakes. |
Quote:
Quote:
|
I just want to hear the story about how he ended up with a slue of directories with the ends named "*.tar"
|
All times are GMT -5. The time now is 08:06 PM. |