Find Text and Find/Replace Easier Than You Think in Linux

How to search all files for a text string:

grep -lr string ./ > results.txt

-l will print only the path and file names of the matches.

Search all files of a certain name for a certain string:

grep -lr string ./ | grep filename

Yes, do specify ./ if you are doing all directories within current.

(source and more info)

Find an replace a string in files:
Searching for a way to do this usually leads me to finding fancy scripts that don’t work right, are scary (create temp files, etc) or aren’t recursive. Just have backups at hand and test the following combination of find and sed before unleashing it, because it works great! You can test it by replacing sed with grep

find ./ -type f -exec sed -i ’s/string1/string2/’ {} \;

Within specific file names/extentions…

find ./ -iname \*.htm\* -exec sed -i 's/\-2005/\-2007/g' {} \;

Don’t forget to use escape \ as seen above. And if your strings contain forward slash / just use a different delimiter such as pipe | or escape it.

You can also install rpl, as shown in the source pdf, for even cleaner line of code for executing your find and replace.

(source and more info) A nice pdf to keep by your side.

Posted in quickfire, tips | Tagged , , , , , | 1 Comment

Open Source storage server

This is not going to be a full review, but more a general take on things.

Since moving from VMware Server to ESXi to host my virtual machines, I’ve been very interested in looking into some more of the advanced features of ESX and ESXi yet most of these require iSCSI.  I remember from a few years back using Openfiler to do some simple samba file sharing, and remembered it supported iSCSI as one method of giving out storage.

Now, I’ve yet to use any of the features of ESX that require iSCSI, or even setup Openfiler to export storage via iSCSI, but I have been using it for simple file sharing and must say I’m quite impressed.

Setup is a breeze, taking about 20 minutes on an older PC. Management is done almost entirely through a web interface, that is very easy to use.  Unlink many of the other appliance packages out there, the web interface is very simple and straight forward.  Very much impressed with that.

Over the next few months I’ll be exploring Openfiler much more, and hopefully getting into some of it’s more advanced features including interface bonding, md devices and clustering.  I plan to keep updating as things more along.

Posted in other, projects | Tagged , , , , | Leave a comment

Installing Dropbox on Ubuntu (and others)

I’ve been using dropbox to sync and share files between my various computers for quite some time, and overall have been very pleased.  However, one area things are not so great… documentation for installation on Linux.  After having to reinstall on my notebook, I decided to somewhat document the hidden part of the process.

After downloading the .deb (or other package) and installing, dropbox instructions leave you hanging.  There is no dropbox folder, there is no daemon running, nothing.  The next step is simply to run dropbox start -i to install the daemon and launch the process to move forward.  It’s simple, easy and poorly documented.  Maybe dropbox should add this to the end of their install instructions?

Posted in quickfire, tips | Tagged , | 1 Comment

OhioLinux September 25-27, 2009

This years OhioLinux Fest starts tomorrow and runs until Sunday. I’ll be there. You should to. More info at the OhioLinux website

Posted in Uncategorized | Tagged , | 1 Comment

Modify Windows XP routing table

During some network changes I’ve found the need to modify the routing table.

To change the default route on Windows XP (and possibly Windows Vista, 2000, etc) you use the route command. The syntax is pretty simple, here is a quick example….

route change 0.0.0.0 mask 0.0.0.0 172.18.12.120

To delete or add routes, simply change the keyword change to either add or delete.

route add 192.168.0.0 mask 255.255.255.0 10.10.0.50
Posted in quickfire, tips | Tagged , | Leave a comment

Check speed of connected link in Linux

If you’ve ever wanted to check on the status of your Ethernet links, you’ve probably used the ip commands (or ifconfig) to view some basic information.  However, you might have noticed these commands do not tell you what the current link speed is, or other possibly important details.  That’s where ethtool comes in.

[jonmoore@megaton ~]$ sudo ethtool eth0
Settings for eth0:
Supported ports: [ MII ]
Supported link modes:   10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes:  10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: MII
PHYAD: 1
Transceiver: external
Auto-negotiation: on
Supports Wake-on: g
Wake-on: d
Link detected: yes

As you can see, ethtool will show you the support modes, as well as the current mode.  From the above example, I’m currently connected at 1000Mb/s at Full Duplex.  Very nice.

Check out the ethtool man page for more useful commands.

Posted in quickfire, tips | Tagged , | Leave a comment

Cancel a traceroute on Cisco devices

Many times I’ve started a traceroute to either a mistyped IP address, the wrong IP or something else that I would really rather not wait for 30 hops to time out before moving on. When doing the traceroute the device tells yous to “Type escape sequence to abort,” but doesn’t share what exactly this escape sequence is. After a bit of googling and finding a few references here and here I’ve found an answer.

This elusive key combination is CTRL+SHIFT+6 twice. I’ve had mixed results using it, but it appears, that holding CTRL+SHIFT while hitting 6 works sometimes, and others retyping the entire combination works. Either way, it’s been a help.

Posted in quickfire, tips | Tagged | Leave a comment

Extend the timeout on SSH connections

A quick google search will quickly answer this question, but I’ve found myself asking it a few times lately.  Often when I let an SSH session go idle, I’ll end up being disconnected.  By adding ServerAliveInterval 60 to ~/.ssh/config I’ve managed to limit this from happening.

There is also a similar server side fix for this.  Consult man ssh_config and man sshd_config for more details.

Posted in quickfire, tips | Tagged , | Leave a comment

Counting occurance of word in list

I’ve had a need to count the number of times a certain value (in this case, a word) appears in a list when using OpenOffice.org.

Here was my problem.  I had a long list of values, each had a status of either “good”, “bad”, or “incomplete”.  I wanted to count the number of times each of the follow occurred.  It turned out to be pretty easy.

Create the following formula where you want the count to be.COUNTIF(range,expression) and bobs your uncle.

Posted in tips | Tagged | Leave a comment

Connecting to serial devices with minicom

I’ve often found the need to break out the console cable to configure a router, switch, or other device that only had a serial console.  On Windows, most folks fall back on the good old hyper terminal to get the job done.  This works great, as long as your on Windows.

Since I’ve been getting myself to use Linux (specifically Archlinux) more and more, I’ve managed to find a way to connect to these devices in a fairly straightforward manner.

Here comes minicom.  Included in most package management systems, is just a {yum,apt,pacman} away, and you’re ready to roll.  On first run, you need to execute minicom -s and setup some basic configurations options. Namely, if you’re connecting to a Cisco device, set the port speed to 9600 baud, and the rest of the defaults should be fine.

At this point, you’re ready to start configuring. Enjoy.

Posted in Uncategorized | Leave a comment