LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   cp command in linux (https://www.linuxquestions.org/questions/linux-general-1/cp-command-in-linux-530976/)

Jan Arve 02-21-2007 04:57 AM

cp command in linux
 
he,

I have some trouble when i try to make a shell script that copies
windows files from a samba share.

#cp -r /app/ftp/NO_lo\ 01.07.2007 /app/ftp_new/
cp: cannot stat `/app/ftp/NO_lo\ 01.07.2007 ': No such file or directory

Hope somebody can help me with this one.

timmeke 02-21-2007 05:10 AM

The error you see simply means that your shell can't find the files/directory you indicate.
Try doing:
Code:

ls -ld '/app/ftp/NO_lo\ 01.07.2007'
ls -ld /app/ftp/*
ls -ld /app

Can you also make sure that your Samba share is accessible?

Jan Arve 02-21-2007 05:37 AM

Quote:

Originally Posted by timmeke
The error you see simply means that your shell can't find the files/directory you indicate.
Try doing:
Code:

>ls -ld '/app/ftp/NO_lo\ 01.07.2007'
ls -ld NE_lo\ 01.07.2006
-rwxr-xr-x    1 root  root        210304 Jun 30  2006 NE_lo 01.07.2007

>ls -ld /app/ftp/*

[oracle@hugin ftp]$ ls -ld /app/ftp/*
drwxr-xr-x    1 root  root          4096 Feb 21 11:07 /app/ftp

>Can you also make sure that your Samba share is accessible?

Yes, it is. I have touch a new file under the same catalog.

timmeke 02-21-2007 08:02 AM

Quote:

ls -ld NE_lo\ 01.07.2006
From which directory was the above command issued (use "pwd" command to find out).
Or try using the absolute path, like in my example.

Quote:

[oracle@hugin ftp]$ ls -ld /app/ftp/*
drwxr-xr-x 1 root root 4096 Feb 21 11:07 /app/ftp
That's a bit strange. With the * wildcard, I expect to see the contents of /app/ftp, not /app/ftp itself.

Did you also notice the different spelling? In the cp -r command, the directory name starts with
"NO_lo", whereas in the ls commands you used "NE_lo".

Jan Arve 02-22-2007 03:00 AM

>Did you also notice the different spelling? In the cp -r command, the directory name starts with
>"NO_lo", whereas in the ls commands you used "NE_lo".[/QUOTE]

Sorry, i change the file name.
My problem is that there is space in the file i want to copy, it is an windows file in a samba share.
Is it possible to do an for loop or something to copy the windows file with space in linux?

[ftp]$ ls -ltr *NE*
-rwxr-xr-x 1 root root 210304 Jun 30 2006 NE_lo 01.07.2006

timmeke 02-22-2007 05:04 AM

This was addressed in another thread I recently contributed to:
http://www.linuxquestions.org/questi...d.php?t=530568

So, please take a look at the posts of that thread.
If you still have questions after that, then post back on this thread.

Edit: during the copy, you might want to change the filenames so that they don't include the
space any more.
Code:

#Let's assume that the original name is stored in the variable $fileName (this can be your
#loop variable, for instance)
newName=`basename ${fileName} | tr -s " " "_"`;
cp ${fileName} /new/path/on/Linux/${newName}

Instead of "tr", you may also use "sed" or "awk".
If you don't want the replacing to spaces, you can added other characters as well, or
use tr's character classes.

Jan Arve 02-28-2007 04:33 AM

Quote:

Originally Posted by timmeke
This was addressed in another thread I recently contributed to:
http://www.linuxquestions.org/questi...d.php?t=530568

So, please take a look at the posts of that thread.
If you still have questions after that, then post back on this thread.

Edit: during the copy, you might want to change the filenames so that they don't include the
space any more.
Code:

#Let's assume that the original name is stored in the variable $fileName (this can be your
#loop variable, for instance)
newName=`basename ${fileName} | tr -s " " "_"`;
cp ${fileName} /new/path/on/Linux/${newName}

Instead of "tr", you may also use "sed" or "awk".
If you don't want the replacing to spaces, you can added other characters as well, or
use tr's character classes.


hi,

I still have some problem with this copy script.
When i try to copy the windows file with spaces, it still dont work:

[root@$ ls -ltr *NE*
-rwxr-xr-x 1 root root 32704 Dec 1 20:22 NE 02.12.2006

[root@$ find /app/disk1/~name/ -iname "*NE*" | \ while read I; do cp "$I" /app/disk2/~name2/in.txt; done;
-bash: syntax error near unexpected token `do'

As you can see, i am trying to copy the content of("*NE*") into this file /app/disk2/~name2/in.txt

timmeke 03-01-2007 06:56 AM

I recommend that you simplify your command.

For instance, use find's -exec option to execute your cp command on each item found.
Don't forget to terminate the -exec option with \;

As for the error, I think your command is a little screwed up. After the \ line separator, I expected to see a newline. The shell may not see the 'while' command and hence has a problem interpreting the 'do'. But that's just my first impression.

Jan Arve 06-14-2007 05:40 AM

Quote:

Originally Posted by timmeke
I recommend that you simplify your command.

>For instance, use find's -exec option to execute your cp command on each item found.
>Don't forget to terminate the -exec option with \;

>As for the error, I think your command is a little screwed up. After the \ line separator, I expected to see a >newline. The shell may not see the 'while' command and hence has a problem interpreting the 'do'. But that's just my >first impression.

Hi,

Can you please help me with this command?

timmeke 06-14-2007 09:59 AM

What part of my post isn't clear to you? Or with which part of the command do you need help?

Jan Arve 06-14-2007 10:38 AM

Quote:

Originally Posted by timmeke
What part of my post isn't clear to you? Or with which part of the command do you need help?


Hi,

When i am trying to take the data from *NE* file and put it into source_inn.txt in the commeand under here.

#find /data/out/ftp/~files/ -iname "*NE*" | while read I; do cp "$I" /data/in/source_inn.txt; done;

Nothing happens when i use this command, can you please help me to get this command or something else so i can get the data from *NE* over in the text file source_inn.txt..


Thanks again.


All times are GMT -5. The time now is 06:27 AM.