0

have a folder with sub folders. I want to remove [ garbage.com ] from each folder name. I would like to remove the space after the ]

Currently

$ ls 
 
[ garbage.com ] happy  
[ garbage.com ] Sad   
[ garbage.com ] confused  
dog  
cat  
rat  
.....

After script

$ ls  

happy  
Sad  
confused  
dog  
cat  
rat  

I tried the find command but the [] and space are messing me up.

1 Answer 1

1

Try the following:

rename "s/\[\ garbage\.com\ \]\ //" -n *

The -n option will only print the planned changes. Remove the -n to actually rename the directories. Note that this will rename not only directories but also files.

To rename only directories, use the following:

find . -type d -exec rename -n "s/\[\ garbage\.com\ \]\ //" {} ";"
1
  • TY for your help. I keep getting error "rename: not enough arguments" Its late I will mess with it to figure it out. Sep 20, 2022 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.