2014-10-27

Grep is one of those Unix utilities around forever and absolutely basic, you can use it anywhere any time without thinking.

Except when you need it.

Today I attempted to use grep to find a string within files in a system directory. Grep decided to not work as described on the packet. I searched for a really simple string specific to one file hidden somewhere in a multilevel directory. Grep decided to interpret the string as something completely different.

Grep is designed to find strings but not the string I entered. I had to switch to Bluefish to find the string.

Grep reported permission errors so I ran grep with system level access. Grep is supposed to read files and do nothing else. The system started reporting weird errors suggesting grep is doing more than reading files. I will not use grep again because it is clearly doing something unknown and possibly dangerous.

Grep eventually locked up without completing. The lockup was after processing just a small part of the directory.

Efficiency

Grep is fast for small simple searches, when it works, but quickly becomes a resource hog. The output can quickly swamp your display, forcing you to rerun the search with changes in an attempt to find what you want.

The alternatives offer better choices for viewing the result, reducing the reruns. If you decide to use grep, look at ways to capture the output in a text file so you can browse and search the output in your editor.

Alternatives

Grep only works from the 1980s DOS box in Linux which is, in turn, copied from the 1980s DOS box style command line used in primitive early versions of Unix, an approach based on the 1935 teletype interface. If you are 97 years old, it was all you had in England when the British were inventing the first electronic computer. (They also invented the first programmable mechanical computer.)

I am happy to use something more modern, something based on the Graphical User Interface invented by Xerox in the 1970s at their Parc research centre. You know the GUI from the version created by Microsoft when Microsoft purchased a license to use the Xerox GUI legally. If you are a fashion victim, you might know the GUI from the version pirated by Apple and released on their disastrous Lisa computer, one of Apple's many failed products.

Just about every useful editor and IDE, Integrated Development Environment, has an option to search for strings in files. Most of them are way ahead of grep with easy to set options for focusing the search.

Bluefish is the fastest editor when opening a few small files. Bluefish has a fast search with options to select the file type and focus the search a few other ways. Bluefish has none of the tricky problems I find in grep.

Bluefish does have other problems and that appears to be standard in Linux. In Windows, there is usually a huge choice and you can find something that does everything you want without annoying problems. In Linux, there is often many choices that are just graphical interfaces to the same primitive utility and they all fail in the same way.

Conclusion

Learn to use all the options in your editor's search.

Technology:

Linux

Show more