Reputation: 81
I have the following file structure :
.
├── data
│ └── test_sample.txt
└── demo_test
├── data.php
├── index_test.php
└── Test.php
I want to replace 'test' with 'demo'. The final file structure will be
.
├── data
│ └── demo_sample.txt
└── demo_demo
├── data.php
├── index_demo.php
└── Test.php
How can I achieve this via a shell script.
Thanks in Advance.
Upvotes: 1
Views: 2576
Reputation: 4221
You need to do it in two phases:
cd yourDir
find . -type d -name "*test*" | while read f; do mv $f $(echo $f | sed 's/test/demo/'); done
find . -type f -name "*test*" | while read f; do mv $f $(echo $f | sed 's/test/demo/'); done
Find lists all the files and directories that matches "test" we then process the ouput of the command line by line
Upvotes: 5