Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

File and Directory same name

UNIX for Beginners Questions & Answers


Tags
solved

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by wtolentino
wtolentino's Unix or Linux Image
wtolentino wtolentino is offline
Registered User
 
Join Date: Oct 2005
Last Activity: 22 December 2017, 9:03 AM EST
Posts: 56
Thanks: 11
Thanked 0 Times in 0 Posts
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.



Code:
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.
Sponsored Links
    #2  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by wtolentino
gull04's Unix or Linux Image
gull04 gull04 is offline Forum Advisor  
Registered User
 
Join Date: Dec 2004
Last Activity: 19 January 2018, 6:23 AM EST
Location: Isle-of-Skye
Posts: 731
Thanks: 19
Thanked 131 Times in 116 Posts
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!



Code:
find . -inum "NNNNNN" -print

Or



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

If this returns what you expect you can then run.



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

Make sure the first find returns the required result.

Regards

Gull04

Last edited by gull04; 4 Weeks Ago at 12:04 PM.. Reason: Additional Information
Sponsored Links
    #3  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by wtolentino
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 19 January 2018, 1:00 PM EST
Location: Simplicity
Posts: 3,941
Thanks: 334
Thanked 1,317 Times in 1,187 Posts
The same name should be impossible.
Perhaps there is a space or other invisible character at the end.
Try rm -i *reports*
    #4  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by wtolentino
gull04's Unix or Linux Image
gull04 gull04 is offline Forum Advisor  
Registered User
 
Join Date: Dec 2004
Last Activity: 19 January 2018, 6:23 AM EST
Location: Isle-of-Skye
Posts: 731
Thanks: 19
Thanked 131 Times in 116 Posts
Hi MadeinGermany,

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



Code:
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
Sponsored Links
    #5  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by wtolentino
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 19 January 2018, 1:00 PM EST
Location: Simplicity
Posts: 3,941
Thanks: 334
Thanked 1,317 Times in 1,187 Posts
Ok, then


Code:
rm -i *r*e*p*o*r*t*s*

The Following User Says Thank You to MadeInGermany For This Useful Post:
gull04 (4 Weeks Ago)
Sponsored Links
    #6  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by wtolentino
rbatte1's Unix or Linux Image
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 19 January 2018, 12:39 PM EST
Location: Lancashire, UK
Posts: 3,441
Thanks: 1,493
Thanked 671 Times in 604 Posts
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

Last edited by rbatte1; 4 Weeks Ago at 01:49 PM.. Reason: Added -xdev
Sponsored Links
    #7  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by wtolentino
wtolentino's Unix or Linux Image
wtolentino wtolentino is offline
Registered User
 
Join Date: Oct 2005
Last Activity: 22 December 2017, 9:03 AM EST
Posts: 56
Thanks: 11
Thanked 0 Times in 0 Posts
i entered these commands:



Code:
$ 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]


Last edited by wtolentino; 4 Weeks Ago at 04:03 PM..
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script cannot create directory and move the file to that directory digioleg54 Shell Programming and Scripting 9 04-12-2017 03:57 AM
Shell scripting-I need a script which should watch a directory for a file with specific directory akashdeepak Shell Programming and Scripting 8 08-26-2014 06:05 PM
Change to directory and search some file in that directory in single command saurau Shell Programming and Scripting 2 01-21-2013 08:53 AM
Grepping file names, comparing them to a directory of files, and moving them into a new directory sHockz Shell Programming and Scripting 1 02-02-2012 02:53 AM
Move the latest or older File from one directory to another Directory pp_ayyanar Shell Programming and Scripting 1 03-24-2010 04:22 PM



All times are GMT -4. The time now is 04:52 PM.