0

I have a folder, A, that contains around 100 subfolders, Asub1,Asub2, etc. I am trying to go into each Asub folder, and copy two files back to the A folder. I have the following code:

for D in `find . -type d`
do
    cd $D
    cp log_* ../
    cp *.pdf ../
    cd ../
done

However this result in the following error for each sub folder:

cp: cannot stat `log_*': No such file or directory
cp: cannot stat `*.pdf': No such file or directory

Could someone please tell me where I am going wrong in my code?

4
  • 1
    a simpler way is to cd into A folder (cd A) and then do cp ./*/log_* ./*/*.pdf . Commented Apr 27, 2016 at 12:56
  • That works perfectly, thank you! Commented Apr 27, 2016 at 12:59
  • @IcedCoffee then please select the person's answer as the correct one. it will show that no one else needs to help. Commented Apr 27, 2016 at 13:19
  • A simpler way is to not cd anywhere and just use find Commented Apr 27, 2016 at 13:27

1 Answer 1

3

A simpler way is to cd into A folder (cd A) and then do:

cp */log_* */*.pdf .
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.