Monday, September 28, 2009

Passwordless ssh

On the local computer: if don't have them already, generate your private/public pair of keys
$ ssh-keygen -t rsa
this should create the files
~/.ssh/id_rsa     - your private key
~/.ssh/id_rsa.pub - your public key

On the remote computer: if it doesn't exist already, create the ~/.ssh directory
$ mkdir ~/.ssh
$ chmod 700 ~/.ssh

Finally copy (or append) the contents of the local file ~/.ssh/id_rsa.pub to the remote file ~/.ssh/authorized_keys. For example (on the local computer):
scp ~/.ssh/id_rsa.pub user@remote.example.com:.ssh/authorized_keys

Thursday, September 3, 2009

Remove Firefox/Iceweasel lock

If Firefox/Iceweasel is "already running, but is not responding", and you are sure it's really not running (e.g. after a clean boot), remove its lock with

rm -i ~/.mozilla/firefox/*/.parentlock ~/.mozilla/firefox/*/lock

Sunday, August 9, 2009

CPAN as non-root user

First, to set up the PERL5LIB environment variable, add the following to your .bash_profile or equivalent:
if [ -z "$PERL5LIB" ]
then
# If PERL5LIB wasn't previously defined, set it...
PERL5LIB=~/perl5lib/lib
else
# ...otherwise, extend it.
PERL5LIB=$PERL5LIB:~/perl5lib/lib
fi
Reboot or source the file. Then, if you are having troubles, make sure you start with a clean user instalation.
> cd ~
> rm -rf .cpan
> rm -rf perl5lib
Create a folder to hold the modules, and start CPAN
> mkdir perl5lib
> cpan
Manual configuration should start, follow the instructions on screen, until at some point the script asks you for any extra arguments for Makefile.PL. You should then supply (all in one line)
PREFIX=~/perl5lib LIB=~/perl5lib/lib INSTALLSITEMAN1DIR=~/perl5lib/man/man1
INSTALLSITEMAN3DIR=~/perl5lib/man/man3
When configuration finishes, make sure CPAN tells you it has writen the updated configuration file. If everything seems fine, type quit.

To install a package now just type
cpan "Some::Module"
Source and more details at Linux Gazette.

Thursday, February 26, 2009

Chop "n" lines from the beginning/end of a file

You need some sort of "inverse" for the standard behavior of the head and tail commands, i.e., print everything but the first/last n lines of a file.

To skip the first n = 10 lines of a file
$ awk '(NR > 10)' file

To print everything but the last n = 10 lines of a file
$ head -n -10 file

Wednesday, February 18, 2009

Make "less" show utf-8 characters

To make the less unix command properly display utf-8 characters, you might want to add the following to your .bash_profile
export LESSCHARSET=utf-8

Wednesday, January 28, 2009

Create TeXShop project

Quick hack to turn a directory into a TeXShop project (i.e. make all .tex files point to a single project root).

ls -1 *.tex | awk '{ print "/bin/echo -n \"main.tex\" > " $1 "shop" }' | sh

to check for sanity you might want to run first without the sh pipe at the end.

Wednesday, January 7, 2009

Add line numbers to a file


awk '{print NR "\t" $0 }' input.txt