I have a script that rename all the files from .txt to .txt2. I want to do the same thing but in all the subdirectories.
This is my code.
rename 's/.txt/.txt2' *.txt
I have a script that rename all the files from .txt to .txt2. I want to do the same thing but in all the subdirectories.
This is my code.
rename 's/.txt/.txt2' *.txt
 
    
     
    
    Like this using Perl's rename:
shopt -s globstar # bash specific, enabled by default in `zsh`
rename 's/\.txt$/\.txt2/' ./**/*.txt
 
    
    I found the answer, but it's hardly readable. 
for filePath in $(find . -name "*.txt"); do filePathWithoutExtension=$(echo ${filePath} | head -c -4) && mv ${filePath} ${filePathWithoutExtension}txt2; done
```
Before :
````bash
tree
.
├── folder1
│   ├── foo.txt
│   ├── subfolder1
│   │   └── foo.txt
│   └── subfolder2
│       └── foo.txt
├── folder2
│   └── foo.txt
└── foo.txt
4 directories, 5 files
After :
tree
.
├── folder1
│   ├── foo.txt2
│   ├── subfolder1
│   │   └── foo.txt2
│   └── subfolder2
│       └── foo.txt2
├── folder2
│   └── foo.txt2
└── foo.txt2
4 directories, 5 files
 
    
    