File and Directory same name


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers File and Directory same name
# 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 12:04 PM.. 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*

This User Gave Thanks to MadeInGermany For This Post:
# 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 01: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 04:03 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find and get a file in an entire directory with an excluded directory specified?

How to get a file 'zlib.h' in an entire directory with an excluded directory specified lives under that starting directory by using find command, as it failed on: $ find . -name 'zlib.h' -a -ipath 'CHROME.TMP' -prune -o -print it'll just list entirely up (2 Replies)
Discussion started by: abdulbadii
2 Replies

2. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory if then mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly ... (9 Replies)
Discussion started by: digioleg54
9 Replies

3. Shell Programming and Scripting

Shell scripting-I need a script which should watch a directory for a file with specific directory

I need a script which should watch a directory for a file with specific directory. If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column. The file should be moved to another directory and the a... (8 Replies)
Discussion started by: akashdeepak
8 Replies

4. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

5. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

6. Shell Programming and Scripting

Script which removes files from the first directory if there is a file in the second directory

Script must removes files from the first directory if there is a file with same name in the second directory Script passed to the two directories, it lies with them in one directory: sh script_name dir1 dir2 This is my version, but it does not work :wall: set - $2/* for i do set -... (6 Replies)
Discussion started by: SLAMUL
6 Replies

7. Shell Programming and Scripting

Move the latest or older File from one directory to another Directory

I Need help for one requirement, I want to move the latest/Older file in the folder to another file. File have the datetimestamp in postfix. Example: Source Directory : \a destination Directory : \a\b File1 : xy_MMDDYYYYHHMM.txt (xy_032120101456.txt) File2: xy_MMDDYYYYHHMM.txt... (1 Reply)
Discussion started by: pp_ayyanar
1 Replies

8. Shell Programming and Scripting

File transfer from one directory to another directory in unix

Hi, I have to transfer five files from one directory to another directory in unix with the help of shell scripts. This shell script calling the param file as input parameter. Every day one file will come and fall on my source directory. Remaining files will fall on any one of the day of the... (5 Replies)
Discussion started by: easterraj
5 Replies

9. Shell Programming and Scripting

Move a file from windows directory to unix directory

Move a file from windows directory to unix directory, is this possible? if it is, can someone help me on this? Thanks! God bless! (1 Reply)
Discussion started by: kingpeejay
1 Replies

10. UNIX for Dummies Questions & Answers

Copying one file at a time from one directory to another directory.

Hi All i want to write a script which could copy one file at a time from one directory to another directory. Scenerio: Let's say i have 100 file in a dirctory,so i want to copy one file at a time to another directory with a sleep statement in between that of 30 secs. please help me... (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies
Login or Register to Ask a Question