Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ?

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

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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.