in administration

Commands of the week

A weekly listing of commands that are new to me or that I’ve had to refresh myself with.

Piping and Grep

<h1>Pipe stderr</h1>

command 2&gt;&amp;1 &gt;/dev/null | command

<h1>Grep stderr</h1>

command 2&gt;&amp;1 &gt;/dev/null | grep 'pattern'

<h1>Colorize output</h1>

command | grep --color 'pattern'

<h1>Grep and colorize stderr</h1>

command 2&gt;&amp;1 &gt;/dev/null | grep --color 'pattern'

C Programming

<h1>Define a macro at compile time with definition = 1</h1>

cc -Dmacro_name program.c

<h1>gprof, profiles the time spent in each function of your c program</h1>

cc -g -pg -o program program.c #generates gmon.out
gprof program gmon.out &gt; gprof.out

<h1>Includes a table like:</h1>

<h1>Each sample counts as 0.01 seconds.</h1>

<h1>%   cumulative   self              self     total</h1>

<h1>time   seconds   seconds    calls  ns/call  ns/call  name</h1>

<h1>78.15     44.28    44.28 200000000   221.40   221.40  get</h1>

<h1>9.64     49.74     5.46 400000000    13.65    13.65  generate_point</h1>

<h1>7.74     54.12     4.38 200000000    21.93    21.93  hash_key</h1>

<h1>2.52     55.55     1.43 200000000     7.15   251.50  calculate_distance</h1>

<h1>1.59     56.45     0.90                             main</h1>

<h1>0.20     56.57     0.12 14514500     7.92     7.92  radians</h1>

<h1>0.16     56.66     0.09  2902900    31.00    31.00  put</h1>

<h1>0.00     56.66     0.00        1     0.00     0.00  hashtable_init</h1>

<h1>0.00     56.66     0.00        1     0.00     0.00  hashtable_init_list</h1>

SVN Issues on OSX

I got an error when trying to operate on an SVN repo over samba:

svn: Can’t move ‘.svn/tmp/entries’ to ‘.svn/entries’: Operation not permitted

sudo chflags -R nouchg . # unset the OSX immutable flag

Creating empty directories

I needed to create a bunch of placeholder directories in a repo for logging.

<h1>Lists the numbers 1 to 31, zero padded to length 2</h1>

seq -f &quot;%02g&quot; 1 31

<h1>Creates directories logs01 to logs31</h1>

for i in $(seq -f &quot;%02g&quot; 1 31); do mkdir logs$i; done;

<h1>Create an empty directory in a git repo, add the following gitignore to the directory</h1>

cat &gt; .gitignore

<h1>Ignore everything in this directory</h1>


<h1>Except this file</h1>


<h1>END WITH CTRL+d</h1>

<h1>Copy the .gitignore into each directory</h1>

for i in $(seq -f &quot;%02g&quot; 1 31); do cp .gitignore logs$i; done;

<h1>Remove the original .gitignore</h1>

rm .gitignore