February 2, 2011
"When you’re young, you look at television and think, There’s a conspiracy. The networks have conspired to dumb us down. But when you get a little older, you realize that’s not true. The networks are in business to give people exactly what they want. That’s a far more depressing thought. Conspiracy is optimistic! You can shoot the bastards! We can have a revolution! But the networks are really in business to give people what they want. It’s the truth."

— Steve Jobs in WIRED magazine, February 1996

January 26, 2011
The origin of Unix file delete permissions

Unix file permissions fall into three basic categories, read, write and execute. Which one do you think controls file deletion? It’s probably write, right? Well, let’s test it:

$ touch foo; chmod -w foo
$ ls -l foo
-r-------- 1 user group 0 2011-01-24 12:16 foo
$ rm foo
$ ls foo
ls: cannot access foo: No such file or directory

That’s weird, it looks like I successfully deleted that file. Maybe it’s governed by user/group ownership.

$ touch foo; sudo chown root:root foo
$ ls -l foo
-rw------- 1 root root 0 2011-01-24 12:18 foo
$ rm foo
$ ls foo
ls: cannot access foo: No such file or directory

I just deleted a file owned by root. WTF?

It turns out, Unix file deletion (and creation) is controlled by write access to the parent directory. Let’s demonstrate quickly:

$ mkdir test; touch test/foo
$ chmod -w test
$ rm test/foo
rm: test/foo: Permission denied

You see, each Unix file has a dedicated datastructure that stores metadata called an inode. While inodes store permissions, access/modification timestamps and other useful info, they do not track file location or name. Instead, directories map file names to inodes. The name of an inode is derived from its location. When we delete a file with the rm command, we are merely removing a directory entry. Hence, we only need write permissions to the directory in question.

You can even link to an inode from multiple directory locations with the ln command. These references are called hard links and are counted by the inode. The inode is reclaimed and the disk storage freed only when the reference count reaches zero. So not all rm operations will result in the underlying file being destroyed, which is yet another reason for file deletion being controlled by the parent directory.

12:24pm  |   URL: http://tmblr.co/Zn_4by2lOCTj
  
Filed under: unix files security 
January 5, 2011
Apparently the iPhone also has a universal orientation lock like the iPad. Here’s how to use it:

Doube-tap the home button to view the recent apps selector.
Swipe right on the selector to reveal the iPod controls and, lo and behold, the orientation lock.
Lie in bed all morning browsing the web.
(Step 3 is optional.)

Apparently the iPhone also has a universal orientation lock like the iPad. Here’s how to use it:

  1. Doube-tap the home button to view the recent apps selector.
  2. Swipe right on the selector to reveal the iPod controls and, lo and behold, the orientation lock.
  3. Lie in bed all morning browsing the web.

(Step 3 is optional.)

November 10, 2010
Keep trying till you succeed with Bash

The following Bash snippet will repeat a command with the given delay until it succeeds.

while [ "$?" -gt "0" ] ; do
    sleep 120 # delay in seconds between retries
    # insert command to retry here
done

Unix processes return integers when they exit. These values can be read via $? in Bash. As a matter of convention, a process that completes without errors will return 0, so by checking for exit codes greater than zero we can detect errors and retry.

4:18pm  |   URL: http://tmblr.co/Zn_4by1Rb4ez
  
Filed under: bash cli 
October 24, 2010
Click on album art.
⌘-W main window.
Pretend iTunes is a minimalist music player.

  1. Click on album art.
  2. ⌘-W main window.
  3. Pretend iTunes is a minimalist music player.

October 23, 2010
Secure delete with rm on OS X

I discovered this gem in the rm man page on OS X the other day:

-P  Overwrite regular files before deleting them.  Files are
    overwritten three times, first with the byte pattern 0xff,
    then 0x00, and then 0xff again, before they are deleted.

So there you go rm -P will securely delete a file from your disk with minimum hassle (i.e. without having to through the Thrash folder). This might be one of those goodies OS X inherited from BSD. On Linux you have to use something like shred to achieve the same thing.

Addendum: santry on the HN Thread points out the same thing can done via the srm command. Several people also noted that secure delete interacts unpredictably with modern file systems. jrockway points out that full disk encryption should be used in place of secure delete for this reason.

9:02pm  |   URL: http://tmblr.co/Zn_4by1Ia1s9
  
Filed under: cli rm os x security 
August 14, 2010
"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair."

— Douglas Adams, presumably talking about how distributed systems are more reliable since fault tolerance is baked into the architecture

Liked posts on Tumblr: More liked posts »