Does 'Owning' A Directory Or File Give You And Special Permissions?
chmod 00000
makes the directory/file inaccesable to owner and group. The only thing you and the group that owns the file can do is remove it with rm -rf tmp/
. Nothing better than an example:
$ mkdir tmp
$ chmod 00000 tmp
$ cd tmp
bash: cd: tmp: Permission denied
You can see the directory with ls -l
d--------- 2 rinzwind rinzwind 4096 Oct 13 14:35 tmp
and but only with sudo
permissions can you enter the directory ...
$ sudo su
# cd tmp
#
Regarding the other posts: yes you can remove a file/dir that is chmodded to 00000:
$ mkdir tmp
$ chmod 00000 tmp
$ rm -rf tmp/
$ touch 1
$ chmod 00000 1
$ rm 1
rm: remove write-protected regular empty file `1'? y
$
As the owner you are also allowed to reset the permissions. That is something someone else (except for root) is allowed too.
A directory is just a special kind of file so the following applies equally to directories and files.
Being the owner allows you to reset access to the file so that you can then read the file. Other than root, other users won't be able to do so.
Until you reset the access the file will be inaccessible to you the same as it would be for other users.
Being the owner of the file does not allow you to remove (delete it). You must have write access to the containing directory to remove it.
Example script demonstrating what can and can't be done. (Don't run as root, but requires sudo access.):
#!/bin/bash
DIR=directory$$
FILE=$DIR/file$$
echo We can remove it - own both file and directory
mkdir $DIR
date > $FILE
chmod 0000 $FILE
ls -ld $DIR $FILE
rm -f $FILE
ls -ld $DIR $FILE
echo
echo We can not remove it - no write access to directory
date > $FILE
chmod 0000 $FILE
chmod -w $DIR
ls -ld $DIR $FILE
rm -f $FILE
ls -ld $DIR $FILE
echo
echo We can remove it - even if we do not own it
chmod 0000 $FILE
chmod +w $DIR
sudo chown root:root $FILE
ls -ld $DIR $FILE
rm -f $FILE
ls -ld $DIR $FILE
echo
echo We can not remove it - even if we can read it - do not own directory
date > $FILE
cat $FILE
sudo chown root:root $DIR
ls -ld $DIR $FILE
cat $$FILE
rm -f $FILE
ls -ld $DIR $FILE
echo
sudo chown $LOGNAME $DIR
echo Now we can clean up
rm -f $FILE
rmdir $DIR
# EOF