LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-21-2007, 04:57 AM   #1
Jan Arve
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Rep: Reputation: 0
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.
 
Old 02-21-2007, 05:10 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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?
 
Old 02-21-2007, 05:37 AM   #3
Jan Arve
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 02-21-2007, 08:02 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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".
 
Old 02-22-2007, 03:00 AM   #5
Jan Arve
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Original Poster
Rep: Reputation: 0
>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
 
Old 02-22-2007, 05:04 AM   #6
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.

Last edited by timmeke; 02-22-2007 at 05:10 AM.
 
Old 02-28-2007, 04:33 AM   #7
Jan Arve
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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
 
Old 03-01-2007, 06:56 AM   #8
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.
 
Old 06-14-2007, 05:40 AM   #9
Jan Arve
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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?
 
Old 06-14-2007, 09:59 AM   #10
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
What part of my post isn't clear to you? Or with which part of the command do you need help?
 
Old 06-14-2007, 10:38 AM   #11
Jan Arve
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 02:23 AM
unix command to linux command leonidas Linux - General 1 09-10-2004 12:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration