CIT050 Index > A Note About Permissions

A Note About Permissions

Questions 8 and 10 in this assignment (p. 114 in the book) always get people confused. Here, excerpted from the Linux™ Phrasebook1 (pp. 144-145), is a useful table.

Permission Meaning for
Regular File
Meaning for
r Can view contents of file Can list with ls
w Can modify contents of file Can delete, rename, or add files
x Can execute file Can access this directory in order to read files or subdirectories; or to run files

Important: renaming, deleting, or creating a file is an operation on the directory where you are doing the operation, not on the file itself. If I issue this command:

mv old.txt new.txt

That command will succeed as long as I have write access to the directory where old.txt resides. Try it. Do this sequence of commands; they will work fine even though old.txt has no permissions. They work because you do have write permission on the directory where that file lives.

mkdir testdir
cd testdir
touch old.txt
chmod 000 old.txt
mv old.txt new.txt
ls -l new.txt
chmod 644 new.txt

If you remove write permission from testdir, then you can no longer do the mv. Presuming you are still in testdir:

chmod 555 .          # removes write permission from testdir
mv new.txt newer.txt # will give you "permission denied"
ls -l new.txt        # will still work; ability to do ls comes from the read permission
chmod 755 .          # give back write permission to testdir

One other note: Even if a file inside a directory is readable, if you don’t have access to that directory, you can’t look at the file. For example:

$ chmod 755 testdir  # restore all permissions for owner
$ ls -ld testdir
drwxr-xr-x testdir/

# Create a readable file in the directory
$ echo "Readable file" > testdir/example.txt
$ ls -l testdir/example.txt
-rw-r--r-- testdir/example.txt
$ cat testdir/example.txt
Readable file

# Remove "x" from the directory; this makes the
# directory inaccessible for reading files or subdirectories.
$ chmod 222 testdir
$ cat testdir/example.txt
cat: testdir/example.txt: Permission denied

1 Granneman, S. (2006). Linux™ Phrasebook. Indianapolis, IN: Sams Publishing.