Commands useful for viewing contents of files.

Generally, these should be applied only text files.


cat [file[s]] # concatenate.

  • displays contents of a list of files.
  • displays them in the order specified.
  • When used with redirection, >, creates a single concatenated file.
  • When used with piping, |, creates a single data stream input to next cmd.
  • When used without input file, redirects keyboard input to specified file.
    # used [ctrl]D to specify end of input. Some Options:

    head file[s] # show the 1st 10 (default) lines of a file.

  • Useful for looking at comment area of source code or shell script.
  • Uses line-feed delimiter to recognize lines for most options.

    Some Options :


    tail file[s] # show the last 10 (default) lines of a file.

  • Useful for looking at log files, which have latest log info appended to end of file.
  • Uses line-feed delimiter to recognize lines for most options.

    Some Options :


    od [file] # octal dump. Displays the byte value of each byte in a file.

  • Default display is in 2 byte octal format.
  • Can be safely used to view binary files.

    Some Options:


    more file[s] # view the contents of text file one screen at a time.

  • Use [return] to advance on line.
  • Use / and regular expressions to search forward.
  • Can only move forward in file.
  • Refuses to view binary file.
  • Superseded by less

    less file[s] # shows the contents of a file one screen at a time.

  • Allows movement or search in either direction.
  • Allows use of {up|down} arrow keys or some vi (vim) keys to move.
  • Uses regular expression (regex) patterns to do search matches.
  • Can search forwards or backwards in text.
  • Highlights found instances of phrase.
  • May be used to safely view a binary. Probably won't make sense.

    Some Options :

    less can be used to view/search multiple files. Some useful cmds:

    pr # displays file in printer friendly format.

  • Doesn't actually print.
  • Use redirection to capture output.
  • Prints header information and numbers pages.

    Some Options :


    diff # compares two files and reports any different lines.

  • Indicates how each file should be modified to match other.
  • Files need to be fairly similar for this to be useful.

    Some Options :


    comm # compares two files and generates 3 columns.

  • More useful if files contain single item or short grouping lists.
  • Files need to be fairly similar for this to be useful.

    grep # global regular expression (regex) parser.

  • Search utility with an extensive search criteria 'language'.
  • Case sensitive but this can be over-ridden.
  • Displays lines containing strings matching criteria.
  • Multiple search patterns can be specified.
  • Search patterns can be stored in file for repeated use.
  • Can search through list of files.

    Some search criteria :

    Some Options : fgrep - version of grep that doesn't use regular expressions - faster.
    egrep - version of grep that uses different regular expressions - adds some features but loses others.
    Both are now emulated in grep with appropriate options.


    Commands useful for modifying contents of files.

    aspell # interactive spell checker.

  • Uses a standard dictionary database.
  • But also allows user to keep a local database of additional words.
  • Saves original file as a .bak When a questionable word is found, user is provided several options.

    sort # sorts a file or files and sends results to standard output.

  • Sorts text based files, expects end of line markers.
  • Original file not modified.
  • Most often used with redirection to generate new sorted version of file.
  • DO NOT redirect to same file as source, file will be destroyed before being opened.

  • Use -o option to put output back in source file.
  • Multiple input files may be specified, will generate single sorted output.
  • Can specify 'columns' or fields to use as primary sort key criteria.
  • Can specify alternative field separators as column separators.
  • Can sort in reverse order.
  • Can check if sorted without doing any sorting.
  • Can recognize, understand, and sort on date.

    Some Options :