-2

I am writing an sh file I have this command

cp test/*.txt NewDirectory/

from my understanding it will go one by one in the test folder

1.txt
2.txt
5.txt
6.txt

but won't copy

3.txt
4.txt

because they are not there

I need it to print out or in a log file the files it couldn't find or couldn't copy to the new folder. How do I do that ?

  • It's quite unclear what you are asking for, so update your question and comment on already proposed answers. – Svetlin Tonchev Mar 8 '16 at 7:04
1

Your understanding is incorrect. If there are only 1,2,5,6 there will be no error message in case those files are copied successfully. IF your need is to parse N number or txt files in folder and see which does not exist you can do something like: for x in {1..10}; do cp $x.txt NewDirectory/;done .Further you can append > output.log to redirect the command output to file.

0

with cp test/*.txt NewDirectory/ 2>./output.log

but the cp with * command will have to copy the files that exist and so do not show display error if files do not exist

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.