LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-20-2007, 03:45 AM   #1
cornish
Member
 
Registered: May 2005
Location: Sussex, England
Distribution: Ubuntu 7.10
Posts: 131

Rep: Reputation: 15
Copying files with special characters


I need to copy a file from a mounted windows share to a linux share but unfortunately it contains a special character which is a single quote '

I cant list, file or stat it as bash tells me No Such File or Directory.

When you try to copy the file it then says it cannot open the file.

Is there a magic way around this?

I'm not allowed to rename the file either.
 
Old 12-20-2007, 04:02 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If you work on the linux side, you can try to escape the quote using a backslash
Code:
cp /path/to/my\'file /path/to/file
 
Old 12-20-2007, 04:09 AM   #3
cornish
Member
 
Registered: May 2005
Location: Sussex, England
Distribution: Ubuntu 7.10
Posts: 131

Original Poster
Rep: Reputation: 15
No joy mate the file is m'ap 1.jpg

anything I do expectes another ' to finish the command
 
Old 12-20-2007, 04:29 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If you try to use <TAB> for name completion, which is the resulting string?
Code:
cp m<TAB>
press <TAB> twice if the directory contains other files beginning by m.
 
Old 12-20-2007, 04:45 AM   #5
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
You should also be able to enclose the filename in double quotes:
Code:
cp "m'ap 1.jpg" ~
 
Old 12-20-2007, 07:25 AM   #6
cornish
Member
 
Registered: May 2005
Location: Sussex, England
Distribution: Ubuntu 7.10
Posts: 131

Original Poster
Rep: Reputation: 15
can you create a file on your PC and try it, I just get can not open the file.
 
Old 12-20-2007, 08:28 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I can create and manage the file, either escaping the quote and the blank space or enclosing with double quotes - as suggested by pwc101. Can you paste and copy the commands you're issuing and the exact messages you get? Please, use the CODE tag to wrap the code, so preserving spaces.
 
Old 12-20-2007, 09:12 AM   #8
cornish
Member
 
Registered: May 2005
Location: Sussex, England
Distribution: Ubuntu 7.10
Posts: 131

Original Poster
Rep: Reputation: 15
cp M\'ap* /home/mark/test
cp: cannot open `M\'ap 1.jpg' for reading: No such file or directory
 
Old 12-20-2007, 11:49 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Hmmm... can you copy other files from the same directory? I suspect a problem related to how the windows filesystem is mounted. Anyway, sometimes it can be useful to specify the path, as in
Code:
cp ./M\'ap\ 1.jpg /home/mark/test
to force the correct behavior of the shell. Another test can be
Code:
find . -name "M'ap*" -print0 | xargs -0tp -I '{}' cp '{}' /home/mark/test
if this does not work you have to investigate about permissions and mount options.
 
Old 12-20-2007, 05:57 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
This worked for me:

cp m\'ap\ 1.jpg t.jpg

ie explicitly escape both the ' and the space
 
Old 12-21-2007, 04:26 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Chris, it worked great for me, too. But there must be something weird in the OP's issue, because the error message does not imply it cannot see the file, otherwise the error would be
Code:
cp: cannot stat `somefile': No such file or directory
and not
Code:
cp: cannot open `M\'ap 1.jpg' for reading: No such file or directory
I am puzzled about this.
 
Old 12-21-2007, 09:36 AM   #12
cornish
Member
 
Registered: May 2005
Location: Sussex, England
Distribution: Ubuntu 7.10
Posts: 131

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by chrism01 View Post
This worked for me:

cp m\'ap\ 1.jpg t.jpg

ie explicitly escape both the ' and the space
I tried the above and this is what I get


cp: cannot stat `M\'ap 1.jpg': No such file or directory

I did mention that this was on a windows share??
 
Old 12-21-2007, 09:49 AM   #13
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
What do you get exactly when doing
Code:
ls -l
inside the directory which contains the file? Please, when posting output or error messages go in Advanced Mode and wrap text around the CODE tag (select text and press the # button). This improves readibility and avoids misunderstanding with spaces, tabs and special characters. Thanks.
 
Old 12-21-2007, 11:22 AM   #14
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
what happens when you try
Code:
cp  /path/m*.jpg  /destination
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching for files with special characters Yig Linux - Newbie 4 11-08-2007 05:53 PM
How to rename file while copying - and remove special characters corporal79 Linux - General 3 10-11-2007 04:16 PM
Special Characters SimeonV SUSE / openSUSE 14 07-07-2006 01:29 PM
special characters greenbox Linux - Software 9 12-23-2005 07:33 PM
Special characters consty Programming 3 08-07-2005 05:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:31 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