Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What permissions are needed to delete a file in unix?

I currently have a directory (udir), which has only read and write permissions for all users. This directory contains two files (file1 & file2)

I initially though that only write access was needed (on the directory) for me to be able to delete/remove a file via (rm udir/file1) but the rm command would give me access denied. when i set the permissions to read, write, and execute, the rm command works.

Obviously the execute access is needed as well but why??

I thought the execute access on a directory was to be able to make it a working a directory and search its contents and access sub directories.

like image 575
Ahmed Khan Avatar asked Feb 11 '19 00:02

Ahmed Khan


People also ask

What permission is required to delete a file in Linux?

User confirmation, read permission, and write permission are not required before a file is removed when you use the rm command. However, you must have write permission for the directory containing the file. After each file name displays, type y and press Enter to delete the file.

Which permission allows you to delete a file?

The basic permissions are: Full Control: Users can read, modify, add, move, and delete files, as well as their associated properties and directories.

How do I delete a file without permission in Unix?

To remove or delete a file or directory in Linux, FreeBSD, Solaris, macOS, or Unix-like operating systems, use the rm command or unlink command.

What are 644 permissions?

644 - owner can read/write, group/others can read only. Some directory permission examples: 777 - all can read/write/search. 755 - owner can read/write/search, others and group can only search.


1 Answers

You actually need read, write and execute permissions on the directory, not on the file itself since the operation is done considering the permissions effects of directories.

A good documentation can be found on this link, which mentions the below in the section Special Considerations on Directories:

To delete a file requires both write (to modify the directory itself) and execute (to stat() the file's inode) on a directory.  Note a user needs no permissions on a file nor be the file's owner to delete it!

like image 113
nortontgueno Avatar answered Oct 03 '22 02:10

nortontgueno