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.
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.
The basic permissions are: Full Control: Users can read, modify, add, move, and delete files, as well as their associated properties and directories.
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With