Listing files with the path in Bash

March 1st, 2008

This little script will print a list of the current files in a directory, prefixed with the full path:

#!/bin/sh
curdir=`pwd`
if [ $# -eq 1 ]
then
usrdir=”$1″
ls | xargs -I % echo `pwd`/% | sed -e s!$usrdir!!
else
ls | xargs -I % echo `pwd`/%
fi

You can optionally provide an initial part of the path to ignore. I use this when writing code change emails where I have to list the updated files within a codebase (and I’ve touched most files in a given directory) and I clip the local path up to the root of the codeset. Assuming the script is saved as “lspath”:

lspath /Users/pete/Sites/project/trunk

Even handier is piping it into the OS X clipboard for easy pasting:

lspath /Users/pete/Sites/project/trunk | pbcopy

Keyboard

February 27th, 2008


Posted by ShoZu

Is Link Journalism any different to the majority of reporting?

February 26th, 2008

ReadWriteWeb has an interesting but not exactly deeply thought-out piece on Link Journalism. I think the point they miss is to question how much journalism done for mainstream media channels is nothing more than repitition of the day’s news agenda - it’s not a coincidence that most journalists’ bosses are called editors.

Haven’t you ever noticed how many news channels at any given time are just churning through the same few Reuters or AP stories as everybody else?  This can be potentially, if not in fact usually, less “original” than more obviously link-based journalism as there is inevitably less freedom and multi-lateralism in the sources.

Then again, I went to art college I have even read Death of the Author so I guess I’ve been a bit brainwashed.

Split and Rename text files from the Bash command line

February 26th, 2008

I occasionally read text files (usually downloaded from the Gutenberg Project) on my mobile phone. This is not the best user experience, but bearable and very useful at times.

The most annoying issue is the incredibly slow management of very large text files (sometimes greater than 1Mb) that my phone displays - so i decided to rename them.

Using my mac, I came up with this couple of commands to do the work for me, between them they will split all text files into 1000 line chunks, and assuming an original filename of “somefile.txt” also rename them to “somefile_XX.txt” where XX is actually two letters denoting the part, starting at aa, ab, ac, etc.

The first command is dead easy and splits the files:

for file in *.txt ; do split $file $file ; done

This will split the files and turn “somefile.txt” into “somefile.txtaa”, “somefile.txtab”, “somefile.txtac” etc. which is obviously not great - so we need the next step:

for file in * ; do mv $file `echo $file |
sed 's/(.*).txt([a-z]{2})/1_2.txt/’` ; done

Now you should have all the files nicely named “somefile_aa.txt”, “somefile_ab.txt”, “somefile_ac.txt” etc.

You might prefer numbers rather than letters, in which case just check out the man page for the ’split’ command.

Am I a Twit

February 26th, 2008

Am I a twit for using twitter?

MS Paint

September 16th, 2007

Posted by ShoZu

The Real Threat

July 26th, 2007

Along the lines of my recent post about car-related deaths versus terrorism-related deaths, see this graph representing the amounts of deaths related to different issues.

I may have to steal the ‘Saint Pete for Peace’ moniker.

Morning after

July 22nd, 2007


Ugh

Posted by ShoZu

sunny

July 21st, 2007

Posted by ShoZu

Nuisance buttons

July 17th, 2007

Posted by ShoZu

This excellent old intercom was removed from our flat recently to be replaced by a boring old phone. The thing I’ll miss most insthe ‘Nuisance button’ that I was never brave enough to press.