Some Linux commands

Some Linux commands

One of the steepest Unix/Linux learning curves is the sheer number of built-in commands, all of which have many options -- most of which you'll never use. Plus there are a number of advanced commands that are extremely powerful but also extremely complex.

To help address this, this page introduces a number of built-in Linux utilities along with some of their common options, by category.

Command line file arguments can be replaced by standard input

Most built-in Linux commands that obtain data from a file can also accept the data piped in on their standard input.

And here's a Linux commands cheat sheet you may find useful:

Basic commands

Displaying file contents

  • cat outputs all the contents of its input (one or more files and/or standard input) or the specified file

    • cat -n prefixes each line of output with its line number

    • CAUTION – only use on small files!

  • zcat <file.gz> like cat, but understands the gzip (.gz) format, and decompresses the data before writing it to standard output

    • CAUTION – only use on small files! ..or pipe the output to more

    • Another CAUTION – does not understand .zip or .bz2 compression formats

  • more and less pagers

    • both display their (possibly very long) input one Terminal "page" at a time

    • in more:

      • use spacebar to advance a page

      • use q or Ctrl-c to exit more

    • in less:

      • q – quit

      • left, right arrows - move back or forward one character

      • up, down arrows - move up or down one line

      • Ctrl-f or spacebar – page forward

      • Ctrl-b – page backward

      • /<pattern> – search for <pattern> in forward direction

        • n – next match

        • N – previous match

      • ?<pattern> – search for <pattern> in backward direction

        • n – previous match going back

        • N – next match going forward

    • use less -N to display line Numbers

    • use less -I to use case Insensitive pattern searches

    • less can be used directly on .gz format files

  • head and tail

    • show you the first or last 10 lines (by default) of their input

    • head -n 20 or just head -20 shows the first 20 lines

    • tail -n 2 or just tail -2 shows the last 2 lines

    • tail -n +100 or just tail +100 shows all lines starting at line 100

    • tail -n +100 | head -20 shows 20 lines starting at line 100

    • tail -f shows the last lines of a file, then follows the output as more lines are written (Ctrl-c to quit)

  • gzip <file> – compresses <file> contents creating a <file.gz> compressed file

    • and removes the original <file>

  • gunzip <file.gz> – un-compresses <file.gz> contents creating a <file> file

    • and removes the <file.gz> file

    • gunzip -c <file.gz> | more (or less)

      • like zcat, un-compresses lines of <file.gz> and outputs them to standard output

      • <file.gz> is not altered on disk

      • always pipe the output to a pager!