My blog has moved! Redirecting…

You should be automatically redirected. If not, visit http://www.keynote2keynote.com/ and update your bookmarks.

Friday, February 2, 2007

Unix Trickery Explained

I realized this morning that I should probably provide a bit of explanation about the Unix commands that I used yesterday.

find . -type d -exec chmod 755 {} find . -type f -exec chmod 644 {}

find is a shell program built into OS X and most if not all Unix based systems. If you type 'man find' in the terminal it will tell you all the info about the switches you can use with find. You'll notice that there are many ways to search for things, including by name, type, permissions, etc. Find also allows you to execute programs on its results using the -exec switch.

chmod is program that allows you to set permissions on files and directories. Alternatively you can set permissions using 'Command + I' and looking under 'Ownership and Permissions'. This doesn't allow you to change a bunch multiple file permissions at once, so thats why chmod is useful. chmod is a bit confusing to explain but I'll do my best. To use chmod effectively you need to understand how it works. The numbers after the command set the permissions. To illustrate this open up the terminal and type 'ls -l' This will list all the files in the directory and information about them. The first column is the permissions on the files. You'll notice they are in the format 'drwxrwxrwx'. R stands for read, W denotes write, and X means execute. The first set of 'rwx' is the users permissions, the second set is the users group, and the final set is the world (ie anyone).

In the command 'find . -type f -exec chmod 644 {}' the 6 corresponds to the first set of 'rwx', the middle 4 corresponds to the second set of 'rwx' and the last 4 corresponds to the last set of 'rwx'. The numbers 644 correspond to binary bits, x=1, w=2, r=4. The 6 stands for rw- (read=4 + write=2). So the user has read and write permissions on the file. The 4 stands for r-- (read=4). So if amazingly you are still following me 644 means user has read and write permissions, and group and world have read permission. Heres a rundown of each possibility.

7 = rwx (read write execute)
6 = rw- (read write)
5 = r-x (read execute)
4 = r-- (read)
3 = -wx (write execute)
2 = -w- (write)
1 = --x (execute)
0 = --- (no permissions)

If you've made it this far I've got a treat for you! Do you ever want to open a terminal that is already at the directory that you are currently at in the finder? I do. I can't stand having to cd all the way to a directory (or type the full path) to execute a command on a file. If you download and install Open Terminal Here you won't have to.

Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home