1823081 Members
3356 Online
109645 Solutions
New Discussion юеВ

deleting a file

 
SOLVED
Go to solution
Shivkumar
Super Advisor

deleting a file

Hi,

There is a file named -p got created in my home directory and filling out the space.

I found inode of the -p file by using ll -li command and used rm -i inode number but file didn't get deleted.

Can someone let me know how this file might have got created and how to delete it ?

Thanks,
Shiv
11 REPLIES 11
Chan 007
Honored Contributor

Re: deleting a file

Shiv,

Try rm ?p pr rm *p, generally rm will ask you permission.

better use mv ?p to /tmp and do your rm

Care : do not try rm -f. This will not ask your permission.

This could have got created by mistake like if you see the keyboard "-" and "p" are just upon one another.

Chan

AwadheshPandey
Honored Contributor

Re: deleting a file

try rm -i ?p or rm -i *p

Awadhesh
It's kind of fun to do the impossible
AwadheshPandey
Honored Contributor

Re: deleting a file

try rm -i ?p* or rm -i *p*

Awadhesh
It's kind of fun to do the impossible
Steven E. Protter
Exalted Contributor
Solution

Re: deleting a file

Shalom Shiv,

I had the same thing happen to me last week.

I finally ended up moving all the good files out of the directory and wiping out the parent folder.

I tried quotes. I tried -f, nothing helped.

Surely my solution was only because I was too busy to find a real solution.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Shivkumar
Super Advisor

Re: deleting a file

Hey Guys, It didn't help. It didn't remove the file. Anymore idea ??
James R. Ferguson
Acclaimed Contributor

Re: deleting a file

Hi Shiv:

If you are not root when you attempt to remove the file, do you own the file? If not, remove it as the root user.

Does an 'ls -l' show the object to be a *file* or is it a *directory*. If its a directory, you need to remove it with 'rmdir' or use 'rm -r' to remove the directory's contents and then the directory.

Are you sure that you have the correct inode number when you issue the 'rm'? Using 'find /path -xdev -inum -exec rm {} \;' should remove the file in '/path' with an inode equal to the value of given that my opening questions are satisfied.

Regards!

...JRF...
Shivkumar
Super Advisor

Re: deleting a file

Hi James,

I used the command as below and got the below error message:-
# find /home/sksonkar/ -xdev -inum 750 -exec rm {} \;

vxfs: mesg 001: vx_nospace - /dev/vg00/lvol4 file system ful (1 blok extent)
#

After few minutes i checked the file having
-p name and it got vanished.

Anyway, seems it worked.

It was a big file and was growing by itself though. I was hoping that after deleting this file will free some disk space but it didn't free up the space.

Thanks a lot.
Shiv
James R. Ferguson
Acclaimed Contributor

Re: deleting a file

Hi Shiv:

If you still have a process that is/was writing to the file, then the file will not be truly removed until the last process using the file terminates.

It is a common practice in Unix programming to open a temporary file and immediately 'unlink' it. (the 'unlink'(2) system call is what 'rm' actually uses). WHen this is done, the visible directory entry ceases to exist, but the file is available to the process that created it for the duration of that process's life. When the last process using the file terminates, the inode is marked free and any space allocated to the file is returned to the filesystem.

Thus, while your file appears to have vanished, as long as any process is using it, the space the file has consumed will continue to be allocated from the filesystem in which it lives!

Regards!

...JRF...
Ninad_1
Honored Contributor

Re: deleting a file

Shiv,

This is a common mistake/problem.
Usually while deleting files you can check
fuser -u filename
to check if the file is opened by any process.
Now in this case if you have lsof on your system them you can run lsof to check which files are open and then if possible kill the process which has the deleted file open.
OR
reboot your system.

If you have an idea which user owns/runs the process which may have opened this file, then do
lsof -u userid

or do
lsof +D dirname -x
where dirname is the path where the file was there e.g. /home/sksonkar
Once the process has been identified - you need to kill the process (at appropriate time) to release the space.

Regards,
Ninad
Bob Ingersoll
Valued Contributor

Re: deleting a file

I do it the easy way:

rm -- -p
rariasn
Honored Contributor

Re: deleting a file

Hi Shivkumar,

?ll|grep "\-p"
-rw-r--r-- 1 usr grp 10 May 2 11:16 -p

?ll -i
1186 -rw-r--r-- 1 usr grp 10 May 2 11:16 -p

?find . -inum 1186 -exec ll {} \;
-rw-r--r-- 1 usr grp 10 May 2 11:16 ./-p

?find . -inum 1186 -exec rm {} \;

?ll

ran