1K Linux Commands

From wiki.ucalgary.ca
Revision as of 05:23, 2 March 2011 by Locasto (talk | contribs)
Jump to: navigation, search

1024 Commands: An Introduction to the Linux Command Line

A shell is just a program stored on a computer. When executed, the shell provides an interactive process for issuing commands. For users accustomed to interacting with a computer through a GUI, mouse, or touchscreen, a command line can seem daunting, particularly since the "prompt" (a terse snippit of characters indicating the input location) does very little prompting and often spits back obtuse error messages.

This brief tutorial demonstrates some of the basics of the Linux command line environment using the Bash shell. A reader should have no trouble using another shell as this tutorial largely avoids shell-specific features. Instead, it focuses on a general set of Linux commands.

The Basics

A shell is a program that helps a user interact with a computing environment. The core functionality of most shells, particularly in a Unix environment, is to locate and execute programs on behalf of the user. The user types a command; commands typically include the name of a program and some arguments or data for that program to operate on. The shell locates the named program, supplies the arguments to the program, and waits for the program to complete.

It is important to realize that the shell typically acts like a dispatcher -- except in the cases where it uses its own built-in functionality (or in cases where the user invokes shell-specific scripting commands), the shell merely looks up the location of the named program and asks the operating system to execute that program. Commands (most of which are separate programs) are typically stored in a few well-known locations in the file system, such as /bin, /usr/bin, /sbin, /usr/sbin and the user's own bin/ directory in their home directory. For example, the /bin directory of a recent distribution of Linux includes more than 100 commands, including ones like `arch', `cat', `cp', and `date'. It has over 1800 commands in the /usr/bin directory, 280 in /sbin, and 375 in /usr/sbin. This amounts to more than 2500 possible programs to run.

Unix and Linux environments come with a large variety of commands. Commands are typically external programs, although some functionality is built into the shell because it is simple.

Takeaway Message: the shell is a program that waits for your input. You provide input by typing commands. Commands start with the name of some program and have optional arguments or parameters.

Getting Oriented

So your prompt is waiting for you. Patiently. Before we tell it to do something, let's give you a fallback so you know where to get help --- right in your shell (without resorting to digging through Google results or bugging your friends or system administrator).

The first place to start is knowing how to access documentation. Most Linux shell environments come equipped with a command to do this, the `man' (short for "manual" command). You can supply the `man' command with a number of arguments to control its behavior in various ways, but the simplest form is by giving it just the name of a program whose functionality you'd like to determine. For example, typing the following command and hitting <enter>:

[michael@host 1k]$ man man

causes the manual page for the `man' command to be displayed in the terminal window. Man pages provide the name and brief explanation of the command, a short synopsis, and a list of accepted arguments to the command. Use the manual pages to explore the rich functionality of the many different Linux commands available on a typical system.

1024 Commands

This tutorial is based on a history of 1024 commands I gathered from one of my terminal windows (I have multiple open, each with their own extensive history). The history of each shell sessions is maintained in memory by the shell during runtime and written to the file .bash_history when the shell exits.

One thousand commands didn't seem like enough, and 1024 is a nice power of two.

So, what have I been typing for the last one-thousand twenty four commands? The simplest way to find out is to ask the shell with the `history' command:

[michael@host 1k]$ history
1  clear
2  more disorder.c
3  more ../include/disorder.h
4  more disorder.c
5  clear
6  cat disorder.c
7  clear
8  grep 8080 /etc/services
...
[michael@host 1k]$

What the shell displays is a numbered list of all commands it has kept track of.

Other Resources

  • In the Beginning Was the Command Line (Neal Stephenson)