Protection Example With the rm Command


$ mkdir temp_dir [Enter]		# create a new directory

$ ls -l [Enter]				# verify creation and protection modes
total 4
drwxr-xr-x    2 mthomas   mthomas       4096 Feb 10 16:21 temp_dir

$ cd temp_dir [Enter]			# change location to new directory

$ touch foo [Enter]			# create an empty file named foo

$ ls -l foo [Enter]			# verify file was created
-rw-r--r--    1 mthomas   mthomas          0 Feb 10 16:21 foo

$ chmod 000 foo [Enter]			# disable all protection modes

$ ls -l foo [Enter]			# verify protection settings
----------    1 mthomas   mthomas          0 Feb 10 16:21 foo

$ rm foo [Enter]			# remove file overriding protections
rm: remove write-protected file `foo'? y

$ ls -l foo [Enter]			# verify file is gone
ls: foo: No such file or directory

$ touch foo [Enter]			# re-create file foo

$ chmod 777 foo [Enter]			# enable all protections

$ ls -l foo [Enter]			# verify protection settings
-rwxrwxrwx    1 mthomas   mthomas          0 Feb 10 16:22 foo

$ chmod 400 ../temp_dir [Enter]		# disable write/execute user protections

$ rm foo [Enter]			# try to remove file
rm: cannot lstat `.': Permission denied

$ cd .. [Enter]				# move up 1 level

$ ls -l [Enter]				# examine protections
total 4
dr--------    2 mthomas   mthomas       4096 Feb 10 16:22 temp_dir

$ rm temp_dir/foo [Enter]		# try again to remove file
rm: cannot remove `temp_dir/foo': Permission denied

Notes: