File and Directory same name

i need to remove a file the problem is it will not let me remove a file because it thought that i was instructing it to remove a directory. the issue was that the file and directory has the same name.

drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  sql
drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  scripts
drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  executables
drwxrwxr-x    8 ora102   lpsgrp          256 Apr 22 2009  ..
-rwxr-xr-x    1 wtolenti lpsgrp       217088 Jul 09 2015  reports
drwxrwxr-x    7 ora102   lpsgrp         4096 Jul 09 2015  .
drwxrwxr-x    2 ora102   lpsgrp        12288 Nov 13 14:31 forms
drwxrwxr-x    2 ora102   lpsgrp        12288 Nov 30 09:22 reports
$ rm reports
rm: 0653-603 Cannot remove directory reports.

please advise. thanks.

Hi,

If you run ls -lib in the directory, this will show both the Inode number and if there are any non-printable characters in the filenames.

To remove the file you should run - without the quotation marks!

find . -inum "NNNNNN" -print

Or

find . -inum "NNNNNN" -exec ls -l {} \;

If this returns what you expect you can then run.

find . -inum "NNNNN" -exec rm -i {} \;

Make sure the first find returns the required result.

Regards

Gull04

The same name should be impossible.
Perhaps there is a space or other invisible character at the end.
Try rm -i *reports*

Hi MadeinGermany,

Not so easy - some times the problem is in the middle of the filename; See below;

e415243 on BUILD cathsunvs02 # ls -l
total 15838
drwxr-x---   2 root     root         512 Dec  6 08:07 bin
-rw-r-----   1 root     root     4037689 Aug 22 10:12 cathvs2-cathnhhda-oas_detach.xml
-rw-r-----   1 root     root     4040266 Aug 22 10:13 cathvs2-cathnhhda-ooa_detach.xml
-rw-r-----   1 root     root           0 Dec 20 15:58 data
drwxr-x---   2 root     root         512 Dec  5 16:04 data
-rw-r-----   1 e415243  other        136 Dec  9  2016 local.cshrc
-rw-r-----   1 e415243  other        167 Dec  9  2016 local.login
-rw-r-----   1 e415243  other        184 Dec  9  2016 local.profile
drwxr-x---   2 root     root         512 Dec  5 16:02 logs
drwxr-x---   2 root     root         512 Dec  5 16:02 tmp
e415243 on BUILD cathsunvs02 # ls -lib
total 15838
     35603 drwxr-x---   2 root     root         512 Dec  6 08:07 bin
     34994 -rw-r-----   1 root     root     4037689 Aug 22 10:12 cathvs2-cathnhhda-oas_detach.xml
     34995 -rw-r-----   1 root     root     4040266 Aug 22 10:13 cathvs2-cathnhhda-ooa_detach.xml
     35610 -rw-r-----   1 root     root           0 Dec 20 15:58 da\001ta
     35604 drwxr-x---   2 root     root         512 Dec  5 16:04 data
     35125 -rw-r-----   1 e415243  other        136 Dec  9  2016 local.cshrc
     35127 -rw-r-----   1 e415243  other        167 Dec  9  2016 local.login
     35128 -rw-r-----   1 e415243  other        184 Dec  9  2016 local.profile
     35606 drwxr-x---   2 root     root         512 Dec  5 16:02 logs
     35605 drwxr-x---   2 root     root         512 Dec  5 16:02 tmp
e415243 on BUILD cathsunvs02 #

This duplicate entry was just a simple "ctrl a" in the file name which is invisible normally - which your rm would miss!

Regards

Gull04

Ok, then

rm -i *r*e*p*o*r*t*s*
1 Like

Might I suggest:-

  1. Get the file inode number with ls -li
  2. Remove the file with find . -xdev -inum <<inode number from before>> -exec ls -l {} \; -exec echo rm {} \;

If you are happy with the display, run the find again without the echo in it.

The -xdev stops it heading off into another filesystem and deleting a file there.

Does that help?

Robin

i entered these commands:

$ ls -lib
total 472
204826 drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  executables
204827 drwxrwxr-x    2 ora102   lpsgrp        12288 Nov 13 14:31 forms
204828 drwxrwxr-x    2 ora102   lpsgrp        12288 Nov 30 09:22 reports
151855 -rwxr-xr-x    1 wtolenti lpsgrp       217088 Jul 09 2015  reports\177s
204829 drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  scripts
204830 drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  sql
$ ls -li
total 472
204826 drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  executables
204827 drwxrwxr-x    2 ora102   lpsgrp        12288 Nov 13 14:31 forms
204828 drwxrwxr-x    2 ora102   lpsgrp        12288 Nov 30 09:22 reports
151855 -rwxr-xr-x    1 wtolenti lpsgrp       217088 Jul 09 2015  reports
204829 drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  scripts
204830 drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  sql
$
$ find . -inum "177" -print
$ find . -inum "177s" -print
$ find . -inum "reports\177s" -print
find: 0652-086 Specify a decimal integer for -inum
Usage: find [-H | -L] Path-list [Expression-list]

The inode number is in the 1st column.

find . \! -name . -prune -inum 151855 -exec echo rm {} \;

Hi,

Please execute find command as below.

find . -inum 151855 -print 

Given what you have shown us with the ls -lib , the following command should work:

rm reports*s

reportss should not collide with reports .

Hi Folks,

This would just seem to me that there is a backspace embedded in the file name.

e415243 on BUILD cathsunvs02 # od -c
reportys^?^?s
reports
0000000   r   e   p   o   r   t   y   s 177 177   s  \n   r   e   p   o
^Ce415243 on BUILD cathsunvs02 #

So most of the solutions above will work fine.

Regards

Gull04

$ ls -lib
total 472
204826 drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  executables
204827 drwxrwxr-x    2 ora102   lpsgrp        12288 Nov 13 14:31 forms
204828 drwxrwxr-x    2 ora102   lpsgrp        12288 Dec 21 15:18 reports
151855 -rwxr-xr-x    1 wtolenti lpsgrp       217088 Jul 09 2015  reports\177s
204829 drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  scripts
204830 drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  sql
$ find . -inum 151855 -print
./reports
$

---------- Post updated at 03:39 PM ---------- Previous update was at 03:37 PM ----------

thanks so much everyone it works

$ ls -altr reports*s
-rwxr-xr-x    1 wtolenti lpsgrp       217088 Jul 09 2015  reports
$ rm reports*s
$
$ ls -latr
total 56
drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  sql
drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  scripts
drwxrwxr-x    2 ora102   lpsgrp          256 Apr 03 2009  executables
drwxrwxr-x    8 ora102   lpsgrp          256 Apr 22 2009  ..
drwxrwxr-x    2 ora102   lpsgrp        12288 Nov 13 14:31 forms
drwxrwxr-x    2 ora102   lpsgrp        12288 Dec 21 15:18 reports
drwxrwxr-x    7 ora102   lpsgrp         4096 Dec 21 15:38 .
$