Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Canot mv or cp file having name beginning with $ 2

Status
Not open for further replies.

RCPD700

MIS
Jun 20, 2001
75
US
My searching has not been able to find an answer to this, so I'm hoping someone here may have a solution.

I was doing some clean-up of unneeded files and found 3 files having names that begin with a dollar sign.

If I use [blue]cat[/blue] or [blue]more[/blue] to try to view the file, cat hangs and more responds "0652-252 Cannot take input from a terminal".

I then attempted to rename the files using [blue]mv[/blue] but it responds "mv: 0653-401 Cannot rename to...".

If I put the file name in quotes like:
[blue]mv "$filename" filename.txt[/blue], mv responds with
"mv: 0653-401 Cannot rename to ./filename.txt:
A file or directory in the path name does not exist."

If I use [blue]cp[/blue] to copy to a new name, I get a couple different responses.

If I do [blue]cp $filename newfilename.txt[/blue] cp insists on showing me its usage note. If I put the source name in quotes, the response is:
"cp: 0653-436 . is a directory.
Specify -r or -R to copy."

The files are in a directory I own and have access rights of 640 (which I am also unable to change). I retried all commands as root with the same results.

I'm still pretty inexperienced in AIX/UNIX so I'm really stuck on this. Any ideas?

In case you're wondering, these files came over during our migration from the mainframe well over a year ago... the mainframe had no problems with such file names.

Thanks in advance for any solutions.

 
escape the $ with single quotes or a backslash

either
[tt]mv '$filename' dollarfilename[/tt]
or
[tt]mv \$filename dollarfilename[/tt]


HTH,

p5wizard
 
You da man" p5wizard! Both suggestions worked perfectly and I was able to successfully rename the files. More importantly, I have learned something.

Thanks you very much!

RCPD700

[small]Running 4 p550's (9133-55A)[/small]

 
Well, that's two of the reasons I participate in these forums: to help and to teach...

HTH,

p5wizard
 
I'm a new AIX admin and our main frame folks are ftping files with single quotes at beginning an end.

Example;
'PLAW.NFT.ARITRANS.XT400.CVT'

After reading your post for the $filename I applied your technique to rename this file to dummyfile:

mv \'PLAW.NFT.ARITRANS.XT400.CVT\' dummyfile

Worked like a Champ! You are da MAN! Thank you.

Newbie AIX admin
 
Two for the price of one, p5!

The internet - allowing those who don't know what they're talking about to have their say.
 
Escaping or quoting is one of the basic methods for handling special characters in unix.

Also note that spaces can be a challenge, and might also impose a risk since a parameter/name can accidentally be mistreated as several individual parameters.

Example: Filename with spaces
-rw-r--r-- 1 user group 0 May 12 19:59 My File With Spaces

Also keep in mind that wild characters (regexp) can sometimes help you.

If you want to remove such files manually, you can use rm -i
... and get prompted for each file
> rm -i My*
rm: Remove My File With Spaces? y
rm: Remove MyFileToKeep?
> ls -l My*
-rw-r--r-- 1 user group 0 May 12 20:06 MyFileToKeep
>

/2r
 
One can also set an array in the shell to remove the file by its index as shown below:

Code:
ls
$testfile testfile1 testfile2

Code:
rm $testfile
Usage: rm [-firRe] [--] File...

Code:
ls
$testfile testfile1 testfile2

Code:
set -A files $(ls .)

Code:
echo ${files[*]}
$testfile testfile1 testfile2

Code:
echo ${files[0]}
$testfile

Code:
rm ${files[0]}

Code:
ls
testfile1 testfile2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top