Tag Archives: bash

1,000,000th Fibonacci Number One-Liner in C

This is possibly the best one-liner I’ve ever written: gcc -x c -o /tmp/out – -lgmp

Putting Non-YouTube Videos in MxTube

So, you have your Jailbroken iPod Touch or iPhone with 2.0 firmware running OpenSSH, and you have MxTube 1.5 or better, of course. What if you want one of those pesky videos that YouTube deletes all the time, like Paris Hilton For President? Or maybe you want a full movie on your iPod without having to sync to iTunes since you’re stuck in Linux Land. Well, here’s how.

Putting Images on the iPod Touch from Linux

Idea I wanted to put images on my iPod Touch without using iTunes since, as most of us know, there is no good way to use it from Linux. It turns out there is a magic directory on the iPod Touch where it saves images from Safari. I simply looked at how it saved them, [...]

Renaming Files Sequentially with BASH

I made a cool one-liner in bash today that renames files sequentially. Here’s an example that takes all the JPEGs in a directory and renames them in order: EII=4; for i in *.jpg; do ls $i; \ NEWNAME=IMG_00`printf “%02d” $EII`.JPG; \ echo Renaming $i to $NEWNAME; \ mv $i $NEWNAME; EII=`expr $EII + 1`; done [...]

DNS for bash

Today, I decided I wanted a network service that propagated variables and aliases to every login shell that subscribed to it. This is dangerous on a large scale, but perfectly acceptable on my small home network where everyone trusts everyone else. First, I got Camping installed, bringing back fond memories of Ruby development. I then [...]

Calculating Averages from a CSV with Perl

Code Here’s a quick one-liner using some UNIX utilities and Perl to construct some nice averages from CSV data: for i in `seq 2 20`; do cat crim_rate_2005_by_state.csv | cut -d , -f $i | perl -e ‘$c=$d=0;$e;while(<>){if(/^\d/){$c+=$_;$d+=1}else{s/\s{2,}/ /g;s/”//g;chomp($e=$_);}} print $e, “: “, $c/$d, “\n”‘; done And now, the spaced out version: #!/bin/bash for i [...]

Linux command line tips and tricks

This awesome page told me about the <<< operator in bash. It rocks. It also told me the best way to set an initial login password: umask u=rw,go= openssl rand -base64 6 | tee -a PasswordFile | passwd –stdin joe chage -d 0 joe Also, there’s ssh-copy-id: Usage: /usr/bin/ssh-copy-id [-i [identity_file]] [user@]machine

GNU Screen’s hardstatus

I use GNU Screen. A lot. I found an article linked from DIgg today that showed me how to use a setting called hardstatus to set the little bar at the bottom to my liking. I decided to mess around with it a bit, and I ended up with this: It shows my hostname, IP, [...]

Using seq to zero-pad strings in a series

I thought this was pretty cool: for i in `seq -f "%03g" 1 100`; do wget http://www.gozerog.com/images/Hawking_$i.jpg; done We were trying to do this the other night using bash, but to no avail since the square brackets only work for local file path expansion. I should have remembered seq. Also, this example shows how to [...]

Not a sandwich, but a Vim Which!

I often find myself going to find scripts I’ve written that I want to edit, but I decided today I’d make things easier on myself: hank@rura-penthe ~ $ cat bin/vimwhich #!/bin/bash vim `which $1` All this does is shorten vim `which myscript` to vimwhich myscript. Helpful for just a couple lines of code.