shellspells beta

chmod

chmod [OPTION]... MODE[,MODE]... FILE...
chmod [OPTION]... OCTAL-MODE FILE...
chmod [OPTION]... --reference=RFILE FILE...

chmod changes the permissions on a file or directory

Real men use octal mode!

Examples

Change file permissions using wimp mode. u=user, g=group, o=other

$ touch nostramo
$ ls -l nostramo
-rw-r--r-- 1 garry garry 0 2010-10-27 01:05 nostramo
$ chmod +x  nostramo
$ ls -l  nostramo
-rwxr-xr-x 1 garry garry 0 2010-10-27 01:05 nostramo
$ chmod g+w  nostramo
$ ls -l  nostramo
-rwxrwxr-x 1 garry garry 0 2010-10-27 01:05 nostramo
$ chmod o+w  nostramo
$ ls -l  nostramo
-rwxrwxrwx 1 garry garry 0 2010-10-27 01:05 nostramo
$ chmod go-w  nostramo
$ ls -l  nostramo
-rwxr-xr-x 1 garry garry 0 2010-10-27 01:05 nostramo
$ chmod u-w  nostramo
$ ls -l  nostramo
-r-xr-xr-x 1 garry garry 0 2010-10-27 01:05 nostramo

Change file permissions using octal mode like a real man

$ chmod 644 nostramo
$ ls -l  nostramo
-rw-r--r-- 1 garry garry 0 2010-10-27 01:10 nostramo
$ chmod 755 nostramo
$ ls -l  nostramo
-rwxr-xr-x 1 garry garry 0 2010-10-27 01:10 nostramo
$ chmod 777 nostramo
$ ls -l  nostramo
-rwxrwxrwx 1 garry garry 0 2010-10-27 01:10 nostramo
$ chmod 000  nostramo
$ ls -l  nostramo
---------- 1 garry garry 0 2010-10-27 01:10 nostramo

Set directory sticky bit (ie. within the directory, only a file's owner, the directory owner, or the superuser can rename or delete files)

$ chmod +t /usr/local/tmp
$ chmod 1777 /usr/local/tmp
$ ls -ld /usr/local/tmp
drwxrwxrwt 16 root root 12288 2010-10-27 01:17 /usr/local/tmp