Operating System - HP-UX
1833083 Members
4191 Online
110050 Solutions
New Discussion

Overwriting Directory file

 
Alexandre W. Agostini_1
Occasional Advisor

Overwriting Directory file


Hi People!

I have the following situation:

drwxr-xr-x 2 bmpadmb bmpb 8192 AFL521 (corrupt)
drwxrwxrwx 6 bmpadmb bmpb 96 NEW_DIR

What happens if I do:

cat NEW_DIR > AFL521

The intention here is to replace the directory file that's corrupted by a new, fresh one, and let a later fsck recover the possible lost file chunks.

Thanks already!
Alexandre.
8 REPLIES 8
Alexandre W. Agostini_1
Occasional Advisor

Re: Overwriting Directory file


Come on guys!

Isn't that dificult, is it?

:)
Robert-Jan Goossens
Honored Contributor

Re: Overwriting Directory file

It give me a headache :-)

Could you be a bit more specific, you can not cat a directory.

Would you like a copy of NEW_DIR replace AFL521 ?

regards,
Robert-Jan
Muthukumar_5
Honored Contributor

Re: Overwriting Directory file

how are you trying cat with directories there ?!

cat NEW_DIR > AFL521 will prompt error first.

Try as,

cat NEW_DIR/* > AFL521/newfile

so that all files in NEW_DIR/ directory will be stored in AFL521/newfile there.

We can use cat command on file(s) only not in directory there.

If you want to send all files ( or copy ) then use as,

cp -R NEW_DIR/* AFL521/.

or

mv -R NEW_DIR/* AFL521/.

It will work there.

drwxr-xr-x 2 bmpadmb bmpb 8192 AFL521 (corrupt) means??

what happened to that directory? can you do as,

ls -l AFL521 getting response?

cd AFL521 ?

HTH.
Easy to suggest when don't know about the problem!
Alexandre W. Agostini_1
Occasional Advisor

Re: Overwriting Directory file

That's the problem.

I can cd to the directory. But when I do a ls -l it complains about a file not existing.

I did a 'strings AFL521' and I've saw a lot of strange file names (file names of windows files). It seems that someone sent a windows directory and its contents, but something went wrong and the directory get corrupt.

I don't if make my self clear.

Jeff_Traigle
Honored Contributor

Re: Overwriting Directory file

Have you tried renaming it? That wouldn't require accessing anything within the directory like ls or cd do so might work...

mv AFL521 AFL521.bad
mv NEW_DIR AFL521
--
Jeff Traigle
Alexandre W. Agostini_1
Occasional Advisor

Re: Overwriting Directory file


Yep, I've mv to other name, and it changed. But continue do to get error. The problem is with the contents of the directory. Aparently it contains a pointer to a file that actualy do not exist.

This way I cannot remove the file, because it don't exist, and cannot remove the whole directory either, because it not empty!

Tricky isn't it? :)

Gregory Fruth
Esteemed Contributor

Re: Overwriting Directory file

You should probably just do the fsck.
The recovered files will go to the
directory lost+found at the top level of
the filesystem. You will then have to figure
out where they go and what their names were,
because the filenames will be lost (I think
they are stored in the containing directory).
Alexandre W. Agostini_1
Occasional Advisor

Re: Overwriting Directory file


Well, I'm almost resigned... :(

There's no other command like fsck that can run on a mounted filesystem?