Linux tools and utilities

[tools-silhouette.jpg]

The GNU/Linux system has a rich and powerful toolbox. It is a collection of programs (many of them written in C) that execute commonplace tasks. Some of these programs are implementations of algorithms and data structures discussed in the present site.

astyle

Does a correct indentation of the source file of a C program. See the astyle site.

bc

Basic calculator: arbitrary precision calculator language. Does calculations with arbitrarily large integer numbers.  See the documentation in Wikipedia, or in man7.org.

~$ bc

chardet

Universal character encoding detector: tries to find, heuristically, the encoding scheme of a file.

~$ chardet names-of-files

cmp

Similar to the diff utility. See documentation in Wikipedia or in man7.org.

~$ cmp file1 file2

diff

The UNIX file-difference utility. Compares the lines of two text files. Shows the lines of the first file that are not in the second and vice-versa.  See documentation in Wikipedia, or in man7.org.

~$ diff -b -B file1 file2

enscript

Converts text files to HTML, PostScript, and other formats.  Example:

~$ enscript --highlight=c --color --language=html \
            --output=filename.html filename.c

converts filename.c into filename.html. See documentation on the official site or in Wikipedia.

file

Tries to find the type (text, executable, binary, etc.) of a file as well as the encoding scheme of the file (ASCII, ISO-LATIN-1, UTF-8, etc.).  The command

~$ file -i *

writes a report about the contents of the current directory. See manual in man7.org.

fmt

A simple text formatter.  See documentation in Wikipedia, or in man7.org.  Example:

~$ fmt -w65 <file_name>

gcc

GNU Compiler Collection:  compiles C programs.  See manual in the gnu.org or man7.org. See also the entry GNU Compiler Collection in Wikipedia.  Example:

~$ gcc -std=c99 -Wall file1.c file2.c

See a tutorial in the Cprogramming.com or in a page of the CSE141 course at the University of California in San Diego.

gdb

GNU debugger.  See documentation on the official site, or in Wikipedia, or in man7.org.  See also the GDB Quick Reference card.  Example:

~$ gdb

To learn how to use the GDB read the articles Debugging with GDB and Debugging Segmentation Faults and Pointer Problems in Cprogramming.com.  See also the tutorial of the CSE141 course at the University of California.

gprof

GNU profiler: makes run-time statistics of a program (how many times each function was called, how much time each function consumed, etc.). See documentation in Wikipedia, or in man7.org.  Example:

~$ gprof

grep

Looks for a pattern in all the files of a directory.  See documentation in Wikipedia, or in man7.org.  Example:

grep -r -s -i -e 'pattern' ./

hexdump

A filter that displays the contents of a file in a format specified by the user. See also od.

iconv

A filter that changes the encoding scheme of a text file (for example, from ISO-LATIN-1 to UTF-8). The name of this filter is a shorthand for international conversion.  Example:

~$ iconv -f iso-8859-1 -t utf-8 in.txt -o out.txt

(The option -f means from and the option -t means to.)  See documentation on the official site, in Wikipedia, or in man7.org.

ispell

Spelling checker.  See documentation in Wikipedia.  Example:

~$ ispell -t files

less

Displays the contents of a file on the terminal screen. See documentation in Wikipedia, or in man7.org.  Example:

~$ less filename

make

Automates the process of compiling a program. See section Make and Makefile in chapter How to organize, compile, and debug a C program.  See documentation in Wikipedia, or in man7.org.  Example:

~$ make

See also the Makefile entry in Wikipedia.

od

Octal dump: displays all the bytes of a file. Example:

~$ od -t u1 -A d filename

to show all the bytes in decimal notation.  Say

~$ od -t o1 -A d filename

to show the bytes in octal notation.  Say

~$ od -t c -A d filename

to show the ASCII characters represented by each byte.  See documentation in Wikipedia, or in man7.org.  See also hexdump.

pr

Prepares text files for printing.  See documentation in Wikipedia, or in man7.org.  Example:

~$ pr -3 -t

sort

Sorts the set of lines of a text file in a dictionary order that respects the norms of the local language.  We are assuming that the local language is America English and the encoding is UTF-8. The order is more complex than a simple lexicographic order. Example:

~$ sort file_name

The choice of the local language is determined by the environment variable LC_COLLATE of the system.  We are assuming that the value of LC_COLLATE is en_US.UTF-8. If this is not the default, you may call the program by saying

~$ LC_COLLATE=en_US.UTF-8 sort file_name

To sort lexicographically byte-by-byte, ignoring the characters that some blocks of bytes may represent, say

~$ LC_COLLATE=C sort file_name

See documentation in Wikipedia or in man7.org.

valgrind

Finds flaws in memory management that may lead to memory leaks and segmentation faults, and makes statistics about the execution of a program.  See documentation on the site of the tool, or in Wikipedia or in man7.org.  Example:

~$ valgrind --leak-check=yes filename

See the article Using Valgrind to Find Memory Leaks and Invalid Memory Use in Cprogramming.com.

wc

Word count:  counts the number of lines, of words, and of bytes of an ASCII file.  Example:

~$ wc filename.txt

See a version of the wc program written by Donald Knuth and Silvio Levi. See the documentation of the program before it is automatically converted into C code. This was written by Knuth and Levi to illustrate the CWEB system of literate programming.

See documentation in Wikipedia, or in man7.org.