Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: How do I know if I can delete a file/folder?

by mitd (Curate)
on Jul 26, 2002 at 06:50 UTC ( #185445=note: print w/ replies, xml ) Need Help??


in reply to Re: How do I know if I can delete a file/folder?
in thread How do I know if I can delete a file/folder?

Sorry grep I had to down vote your node because at worse is just wrong and at best its misleading.

If you are in a modern version of linux it's easy
What does 'modern linux' mean? The basic operation of *nix file permission and ownership mechanisms have been around since before my beard started turning grey.

To delete a file (in a directory you can get to) you must have write permissions for that directory.
Not complete, you must also have write permissions on the file. What if the directory is 777 but he file is 644 and owned by root or file is owned by you and is 444? Try this:

Prologue drwxrwxrwx 2 mitd mitd 4096 Jul 26 02:36 testdir -r--r--r-- 1 mitd mitd 0 Jul 26 02:36 testdir/myfile perl -e 'open(FILE,">myfile") or die $!'

For a more OS independant solution copy the file (cp -p) to a backup file then delete the original
'OS' dependent true but then you quote a *nix dependent command with no regard to what the ownership permissions conditions might be,

mitd-Made in the Dark
'Interactive! Paper tape is interactive!
If you don't believe me I can show you my paper cut scars!'


Comment on Re: Re: How do I know if I can delete a file/folder?
Download Code
Re: Re: Re: How do I know if I can delete a file/folder?
by gmpassos (Priest) on Jul 26, 2002 at 08:15 UTC
    I put a plus vote for this, not because grep was wrong, but because mitd sent a reply, not just clicked in the radio! I think that any type of post trying to help another user is valid.

    "The creativity is the expression of the liberty".
Re: Re: Re: How do I know if I can delete a file/folder?
by greenFox (Vicar) on Jul 26, 2002 at 09:04 UTC

    Not complete, you must also have write permissions on the file. What if the directory is 777 but he file is 644 and owned by root or file is owned by you and is 444?

    Nope on unix if you have write permission to the directory you can delete the file, even if it is owned by root and not even readable by you, on Solaris it comes up with a "override protection 600" prompt and then it is gone, tested on BSD and Linux as well.

    --
    Until you've lost your reputation, you never realize what a burden it was or what freedom really is. -Margaret Mitchell

Re: Re: Re: How do I know if I can delete a file/folder?
by aersoy (Scribe) on Jul 26, 2002 at 14:22 UTC

    Hello,

    Well, you are wrong. When you delete a file, you are actually changing the directory that the file is in, so write access to that directory is sufficient. When you change the contents of the file, eh, you are actually changing the file itself, so you need write access to the file (write access to the directory is not needed). Your demonstration is in no way related to the question asked.

    Since the original question asks about deleting, then write access to the directory is the right answer, therefore grep is not wrong.

    --
    Alper Ersoy

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://185445]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2014-09-18 03:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (105 votes), past polls