can anyone tell me how to rename all the folders in a directory from terminal?
every folder is in format of "id-namestring", is there any way to rename using this pattern to remove everything after "id" in the folder name?
for example if folder name is "123-abcd&efg" it should be renamed to "123"
find top-level-dir -type d -print0 | xargs -0 rename 's/(\d+)-.+/$1/'
This will rename all the directories (
-type d) contained in the directory
xargs is used to cope with the case of very long list of files.
-0 is for the case when your file names contain spaces.
s/(\d+)-.+/$1/ is the actual regexp used for renaming.
you can use Perl expression if you feel comfortable with this.
in this link you can find an overview of rename command with this perl expressions