Can not remove file using rm command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can not remove file using rm command
# 8  
Old 03-27-2015
Hi

Quote:
Originally Posted by cmccabe
...
Code:
 printf "What is the id of the patient getting GJB2 analysis  : "; read id

that stores a user input in a variable $id in the python directory c:/Users/cmccabe/Desktop/Python27/$id.txt
At no point i see the file $id.txt created.
I only see you read the the user input into the variable id.
Just because there is a variable $id, doesnt mean there is a file $id.txt

Anway, was the "file not found" message regarding $id.txt or rm?

gn8
# 9  
Old 03-27-2015
${id}.txt is not found but I see the file in the directory, rm can't find it. Thank you Smilie.

Last edited by Don Cragun; 03-27-2015 at 09:05 PM.. Reason: Fix ICODE tags.
# 10  
Old 03-27-2015
What, exactly, is the diagnostic message produced by rm?

What is the name of the file you are trying to remove?

What output do you get from the command line?:
Code:
cd c:/Users/cmccabe/Desktop/Python27; ls | od -bc

This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 03-28-2015
The error in rm is:

Code:
 Removing old files, please wait rm: cannot remove 'c:/Users/cmccabe/Desktop/Pyth
on27/.txt': No such file or directory

The file name, in this case is del.txt and it is in the Python directory and I can manually remove it.

Code:
 
cd c:/Users/cmccabe/Desktop/Python27; ls | od -bc
0000000 144 145 154 056 164 170 164 012 104 114 114 163 012 104 157 143
          d   e   l   .   t   x   t  \n   D   L   L   s  \n   D   o   c
0000020 012 151 156 143 154 165 144 145 012 114 151 142 012 154 151 142
         \n   i   n   c   l   u   d   e  \n   L   i   b  \n   l   i   b
0000040 163 012 114 111 103 105 116 123 105 056 164 170 164 012 116 105
          s  \n   L   I   C   E   N   S   E   .   t   x   t  \n   N   E
0000060 127 123 056 164 170 164 012 157 165 164 056 164 170 164 012 160
          W   S   .   t   x   t  \n   o   u   t   .   t   x   t  \n   p
0000100 171 164 150 157 156 056 145 170 145 012 160 171 164 150 157 156
          y   t   h   o   n   .   e   x   e  \n   p   y   t   h   o   n
0000120 167 056 145 170 145 012 122 105 101 104 115 105 056 164 170 164
          w   .   e   x   e  \n   R   E   A   D   M   E   .   t   x   t
0000140 012 162 165 156 137 142 141 164 143 150 137 152 157 142 056 160
         \n   r   u   n   _   b   a   t   c   h   _   j   o   b   .   p
0000160 171 012 123 143 162 151 160 164 163 012 164 143 154 012 124 157
          y  \n   S   c   r   i   p   t   s  \n   t   c   l  \n   T   o
0000200 157 154 163 012 167 071 170 160 157 160 145 156 056 145 170 145
          o   l   s  \n   w   9   x   p   o   p   e   n   .   e   x   e
0000220 012
         \n
0000221

Thank you Smilie.
# 12  
Old 03-28-2015
Obviously, $id is empty in above rm, and, unless $id were one of "del", "LICENSE", "NEWS", "out", or "README", rm wouldn't find it in that directory anyway.
# 13  
Old 03-28-2015
Quote:
Originally Posted by cmccabe
...
Code:
 Removing old files, please wait rm: cannot remove 'c:/Users/cmccabe/Desktop/Pyth
on27/.txt': No such file or directory

...
$id has not been set here as can be seen from the part in red color.
It hasn't been set to "del".

Quote:
Originally Posted by cmccabe
...
The file name, in this case is del.txt and it is in the Python directory and I can manually remove it.

Code:
 
cd c:/Users/cmccabe/Desktop/Python27; ls | od -bc
0000000 144 145 154 056 164 170 164 012 104 114 114 163 012 104 157 143
          d   e   l   .   t   x   t  \n   D   L   L   s  \n   D   o   c
0000020 012 151 156 143 154 165 144 145 012 114 151 142 012 154 151 142
         \n   i   n   c   l   u   d   e  \n   L   i   b  \n   l   i   b
0000040 163 012 114 111 103 105 116 123 105 056 164 170 164 012 116 105
          s  \n   L   I   C   E   N   S   E   .   t   x   t  \n   N   E
0000060 127 123 056 164 170 164 012 157 165 164 056 164 170 164 012 160
          W   S   .   t   x   t  \n   o   u   t   .   t   x   t  \n   p
0000100 171 164 150 157 156 056 145 170 145 012 160 171 164 150 157 156
          y   t   h   o   n   .   e   x   e  \n   p   y   t   h   o   n
0000120 167 056 145 170 145 012 122 105 101 104 115 105 056 164 170 164
          w   .   e   x   e  \n   R   E   A   D   M   E   .   t   x   t
0000140 012 162 165 156 137 142 141 164 143 150 137 152 157 142 056 160
         \n   r   u   n   _   b   a   t   c   h   _   j   o   b   .   p
0000160 171 012 123 143 162 151 160 164 163 012 164 143 154 012 124 157
          y  \n   S   c   r   i   p   t   s  \n   t   c   l  \n   T   o
0000200 157 154 163 012 167 071 170 160 157 160 145 156 056 145 170 145
          o   l   s  \n   w   9   x   p   o   p   e   n   .   e   x   e
0000220 012
         \n
0000221

...
The output that you posted shows that the following files are present in your python directory:

Code:
del.txt
DLLs
Doc
include
Lib
libs
LICENSE.txt
NEWS.txt
out.txt
python.exe
pythonw.exe
README.txt
run_batch_job.py
Scripts
tcl
Tools
w9xpopen.exe

So, yes, "del.txt" is there but because "id" hasn't been set to "del", your shell script cannot remove the file.

You may want to add a "set -x" or "set -ex" at the top of your Bash script right below the shebang line to trace its execution.
This User Gave Thanks to durden_tyler For This Post:
# 14  
Old 03-28-2015
del.txt is the file to be removed but the ${id} has not been set and I don't know why. Thank you Smilie.

Code:
rm c:/Users/cmccabe/Desktop/Python27/"${id}".txt
rm: cannot remove ‘c:/Users/cmccabe/Desktop/Python27/.txt’: No such file or directory

---------- Post updated at 08:24 AM ---------- Previous update was at 08:23 AM ----------

I will add the set -x or set -ex

---------- Post updated at 08:36 AM ---------- Previous update was at 08:24 AM ----------

set -x

Code:
 
+ printf 'Removing old files, please wait '
Removing old files, please wait 
+ rm c:/Users/cmccabe/Desktop/Python27/.txt
rm: cannot remove 'c:/Users/cmccabe/Desktop/Python27/.txt': No such file or dire
ctory
+ cd C:
+ rm c:/Users/cmccabe/Desktop/Python27/out_name.txt

Looks likr rm cant find the file that is the variable but can find the other file. Thank you Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need a command to remove the last word in the first line of a file

I have a eg file op.txt This is a cat This is a fat cat This is a fat black cat I want to remove only the word cat from the first alone .can somebody help. please do wrap your samples in CODE TAGS As per forum rules. (7 Replies)
Discussion started by: Sharks
7 Replies

2. Shell Programming and Scripting

Remove data from grep command using the pattern in the file

Hi, I writing a shell program to remove the data from output of the find which matches a list in a file I am using the below find command to get the list of files x=`find . -name test*.dat` the output of the find command is as follows test1.dat test2.dat test3.dat test4.dat... (4 Replies)
Discussion started by: pals70423
4 Replies

3. UNIX for Dummies Questions & Answers

Using sed command to remove multiple instances of repeating headers in one file?

Hi, I have catenated multiple output files (from a monte carlo run) into one big output file. Each individual file has it's own two line header. So when I catenate, there are multiple two line headers (of the same wording) within the big file. How do I use the sed command to search for the... (1 Reply)
Discussion started by: rebazon
1 Replies

4. Shell Programming and Scripting

sed command to remove the first field from a '|' delimited file

Hi I have a file with fields delimited by |. I need to remove the first field from the file. I tried cut but it just extracts that field. sample.output abc|100|name1 cde|200|name2 efg|300|name3 Output should be sample.output 100|name1 200|name2 300|name3 thanks Var (6 Replies)
Discussion started by: var285
6 Replies

5. Shell Programming and Scripting

Command to remove numbers from beginning of txt file

Hello. I have the following issue: my txt file has the following format: train/dr4/fklc0/sx175.txt 0 80282 Severe myopia contributed to Ron's inferiority complex. train/dr4/fklc0/sx355.txt 0 42906 Dolphins are intelligent marine mammals. train/dr4/fklc0/sa2.txt With the... (1 Reply)
Discussion started by: li_bi
1 Replies

6. UNIX for Dummies Questions & Answers

Command to remove First and Last line from a File

I have a file from which the Header and the Trailer lines need to be removed. They are confirmed to be the first and the last lines in the file. I have tried a few commands, but not successful yet. It needs to be implemented urgently, hence any help is greatly appreciated. Raghu ----------... (1 Reply)
Discussion started by: ragz_82
1 Replies

7. Shell Programming and Scripting

what command is used to remove the all text of the particular file.

Hi all... I want to delete the entire text of the file and want to make it zero byte.. would you please tell me the command for it. Thanks and regards Vijay sahu (4 Replies)
Discussion started by: vijays3
4 Replies

8. Shell Programming and Scripting

Command/Script to remove duplicate lines from the file?

Hello, Can anyone tell Command/Script to remove duplicate lines from the file? (2 Replies)
Discussion started by: Rahulpict
2 Replies

9. Shell Programming and Scripting

rm command not able to remove file

I have directory IXNPG7 under which i have seen file ads.c , ads.gif , ads.js and lots more with extension .html I tried to remove the Entire Directory with rm -Rf IXNPG7 but it is saying -- Directory Not empty can't remove Secondly i tried removing all the files first using rm *.*... (7 Replies)
Discussion started by: jambesh
7 Replies

10. UNIX for Dummies Questions & Answers

command to remove last record on file

Hi, First time on the forum. I have converted some files using the Unix to DOS command but need to strip off the last record that is generated from this conversion that contains just a ^Z. Is there any command that would accomplish this without having to do stream editing? (4 Replies)
Discussion started by: mheinen
4 Replies
Login or Register to Ask a Question