Operating System - HP-UX
1837035 Members
3483 Online
110111 Solutions
New Discussion

Need help with a file & directory.

 
SOLVED
Go to solution
Jason Nickelson_1
Occasional Advisor

Need help with a file & directory.

One of our users managed to create a file and a directory of the same name (items.csv) in their home directory. I can do nothing with either one ... I always get the message "No such file or directory". I'd like to delete the directory and save the file if possible. We are running HPUX 11.0 on a K580. Any ideas???
11 REPLIES 11
Helen French
Honored Contributor

Re: Need help with a file & directory.

Hi Jason:

Use:

# cd $HOME
# rm -r -i - you can select the one you need to delete.

HTH,
Shiju
Life is a promise, fulfill it!
Jeff Schussele
Honored Contributor

Re: Need help with a file & directory.

Hi Jason,

If you can list it with wildcards - you should be able to delete it - try

ll *.csv

if that works try

rm *.csv

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Jim Carter
Advisor
Solution

Re: Need help with a file & directory.

Hi there, done the same thing myself and I think if you stay in this business long enough, everyone will eventually...

try determining which entry is in the directory first (file or sub-dir), then:

cd

now delete "all" files recursively in this directory but do it interactively so you can control the actual deletion action:

rm -i -r *

when the offending entry comes up, answer "Y", otherwise answer "N" to retain all other entries. BE CAREFUL you don't delete the wrong entry.
Keely Jackson
Trusted Contributor

Re: Need help with a file & directory.

Hi

I have no idea if this will work or not, but you could try doing an 'ls -i' to get to inode numbers and then use find . -inum -exec rm {} \;

Cheers
Live long and prosper
Jon Mattatall
Esteemed Contributor

Re: Need help with a file & directory.

Hi..

I have no idea how the file and directory coud have the same name, but...

How about "rm -iR items*" (or whatever wildcard would identify just the file/dir name?

When the prompt comes, it will say "Directory dirname (y/n)?" so you can keep the file and waste the dir.

HTH

Jon
A little knowledge is dangerous - none is absolutely terrifying!!!
John Poff
Honored Contributor

Re: Need help with a file & directory.

Hello,

I'd try using the find command with the inode number. You can see the inode numbers by doing a 'ls -li items.c*'. Once you have the inode number for the file (or directory), you can use find to rename it (or delete it, I prefer to rename them first).

Let's say your inode number for the file is 950, you can do this:

find . -inum 950 -exec mv {} items.file.csv \;

which should rename the file to items.file.csv.


I used to work with a slick young programmer who liked to create a junk directory named '*' in his home directory. I had to resort to this method to get it fixed. As for the young programmer, well, threats of physical violence go a long way towards compliance. :)

JP
A. Clay Stephenson
Acclaimed Contributor

Re: Need help with a file & directory.

It appears that some stray non-printable characters have been embed in the pathnames.
Do this:

cd to desired directory
ls ite*
If the files are listed then
rm -r -i ite* and confirm the removes. This is safer than
rm -r -i * because you are far less likely to accidently delete the wrong files. However, if the control characters are the first characters then you will be forced to use the
rm -r -i * form. Answer 'y' to each file that you want to remove and 'n' to everything else. As soon as your desired files have been removed, you can simply hit Ctrl-C or whatever your interrupt is set to to terminate the rm command.
If it ain't broke, I can fix that.
Ruediger Noack
Valued Contributor

Re: Need help with a file & directory.

I don't believe it is possible to get the exactly same name twice in a directory. Are there some invisible signs in the name.
Try ls | od -xc
Please post your output from ls -l

Ruediger
John Poff
Honored Contributor

Re: Need help with a file & directory.

Also, the file and directory probably do have different names, but they might have control characters in the name. Before renaming or deleting them, you might try this:

ls -l items.cs* | od -cx

which should show the names in hex and ascii. You might see some extra control characters in the name. I see this sometimes when people are using telnet and try using the left arrow key instead of the backspace.

JP
Carlos Fernandez Riera
Honored Contributor

Re: Need help with a file & directory.

try

ll -b , maybe spaces, erase characters or other non visible char compound the names.

unsupported
Jason Nickelson_1
Occasional Advisor

Re: Need help with a file & directory.

OK, I got it but I had to delete it several times using the rm -i -r * command. (Thanks James) When I issued the command I said no until I got to the items.csv records. Here are all the things I had to delete from /u01/home/jepker:
directory items.csv
items.csv /u04
items.csv /u04/app
items.csv /u04/app/lawson
items.csv /u04/app/lawson/law
items.csv /u04/app/lawson/law/print
items.csv /u04/app/lawson/law/print/jepker
items.csv /u04/app/lawson/law/print
items.csv /u04/app/lawson/law
items.csv /u04/app/lawson
items.csv /u04/app
items.csv /u04
-------------- at this point the dir was gone
items.csv
"items.csv "

Seems kind of weird, but it worked. I checked each of the /u04 directories before I said yes to make sure there was actually no file/dir named items.csv before I said yes. Once I said yes to the directory items.csv and all the /u04 entries the directory was gone, but not until I said yes to all the /u04 entries. Still couldn't access the file so I deleted the items.csv file and the next entry was items.csv with about 20 blank spaces behind the name ... figured that was the problem so deleted it to. Now the file and directory are gone ... oh well, at least their gone. Thanks for all the help and VERY quick responses!!!