Reputation: 1032
I have a folder (name250) which contains several sub-directories. I want my script to find certain files (tE1_sys_250.txt to tE99_sys_250.txt) in all the sub-directories and copy them in another folder (name250_sys).
This is my script but when I run it nothing happens.
#!/bin/bash
cd ~/name250/
mkdir ../name250_sys
for a in {10..99}
do
`find . -name tE$a'_sys'_250.txt -exec cp {} ./name250_sys/ \;`
done
Thanks in advance.
Upvotes: 0
Views: 158
Reputation: 2160
Try if following one line will help:
if you are looking for 1-99
find . -regextype posix-awk -regex '.*tE[0-9]{1,2}_sys_250\.txt' -exec cp {} ./name250_sys/ \;
and if you are looking for 10-99
find . -regextype posix-awk -regex '.*tE[0-9]{2}_sys_250\.txt' -exec cp {} ./name250_sys/ \;
Assuming you are only looking to copy such files
Upvotes: 0
Reputation: 1032
I found the solution. my problem was the last part of the script which I had to add a line " cd .." before find command. Then, it works.
#!/bin/bash
cd ~/name250/
mkdir ../name250_sys
cd ..
for a in {10..99}
do
`find . -name tE$a'_sys'_250.txt -exec cp {} ./name250_sys/ \;`
done
Upvotes: 0
Reputation: 2195
This looks wrong:
cd /name250/
That would attempt to change the directory to a "name250" directory contained in the root folder. I imagine you want:
cd ../name250_sys
Upvotes: 1