0

I started copying a (large) file inside a python script with copyfile from shutil and I had to interrupt the transfer. Now I notice that I cannot delete the file

The file that I am trying to delete is shown below (i.e. it appears to exist)

ngs@bngs05b:/path/to/dir/210305_M05113_0148_000000000-J6HHR/Data> ll
total 1
-rwxrwx--- 1 user lgen 99542099  6. Mai 11:42 LHLA-MS5387-MJ-S-10_S20_L001_R2_001.fastq.gz

If I then try to remove it with rm

ngs@bngs05b:/path/to/dir/210305_M05113_0148_000000000-J6HHR/Data> rm LHLA-MS5387-MJ-S-10_S20_L001_R2_001.fastq.gz
rm: cannot remove 'LHLA-MS5387-MJ-S-10_S20_L001_R2_001.fastq.gz': No such file or directory

which is a very strange behaviour in my opinion.

I tried a few solutions as described here (e.g. ls --escape, ls -1b), but none of them work.

I also tried to see if that file was opened somewhere, though the output of lsof +D does not output anything useful I guess:

ngs@bngs05b:/path/to/dir/210305_M05113_0148_000000000-J6HHR/Data> lsof +D .
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF                NODE NAME
bash    44509  ngs  cwd    DIR   0,37        0 5429445751479423221 .
lsof    45768  ngs  cwd    DIR   0,37        0 5429445751479423221 .
lsof    45769  ngs  cwd    DIR   0,37        0 5429445751479423221 .

I first thought that the problem had something to do that the copied file was corrupt/ incomplete, though I don't think this is the case as I checked that the size of the file in the original location is the same of the file that I am trying to delete.

Does anyone know how can I get rid of this file?

BCArg
  • 427
  • it may cause because of a corrupt process! did you try reboot the system once then removing the file? – Pooya Behravesh May 06 '21 at 11:10
  • the directory is only mounted on a server, so I guess rebooting it is last resort – BCArg May 06 '21 at 11:39
  • does ls LHLA-MS5387-MJ-S-10_S20_L001_R2_001.fastq.gz give an error? and what does ls LH show when you use {tab} to complete the file? any extra characters? – Rinzwind May 06 '21 at 18:30

1 Answers1

0

The filename might have some strange characters which you cannot see in the terminal.

If this is the only file in the data directory I would remove the data directory and take the file with it,

rm -rf data

otherwise try using a gui file manager to remove it or see if you can remove it with a wildcard pattern, use ls with the pattern first so that you ensure you remove the target :)

ls LHRA*.gz

if that lists your file then

rm LHRA*.gz 

If it was in use by another process the message would be different.

SEWTGIYWTKHNTDS
  • 367
  • 1
  • 7
  • it could have been yes that the file has weird characters that the terminal does not show, that's not the case though. Unfortunately I had already tried all of these commands and none of them work (considering the correct directory/ file names - Data and LHLA) – BCArg May 07 '21 at 07:51
  • Sorry for the typos! What message was returned from the rm -rf Data command? – SEWTGIYWTKHNTDS May 07 '21 at 09:33
  • I get rm: cannot remove 'Data/': Directory not empty – BCArg May 07 '21 at 10:24