----------
chmod +r foo.txt
-r--r--r--
chmod +w foo.txt
--w--w--w-
chmod +rw foo.txt
-rw-rw-rw-
chmod +rwx foo.txt
-rwxrwxrwx
control file permissions for the user (u), the user's group (g), and all others (o). Here's a command where I add read permission for the current user:
chmod u+r foo.txt
-r--------
chmod u+w foo.txt
--w-------
chmod u+x foo.txt
---x------
chmod u+rwx foo.txt
-rwx------
chmod g+rwx foo.txt
----rwx---
chmod o+rwx foo.txt
-------rwx
You can also combine chmod permission commands:
chmod u+rwx,g+rw,o+r foo.txt
-rwx-rw-r--
So far I've just shown "add" permissions with the plus sign (+) operator; this adds permissions to whatever permissions the file already has. You can also use the equal sign operator (=) to set permissions exactly, instead of adding to file permissions as shown so far. Here's a typical chmod equal permission assignment:
chmod u=rw,g=rw,o=r foo.txt
-rw-rw-r--
When using numerical chmod commands you use a sequence of three numbers, and the numbers again correspond to the user, group, and owner of the file.
chmod 400 foo.txt
-r--------
chmod 440 foo.txt
-r--r-----
chmod 444 foo.txt
-r--r--r--
chmod 664 foo.txt
-rw-rw-r--
chmod 774 foo.txt
-rwxrwxr--
chmod 700 foo.txt
-rwx------
Finally, if you want to set and read and execute permissions -- typically done on a directory -- you use this command:
chmod 755 MyDir
-rxwr-xr-x