Demoing Distributions

I finally got my big desktop computer organized and rebuilt to the latest version of Ubuntu. The computer has two 500GB SATA drives on it, so I also put Sun's Virtualbox on it and am now downloading Open Source operating systems like crazy. I have already got two Linux distributions and one Unix installed and about five or so more downloaded.

I want to get back into trying out all kinds of distributions again because for about the past year I have stopped hopping from one distribution to the other and settled on Ubuntu. So I am a bit out of touch on non-Debian based operating systems.

I have been taking some notes on my experience installing and playing with these systems and I will post my thoughts here as I get time.

Basic Grep Searching

Grep is a tool for searching through the contents of files on the command line. It can be very useful for activities like finding records in log files or searching a directory of files for specific content. Anyway, it is a very powerful tool that has many options which can make it quite complex to construct a useful command.

Typically when I use it always takes me a few tries to get the syntax right because I forget how the basic options go. So I figure I would record it here for future reference; so a basic search goes like this:

grep -rni searchterm /path/to/directory/or/file

The basic form of the command is the command followed by options followed by the search term and then where in the file system to look.

The options are as follows:

  • r is for recursive, this way if you are trying to search a folder it will search all files in the folder and everything in all sub-folders too.
  • n means it will show you what line of the file the the match was found. this can be useful to know if you are looking through files to find and change something.
  • i means that the search will be case-insensitive. Which means that it doesn't care whether or not the match is made up of uppercase or lowercase letters. So if your search term is foo; Foo, FOo and FOO will all be a positive match.

There are many more options but these are the most useful typical options.

The search term cannot have any spaces in it unless you put quotes (or something) around it. You could also use basic regex (i.e. ?+.).

The path is the last argument and it can be a folder or a single file. If you specify a folder it will search the whole folder and all of its sub-folders, you can also use an asterisk to specify a range of files and folders.

Counting the Lines in a Set of Files

I find myself needing this command every once in a while and I can never remember exactly how it goes. It parses through a directory (and subs) to give you a report on how many lines are in each file. It is great for working with csv files.

wc -l `find ./ -name '*.csv'`

I got this from an old post on Dev Shed forums that I participated in. I posted it here so I don't have to keep seeking out the post every time I am trying to remember this command.

http://forums.devshed.com/showthread.php?p=1857692#post1857692

Command Line Reference

Came across this on digg today. It is another reference sheet for common Linux/Unix commands and programs. It has a lot of good common uses of good programs like scp, rsync, svn, psql and mysql.

http://cb.vu/unixtoolbox.xhtml

Linux/Unix Cheet Sheet Collection

This is a great article that compiles over fifty references for both Linux and Unix. It pretty much all command line references, which can be really handy.

Thanks to Scott Klarr for compiling this list of references.

Linux-Unix cheat sheets - The ultimate collection

{
}