Home Man
Search
Today's Posts
Register

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

Tags
solved

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 12-20-2017
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.
# 2  
Old 12-20-2017
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; 12-20-2017 at 11:04 AM.. Reason: Additional Information
# 3  
Old 12-20-2017
The same name should be impossible.
Perhaps there is a space or other invisible character at the end.
Try rm -i *reports*
# 4  
Old 12-20-2017
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
# 5  
Old 12-20-2017
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 (12-21-2017)
# 6  
Old 12-20-2017
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; 12-20-2017 at 12:49 PM.. Reason: Added -xdev
# 7  
Old 12-20-2017
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; 12-20-2017 at 03:03 PM..
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find and get a file in an entire directory with an excluded directory specified? abdulbadii UNIX for Beginners Questions & Answers 2 03-22-2018 06:14 AM
Shell script cannot create directory and move the file to that directory digioleg54 Shell Programming and Scripting 9 04-12-2017 02: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 05:05 PM
Change to directory and search some file in that directory in single command saurau Shell Programming and Scripting 2 01-21-2013 07: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 01:53 AM
Script which removes files from the first directory if there is a file in the second directory SLAMUL Shell Programming and Scripting 6 10-26-2011 08:12 PM
Move the latest or older File from one directory to another Directory pp_ayyanar Shell Programming and Scripting 1 03-24-2010 03:22 PM
File transfer from one directory to another directory in unix easterraj Shell Programming and Scripting 5 11-03-2009 01:40 AM
Move a file from windows directory to unix directory kingpeejay Shell Programming and Scripting 1 06-19-2009 01:31 PM
Copying one file at a time from one directory to another directory. Nikhilindurkar UNIX for Dummies Questions & Answers 1 09-01-2008 09:25 AM


All times are GMT -4. The time now is 09:01 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password