vi search pattern for replacing line numbers in code snippet

19 12 2008

This is a useful search and replace pattern for deleting the line numbers in a code snippet…

use this command in vi (the unix based txt editor):

%s/^[0-9][0-9]\s*//g

this will delete (replace pattern with nothing) all the line numbers in the following code snippet (thus cleaning it and allowing you to compile it without first manually editing every line):

...
03 import java.util.List;
04 import java.util.ArrayList;
05 import java.util.Iterator;
06
07 public class Todo {
08 private String name;
09 private String note;
...





chmod: copy user / owner permissions to group

24 07 2008

This is a useful unix command to copy the file / dir owner permissions to the group:

find * -exec /bin/sh -c 'chmod g+`ls -ld "{}" | cut -c2-4` "{}"' \;

As pointed out in the post below, chmod actually has built in support for this operation:

chmod g+u file