LinuxQuestions.org
Help answer threads with 0 replies.
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 05-07-2008, 04:47 PM   #1
homer_3
Member
 
Registered: May 2008
Posts: 85

Rep: Reputation: 15
What does "cp: cannot stat" mean?


This error doesn't make sense to me. I'm trying to copy a file from one place to the other. It's a jar file with a name like [asdfasdf].jar. I don't know why it had [] around it, but it does. Whenever I try to copy it anywhere I get the error:

cp: cannot stat `[filename].jar': No such file or directory

Does anyone know how I can copy the file?
 
Old 05-07-2008, 04:54 PM   #2
puntjuh
Member
 
Registered: Apr 2006
Location: holland
Distribution: Gentoo / debian / suse / mint
Posts: 558

Rep: Reputation: 41
in the command line .. the following name.. with [ ] around it, are .. too keep it simple.. interpreted as spaces.. So you have to put a \ there.


like this: cp file\ name.jar

or in your case: cp \[filename\].jar

or cp [\filename]\.jar i'm not 100% sure at the moment. But anyway the \ is the way too go!
 
Old 05-08-2008, 11:29 AM   #3
homer_3
Member
 
Registered: May 2008
Posts: 85

Original Poster
Rep: Reputation: 15
Since I used tab to finish typing the file name it puts the \s in for me. So I am doing cp \[filename\].jar /destination.
 
Old 05-08-2008, 11:40 AM   #4
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
The '[' and ']' are one examples of special characters that your shell (probably bash) tries to interpret unless you tell it not to. '{' and '}' are another example: to clarify this, the following two lines would be equivalent
Code:
ls file{1,2}.abc
ls file1.abc file2.abc
There are a lot of things like this - special ways to tell your shell's interpreter to do something "handy". The cost is that some characters are then interpreted in a special manner, and if they exist in a filename (they can exist there, it's just fine because it wouldn't be fair to disallow such filenames just because one shell couldn't deal with them) you need to tell the interpreter that it's part of a filename, not a "special command".

To tell bash, for example, that a string you type is a filename with possibly special characters inside and not a sequence of characters with some "command characters" to be interpreted, you can use (at least) two ways. One was described above: escape each "special" character with a leading slash:
Code:
cp \[file\].abc anotherfile.abc
cp file\ name\ with\ spaces\ in\ it.abc some\ other\ name.abc
The other way is to put (double-)quotation marks around the filename, which has the same effect:
Code:
cp "[file].abc" anotherfile.abc
cp "file name with spaces in it.abc" "some other name.abc"
At least in most cases the latter works, and is often a lot shorter to use. Especially with filenames with spaces it's more handy to type two quotation marks than a dozen slashes.

More:
Code:
man bash
and a few good websites. See linuxcommand.org for a start.

Last edited by b0uncer; 05-08-2008 at 11:42 AM.
 
1 members found this post helpful.
Old 10-06-2009, 01:57 PM   #5
nar_adi
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Rep: Reputation: 0
"cp: cannot stat"

Dear experts..

I hope you don't mind answering my question (so common in many forums) once again. "cp" command does not seem to work when used in a bash shell script. I agree it is something to do with the special characters. I just don't seem to get it! I saw a post on a similar one (w/ a jar file, which appears to be slightly different)

Following are the lines used in a bash script in Linux RHEL5.
#!/bin/bash
f1=/home/user/dir1/f1
cd=/home/user/dir1/sdir2/data/
cp $f1 $cd
cp: cannot stat `/home/user/dir1/f1\r': No such file or directory

Your response is very highly appreciated.

Thanks,
Naradi

Last edited by nar_adi; 10-06-2009 at 02:10 PM.
 
Old 10-06-2009, 03:14 PM   #6
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,650

Rep: Reputation: 525Reputation: 525Reputation: 525Reputation: 525Reputation: 525Reputation: 525
Sounds like your bash script is using Windows newlines instead of Unix. Convert them to Unix. If using vi, the command is ":set ff=unix"
 
Old 10-06-2009, 03:18 PM   #7
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,033

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
My guess is that you are running a script that was written with a windows editor (eg notepad) so it has incorrect End Of Line (EOL) characters for linux.

Retype the script with a linux editor, and you'll be OK.
Or search on the dos2unix and unix2dos utilities which will make the conversions for you.

In future, please don't post to threads that are more than a year old (like this one) - start a new one.

Welcome to LQ!
 
Old 10-06-2009, 04:49 PM   #8
nar_adi
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Rep: Reputation: 0
What does "cp: cannot stat" mean?

Thanks for your quick response... Now it makes sense..

Actually those escape characters come from extracted values stored in those variables (e.g. $f1); the extracted values were obtained from another file (an ASCII text) probably created using Windows based editor.

Is there a way to get rid of those escape characters...? I am not sure of the syntax.. I guess it would be something like ${f1//\x/} (for global replacement)

Thanks!
Naradi
 
Old 10-06-2009, 04:59 PM   #9
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,033

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Quote:
Is there a way to get rid of those escape characters...?
I already gave you the name of the tool at post #7: dos2unix
 
Old 10-06-2009, 06:05 PM   #10
nar_adi
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Rep: Reputation: 0
I thought dos2unix takes care of files. How do I remove similar escape characters in variables? $var{//x/y} construct...

Thnks.
 
Old 10-06-2009, 06:35 PM   #11
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,033

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Quote:
I thought dos2unix takes care of files. How do I remove similar escape characters in variables? ..... the extracted values were obtained from another file (an ASCII text) probably created using Windows based editor.
Maybe run that file through dos2linux before you extract the variables.
 
Old 10-07-2009, 03:50 AM   #12
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,557
Blog Entries: 28

Rep: Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178
Quote:
Originally Posted by nar_adi View Post
I thought dos2unix takes care of files. How do I remove similar escape characters in variables? $var{//x/y} construct...

Thnks.
Code:
"${var/$'\n'/}"
 
Old 10-18-2012, 11:43 AM   #13
sunriseresources
LQ Newbie
 
Registered: Oct 2012
Posts: 1

Rep: Reputation: Disabled
Special Character in Filename

When working on a client site there were several files that contained special characters. This caused the error message of "cp: cannot stat".

An easy solution was to use wildcards for a portion of the filename that was OK, for example:

filenamewithspecialcharacters.pdf

cp ./*filenamewith* ./newfilename.pdf

After I verified that this found and copied the correct file, then I removed the old file:

rm ./*filenamewith*
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Alsa-utils failing make stage: "cannot stat `t-ja.gmo'", I think I need xgettext timkarwoski Linux - General 2 10-06-2008 03:07 PM
"failed to stat" what does it actually mean? lauram93 Linux - Newbie 1 02-19-2008 02:13 PM
Can't run LILO error : Fatal:raid_setup:stat("/dev/hdi1") robban59 Linux - Newbie 4 05-31-2005 05:44 PM
Can't "stat source package list" irvken Debian 3 01-31-2005 02:52 PM
"mv: Can't stat source" l2g Linux - Newbie 0 02-16-2004 10:28 AM


All times are GMT -5. The time now is 04:47 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration