chrisspeck.com

Chris' random ramblings

How to chroot from a Ubuntu LiveCD

For the sake of posterity, the following commands will allow you to login to an otherwise unbootable Linux install and run commands from the install on the hard drive:

sudo fdisk -l
sudo mount /dev/sda6 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt /bin/bash

With thanks to this part of the Ubuntu wiki.

For those are are interested, I managed to break my 64 bit install of Karmic 10.04 on my brand new Asus laptop by activating the proprietary (Nvidia) drivers when the install offered. After Usplash I see now is a black screen, however the system is working. Installing the version from Nvidia’s website did not help. Deleting xorg.conf (and forcing the system to use the fall-back VESA driver) worked.

posted by specky in Uncategorized and have No Comments

Neat things with find, LAME and sed in Bash

Just want to chronicle l some really neat, time saving tricks I’ve picked up today for handling files in bash.

The first, how to use the find command:

 find -type f -iname "*.txt"

Easy enough, right?

Let’s use find and cp to back up a bunch of text files:

 find . -name "*.txt" -execdir cp {} a_copy.txt  \;

NOTE: the above assumes that there is only one text file in each directory, and will create a file in the same directory being a copy of whatever file it is that the find command returns.

Let’s string find to sed, and use sed to replace all instances of “.ogg” to “.mp3″ within a collection of text files:

 find . -name "*.txt" -exec sed -i "s/.ogg/.mp3/g" '{}' \;

Let’s also use find and LAME together to convert a batch of wav files to mp3 files (I recommend you run the following from within a screen session):

  find -type f -name "*.wav" -execdir /usr/bin/lame -V3 {} \;

NOTE: The above will create mp3 files in the form of “somefile.wav.mp3″ in the same directory that “somefile.wav” is located.

Let’s use find to delete the remaining wave format files:

 find -type f -iname "*.wav" -delete

The above commands can save hours of messing around with a file manager.

posted by specky in Uncategorized and have No Comments

Using SSH in Bash to tunnel IP traffic

While it is trivial to set up locally forward ports using a GUI SSH client like Putty, I have a habit of forgetting how to do the same at the Bash command line, and I find the ssh man page a tad confusing. Cutting straight to the chase:-

$ ssh -X myserver.dyndns.org -p 1045 -L 10001:192.168.0.100:10000

This will connect to server called “myserver.dyndns.org” on arbitrary external port 1045, and map your localhost port 10001 to port 10000 on the machine with IP address 192.168.0.100 on the remote site (allowing you, for instance to access Webmin on the remote machine by going to https://localhost:10001 ).

The tack “-X” tells SSH to forward X11 requests, allowing you to run GUI applications on the remote machine and have the display on your local machine without further configuration in a Linux environment, or after installing a program like Cygwin on a Windows machine.

posted by specky in Uncategorized and have No Comments