I have created script to copy .png files from one directory to another. Script is as follows:

i="`cat /usr/local/app1/default.conf | grep -i values | sed -e 's/\values=//g' -e 's/,/ /g'`"
for data in $i
cp -rvp /usr/local/dir1/$data.png /home/user1/dir1

When I run the above script, this copies files from dir1 to /home/user/dir1 but at the end giving me error such as:

cp: cannot stat ‘/usr/local/dir1/wasw\r.png’: No such file or directory

contents in default.conf:

 values= wads sead seda okaw wasw

The command cp searches for these values 'wads', 'sead' etc but at the end I am getting the above error..

  • 5
    Is it possible the file was edited on Windows (or an old mac)? It looks like there are \r which probably points that there are wrong line-endings in the file.
    – Gert
    Commented Jun 9, 2015 at 11:23
  • 2
    Please try this : cp - rvf /path_from_where_youwanttocopyfiles/*.png /home/user1/dir1/ Or use find command and grep png files and copy them to to desired directory. Commented Jun 9, 2015 at 11:30

3 Answers 3


If you want to keep the same code as you currently have, I suggest using sed a little more to its capacity :

i="`sed -n 's/'$'\r''//;s/,/ /g;s/values=//gp' /usr/local/app1/default.conf`"
for data in $i; do
    cp -rvp /usr/local/dir1/$data.png /home/user1/dir1

How it works :

  • The -n flag to sed tells it to not print the lines automatically
  • The s/$'\r'// statement removes the \r characters that is probably causing your problems
  • The added p at the end of the s/values=//gp statement prints the buffer only if a replacement was made (only if values= was present on the line)
  • @Shri I'm glad it did. To help others find the answer when confronted to a similar problem, it would be nice to accept the answer by selecting the little check mark on the left of the answer.
    – user43791
    Commented Jun 11, 2015 at 18:28

Actually I didn't get your use case, but all I understood is you want to find .png files from a directory and want to copy those files to another directory.If my understanding about your use case is correct then the below command helps,

find /home/your/source/path/ -name \*.png -exec cp {} /home/your/destination/path/ \;


You probably edited that default.conf file on windows machine and copied it over. There seems to be an extra character at the end of that line before the newline. Try od -c default.conf. It probably gives you something like:

0000000   v   a   l   u   e   s   =       w   a   d   s       s   e   a
0000020   d       s   e   d   a       o   k   a   w       w   a   s   w
0000040 022  \n

Edit the file to remove the 022 character (which is \r) and try again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .