Archives for February, 2010
Posted by Derek@TheDailyLinux »
3 Comments »

A hard word wrap or line break feature isn’t included in gedit by default, but it’s easily added by using the ‘External Tools’ plugin and a two-liner shell script. This will allow you to format your documents with a line break at column 80, or whatever you’d like it to be, by selecting the text, paragraph, or entire document and applying the shell script. Here’s how…
1. Open gedit
2. Navigate to Edit -> Preferences -> Plugins
3. Enable “External Tools” and press “Configure Plugin”
4. Press “New” and enter “Line Break at Col 80″ (or any name you like)
5. Paste the following script in the “command(s)” text area (you can choose to leave out the #comments, these are only here as a reminder in case you want to modify it to fit your needs):
#!/bin/sh
BREAK=80
# fmt [-WIDTH][OPTION]... [FILE]...
# --uniform-spacing -- one space between words, two after sentences
# --split-only -- split long lines, but do not refill
# --width=WIDTH -- maximum line width (default of 75 columns)
# when FILE is -, read standard input
fmt --uniform-spacing --split-only --width $BREAK -
6. Choose “Current selection” as Input
7. Choose “Replace current selection” as Output
8. At this point, you can choose to create a shortcut key such as “ctrl+m” for easy access.
8. Close “External Tools Manager” by pressing the “Close” button
9. Now this script is executable under the “Tools” menu. Alternatively, you can use your shortcut key for quick access.
The next step would be to somehow get gedit to automatically perform these hard wraps as your typing (like the evolution email client does). If anybody has a suggestion, I’d love to hear about it in the comments below. I’m very surprised that this isn’t included in the already many featured gedit program by default, but thankfully it’s very easily remedied with the method described above.
Posted by Derek@TheDailyLinux »
Add Comment »
If you’re using the Busybox environment common in embedded linux systems, and you come across a situation where you need to refresh the /dev device nodes, simply use the command ‘mdev -s‘. The description from the Busybox help file states:
Scan /sys and populate /dev during system boot
I ran across this scenario today where I had a USB thumb drive plugged into a Technologic Systems SBC. I could see that the device node was assigned as /dev/sda1 after the appropriate modules were inserted, but it didn’t appear in the /dev directory until I used mdev -s. I could then mount it as usual.
I believe the same would be true for typical Linux systems with the udev deamon running in the background, but if the situation did ever come up, I would probably try to simply restart the udev service by using /etc/init.d/udev restart. I haven’t actually come across this situation yet, so obviously, this hasn’t been tested personally.
Posted by Derek@TheDailyLinux »
2 Comments »
A quick tip for automating those terminal prompts or warnings that you may get while, for example, overwriting files during a ‘cp’ command, is to use the ‘yes‘ command which will “be repetitively affirmative”. Use it like this:
yes | cp -r foo/ bar/
The ‘yes’ command will output whatever you want forever as well. For example, if you wanted to say “no” to all prompts or warnings, you would simply use…
yes n | cp -r foo/ bar/
Posted by Derek@TheDailyLinux »
1 Comment »
This is something that I’m still coming to grips with, but today I learned that the cross compile toolchains that Technologic Systems provides for at least some of their products come from CodeSourcery.com. A quick blurb from their website:
CodeSourcery, in partnership with ARM, Ltd., develops improvements to the GNU Toolchain for ARM processors and provides regular, validated releases of the GNU Toolchain. Sourcery G++ Lite Edition supports ARM, Thumb, and Thumb-2 compilation for all architectures in active use, including Version 7 of the ARM Architecture.
For example, today I needed a newer version of the g++ cross compiler targeted towards EABI and glibc, so I took a look around the website at http://www.codesourcery.com/sgpp/lite/arm and found the release in the downloads section here: http://www.codesourcery.com/sgpp/lite/arm/portal/subscription?@template=lite
A short term goal for myself is to figure out what goes into creating a cross compile environment. I think this would be a valuable skill in the embedded Linux market. For now, this was a shock to learn about how simple it really is to be able to simply download the toolchain and that there wasn’t any other trickery or knowledge required.
Posted by Derek@TheDailyLinux »
1 Comment »
This guide will help you understand the very basics of setting up a TFTP server. This was written using Fedora 12 and tested with SELinux disabled. I have not yet confirmed if SELinux needs to be disabled, but I have confirmed that the firewall needs to be configured to allow port 69 (TFTP port). Let’s get to it…
[Read more →]
Posted by Derek@TheDailyLinux »
Add Comment »
Here are the steps that I have taken in the past to fix the “public key is not available:” message while trying to use apt-get:
1.) Use apt-get to install debian-archive-keyring
apt-get install debian-archive-keyring
2.) Try using apt-get again. Additional information will be provided.
3.) Use additional information from last attempt with gpg commands.
Replace the KEYNUMBER with the actual keynumber that you should now have from running apt-get again.
gpg --keyserver wwwkeys.eu.pgp.net --recv-keys KEYNUMBER
gpg --armor --export KEYNUMBER | sudo apt-key add -
4.) Update apt-get to resynchronize the package index files.
apt-get update
5.) You should be good to go!
Keep in mind you may need to run apt-get update a couple of times. Also, make sure your date is set correctly.
Posted by Derek@TheDailyLinux »
Add Comment »
This tidbit intends on helping folks running Linux in an embedded environment to setup a static IP address. This is also applicable to full fledge desktop installations of Linux as well. It has been tested on Debian Linux, but I suspect the process is identical for most distributions. Let’s get to it…
Edit “/etc/network/interfaces” to reflect the changes you’d like to make to your IP address. For example, I would like to setup my Debian box with the IP address 192.168.1.100. I have filled in all of the important information as well as seen below:
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.100
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
Then, edit the “/etc/resolv.conf” file to reflect your DNS servers (or simply use OpenDNS addresses below):
nameserver 208.67.222.222
nameserver 208.67.220.220
Now, reset the eth0 interface by using the command:
ifdown eth0; ifup eth0
Test the connection using the command:
ping google.com
As an additional tidbit, you can simply get an IP address via DHCP using the ‘dhclient’ or ‘pump’ command.
Posted by Derek@TheDailyLinux »
Add Comment »
Today I was asked to compile a program for one of the SBCs that I work with. The difficulty was in trying to choose the correct cross-compiling toolchain. Since there were several different toolchains each with a different version of gcc and glibc, I wanted to know what other utilities like ‘ls’ were compiled with so I had a good idea of which toolchain to use. I found several different methods of finding a suitable toolchain.
A good place to start is on the target system itself, and if it has ldd and gcc installed, then it’s as easy as using:
ldd --version
gcc --version
Another not-so-obvious method to find all information including gcc and glibc versions is simply using (may not work on all systems):
/lib/libc.so.6
If the above doesn’t work, there is yet another solution and that is to actually compile this short program and run it so that it spits out the glibc version used:
#include <stdio .h>
#include <gnu /libc-version.h>
int main (void) { puts (gnu_get_libc_version ()); return 0; }
It may not be as common, but if a binary has not yet been stripped of it’s comments and extras you can use objdump and objcopy to view information about that file. For example, the following command will use objcopy to spit out the section named .comment within the /bin/ls binary to the /tmp/foobar file. The strings command will then spit out readable text from which you can derive the glibc and/or gcc version that was used to compile the binary. Again, keep in mind that this may not work for every binary. Use the objdump command to see which other fields are available.
objcopy -j .comment /bin/ls /tmp/foobar; strings /tmp/foobar
If you have any more methods for extracting this sort of information out of an already-compiled binary, I’d love to hear about it in the comments.
Posted by Derek@TheDailyLinux »
1 Comment »
This is a no-frills Linux command line guide/cheat sheet that will help you archive or compress just about any file that you’re bound to come across. If you’d like to have more options, read the man pages! Also, the opposite to this guide about extracting/uncompressing/unarchiving files in Linux can be found here.
[Read more →]
Posted by Derek@TheDailyLinux »
Add Comment »
Forget pulling up Photoshop, GIMP, or any other GUI program for a simple CLI job. With utilities like ‘mogrify‘ for Linux and ‘sips‘ for Mac OSX, it’s incredibly quick and easy to batch resize images through the command line. For example, if I wanted to resize all images within a particular folder to a width of 800px without losing aspect ratio, I would use the following commands:
Under Linux:
mogrify -resize 800 *.jpg
Under Mac OSX:
sips --resampleWidth 800 *.jpg
There are many more options for these programs, so play around and be sure to read the man pages.
Another usage example that I heard about today was to use the commands above in a script that will automatically create a thumbnail, small, medium, and large image sizes from a supplied image and then copy them off to the appropriate folder. This is useful in building a website that has a lot of different image sizes required for the same image.
Additional Resources:
http://www.smokinglinux.com/tutorials/howto-batch-image-resize-on-linux
http://www.ibm.com/developerworks/linux/library/l-graf/