# GNU/Linux Command-Line Tools Summary

Gareth Anderson <somecsstudent(at)gmail.com>

Chris Karakas - Conversion from LyX to DocBook SGML, Index generation

## Revision History

 Revision 1.2 15th April 2006 Revised by: GA Corrected typing errors, generated new, much smaller index (more accurate in my opinion). Updated errors in document for TLDP. Revision 1.1 28th February 2006 Revised by: CK Corrected typos, generated new index (9000 index entries!). Revision 1.0 6th February 2006 Revised by: GA Major restructuring, now in a docbook book format. Removed large chunks of content and revised other parts (removed chapters and sectioned some areas more). This is likely the final release by the author, I hope that someone finds this guide useful as I do not intend to continue work on this guide. Revision 0.7.1 25th February 2005 Revised by: CK Set special characters in math mode, produced PDF and PS with Computer Modern fonts in OT1 encoding and created correct SGML for key combinations. Revision 0.7 5th December 2004 Revised by: GA Updated document with new grammatical review. Re-ordered the entire Text section. Removed a fair amount of content. Revision v0.6 20th April 2004 Revised by: GA Attempted to fix document according to TLDP criticisms. Added notes and tips more sectioning. Now complying to the open group standards for the UNIX system trademark. Document should be ready for TLDP site. Revision v0.5 6th October 2003 Revised by: GA Fixed a variety of errors as according to the review and made some consistency improvements to the document. Revision v0.4 15th July 2003 Revised by: GA Made small improvements to the document as suggested (so far) by the thorough TLDP review, improved consistency of document and made small content additions. Revision v0.3 26th June 2003 Revised by: GA Minor errors fixed, updated the appendix with information for finding where a tool is from. Fixed referencing/citation problems and improved further reading and intro sections, added an audio section. Revision v0.2 20th April 2003 Revised by: GA This is the initial public release. Added more code-style then before, broke text-section into more subsections. Improved consistency of document and fixed various index entries. Revision v0.1 27th March 2003 Revised by: GA This is the initial draft release (the first release to be converted from LyX to DocBook SGML).

This document is an attempt to provide a summary of useful command-line tools available to a GNU/Linux based operating system, the tools listed are designed to benefit the majority of users and have being chosen at the authors discretion. This document is not a comprehensive list of every existent tool available to a GNU/Linux based system, nor does it have in-depth explanations of how things work. It is a summary which can be used to learn about and how to use many of the tools available to a GNU/Linux based operating system.

## Introduction

This document is an attempt to summarise the many command-line based tools available to a GNU/Linux based operating system. This guide is not a complete listing (I doubt it's possible to document all available programs), this document lists many tools which are available to GNU/Linux systems and which are, or can be useful to the majority of users.

Each tool description provides a quick overview of it's function and some useful options for that individual tool.

The tools listed that require a GUI, usually the X windowing system, are those listed in the Graphics Tools section. All other tools are completely command-line-based and do not require a GUI to run.

If you are looking for information on GUI based tools you will need to look elsewhere.

Also note that a few of the tools in this guide are bash (the Bourne-Again-SHell) specific, tools specific to other shells are not listed in this document.

For some of the tools that are harder to use, or perform a more complex task, there are several mini-tutorials (or mini-guides; Chapter 20) within this document.

Where a mini-guide was considered unncessary, detailed descriptions that explain in detail how a particular tool works, and some examples of how to use it are provided.

Please note that the word “tool” is used interchangeably with the word “command”, both have the same meaning (at least in this guide). For a more detailed explanation, read about the UNIX Tools Philosophy here: Chapter 3 or visit the links in the appendix, Section A.2.2.1.

To find out which tools are bash specific

To find out which tools are bash specific you can type:

enable -a

### Who would want to read this guide?

Anyone who is interested in learning about the tools (also known as commands) available to them when using their GNU/Linux based operating system.

Why would you want to learn how to use the command-line (and available tools)? The Command Line-Interface (CLI), while difficult to learn, is the quickest and most efficient way to use a computer for many different tasks. The CLI is the normal method of use for most UNIX system administrators, programmers and some power users. While a GUI is better suited to some tasks, many operations are best suited to the CLI.

The major motivation behind learning the GNU/Linux CLI is the authors idea that, with software in general, the more time spent learning something equals less time spent performing that particular task (authors opinion only).

This guide is aimed at beginners to intermediate users who want to learn about the command-line tools available to them. Advanced users may wish to use it as a command reference, however this document aims to list commands of interest, as judged by the authors opinion, it is not designed to be completely comprehensive, see the appendix, Section A.2.1 for further information. Or if you are not looking for a command reference guide, but a more gentle introduction to GNU/Linux you may be interested in the Introduction to Linux guide authored by Machtelt Garrels.

This guide could also be considered a summarised version of the Linux Cookbook. If you are looking for a book with more detailed descriptions of each tool have a look at the Linux Cookbook Homepage, also check out the command list from "Linux in a Nutshell 3rd Edition" for an index of 300+ commands and their explanations.

### Who would not want to read this guide?

Anyone who is not interested in the command-line, or anyone looking for a detailed reference to all available GNU/Linux tools should look elsewhere. This is only a summary, while it does list many commands, it's not a complete listing (I don't think it's possible to make a complete listing anyway).

This document would not be of interest to those who already have an expert knowledge of the command-line interface and do require any reference information. Or those readers who require detailed lists of options for each command, the man pages are better suited to this purpose.

### Availability of sources

The modifiable sources of the original book (in english), are available in LyX format (LyX Document Processor) or Machine-translated SGML (SGML markup language).

LyX is a completely free document processor based on LaTeX, downloadable from the LyX homepage.

See for the modifiable sources of this document. These are the official versions. We (the translators and current maintainers) plan to continue work on this document and add new chapters and enhancements. If you want to see the version we are currently working on (the "bleeding edge" version), check the GNU/Linux Command-Line Tools Summary Homepage from time to time (kindly hosted by Chris Karakas).

### Conventions used in this guide

The following conventions are used within this guide:

italic

• Anything appearing in italic, like this is either an executable command or emphasized text. Tools (executable commands) are in italics to prevent confusion. Some tools have names which are real english words, such as the “locate” tool.

key combinations

• Are represented by using a '-' (dash sign) in-between the key(s), which must be used in combination. All combinations are also printed in italics to improve clarity. For example CTRL-Z means hold down the Control key and press the z key.

• Admonitions are little pictures used to emphasize something of importance to the reader. The five types used are:

This is a note

Notes often give important information about a tool.

This is a tip

This will offer a useful switch or useful way to use a tool.

This is something important

This is something that is considered very important. Consider it like a note with extra importance, they are usually there to save the reader time.

This is a caution

This will inform you of something that you be careful about (because it could be harmful to your system).

This is a warning

This will inform you of something that you shouldn't do (because it probably will break something within your system).

code examples

• Code examples are shown for most commands. Below is an example of what code looks like:

    Hello World, I'm a code example. :)

command syntax

• (or a similar phrase) simply shows how you would normally use the command. Often real examples are used instead of explaining the command syntax. The phrase “ Command syntax” is always followed by the way you would type a command in a shell. The standard syntax for any tool is usually:

    command -options file

Note

Note that some tools do not accept options.

wildcards

• Also note that most commands, even when not explicitly stated, will work with standard wildcards (or globbing patterns) such as *, [A-Z] and various other standard wildcards. Refer to Section 20.4.1 for further information.

access keys

• Access keys enable navigation through the document, without relying on a mouse. The following keys have been given special meaning in this document:
• P
• Previous page.
N
• Next page.
H
U
• Up (takes you one level up the section hierarchy).
If you also happen to be reading the document from its original location, then the following access keys can also be used:
• S
• Start (takes you to the author's start page).
T
• The current (“This”) page, without the Sitemenu on the left.
M
• The current page in a frameset, where the left frame contains a Menu.

To use the access keys, you have to simultaneously press a modifier key, which may vary from browser to browser. For example in NN6+/Mozilla, the modifier key is ALT, so you have to use ALT-N to go to the next page, and ALT-P to come back. In other browsers such as IE6, the access keys just give focus to the associated link, so the sequence becomes ALT-N Enter. Try it, you'll like it!

### Resources used to create this document

To create the GNU/Linux Command-Line Tools Summary, I used LyX, the document processor. To convert the LyX files to DocBook SGML I used the lyxtox Scripts created by http://www.karakas-online.de/Chris Karakas.

You may also want to check out the db2lyx package, created by Dr. B Guillion, which can be used to convert LyX files to XML DocBook and XML DocBook back to LyX.

I also had assistance from various The Linux Documentation Project volunteers (see the contributors section Section 1.7 for specific details).

### Feedback

Feedback is necessary for the advancement of this guide. Positive, constructive criticism is encouraged. If you have ideas, suggestions, advice, or problems with this guide, please send an email to the author Gareth Anderson.

Contributions

If you wish to make contributions it is recommended (if possible) to read the LyX file(s) for this document. They contain various notes which you can't see in the other versions.

These notes highlight the areas that need contributions, certain tools which I cannot understand, tools which have not been added, or tools which were removed. These notes also explain some of the structure of this document.

### Contributors

As you may be able to see, parts of this guide are based off various advice columns on GNU/Linux, anything that has being directly quoted from an article can be found in the references, Bibliography, section of this document.

The following is a list of people who have made a significant contribution to this document, in a rough chronological order.

• Chris allowed the use of his lyxtox scripts to convert the LyX file of the document to working DocBook SGML output (to learn how to use the lyxtox scripts yourself, see http://www.karakas-online.de/mySGML/).

• Chris provided useful suggestions and advice, and added an index listing for many of the commands.
• Chris is also responsible for the great looking HTML file for this document (the CSS file and HTML customisations are completely his work).
• Chris has also helped fix up problems in the document (many times), especially with docbook/sgml, and LyX related issues.
• Chris has also improved the structure of the document by adding labels and fixing minor errors.

William West:

• William provided a thorough review of the document as required by the Linux Documentation Project. He is responsible for a variety of improvements to the quality of this document. His contributions include:

• Improvements to the readability of this document.
• Improvements to the structure and consistency of this document.
• Various grammar improvements throughout the document.
• Repair of some minor technical errors.
• Tabatha, as the Linux Documentation Project Review Coordinator (at the time) also gave a brief review of this document. Her general advice was used to improve the structure, language and grammar of the document.

• Rahul provided a brief review of this document for the Linux Documentation Project. Advice from his brief review was integrated into this document to improve readability and structure, several references were added as recommended by Rahul.

• David's criticism of the document (via the TLDP discuss list) were listened to, and attempts to improve the document were made. A number of his criticisms were addressed and improved.

George Harmon:

• George provided a second language review. His detailed review of the material allowed me to improve the general grammar of the document and some minor errors.
• Machtelt provided tips in regard to referencing the correct LDP documents from this guide. As well as general advice on improvements to the guide.

Michael Kerrisk:

• Michael pointed out a number of technical errors in the document after his brief review on behalf of the TLDP during posts to the discussion list.

## Legal

### Disclaimer

No liability for the contents of this document can be accepted. Use the concepts, examples and other content at your own risk. There may be errors and inaccuracies, that may of course be damaging to your system. Although this is highly unlikely, you should proceed with caution. The author does not accept any responsibility for any damage incurred.

All copyrights are held by their respective owners, unless specifically noted otherwise. Use of a term in this document should not be regarded as affecting the validity of any trademark or service mark.

Naming of particular products or brands should not be seen as endorsements.

UNIX is a registered trademark of The Open Group.

Copyright © 2003 - 2006 Gareth Anderson. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license can be found in the section called the GNU Free Documentation License or at the GNU Documentation License Site.

## The Unix Tools Philosophy

A tool is a simple program, usually designed for a specific purpose, it is sometimes referred to (at least throughout this document) as a command.

The “Unix tools philosophy” emerged during the creation of the UNIX operating system, after the breakthrough invention of the pipe '|' (refer to Chapter 6 for information on using the pipe).

The pipe allowed the output of one program to be sent to the input of another. The tools philosophy was to have small programs to accomplish a particular task instead of trying to develop large monolithic programs to do a large number of tasks. To accomplish more complex tasks, tools would simply be connected together, using pipes.

All the core UNIX system tools were designed so that they could operate together. The original text-based editors (and even TeX and LaTeX) use ASCII (the American text encoding standard; an open standard) and you can use tools such as; sed, awk, vi, grep, cat, more, tr and various other text-based tools in conjunction with these editors.

Using this philosophy programmers avoided writing a program (within their larger program) that had already been written by someone else (this could be considered a form of code recycling). For example, command-line spell checkers are used by a number of different applications instead of having each application create its own own spell checker.

This philosophy lives on today in GNU/Linux and various other UNIX system-based operating systems (FreeBSD, NetBSD, OpenBSD, etc.).

For further information (articles) on the UNIX tools philosophy please see the further reading section, here: Section A.2.2.1

## Shell tips

The shell tips chapter provides handy tricks that you may wish to use when you are using a GNU/Linux shell (the command-line interface). This information includes handy shortcut key combinations, the shell's command history and information on virtual terminals.

If you can't boot into your system

If your having problems booting into your system you may like to use a shell so you can boot into your system and attempt to fix things up again.

To do this you need to pass the “init=/bin/sh” to your system before you boot up.

If you don't know how to do this please see Chapter 14, the technique is the same except this time you pass "init=bin/sh" rather than "single".

### General Shell Tips

Automatic Command Completion

• Use the TAB key and bash will attempt to complete the command for you automatically. You can use it to complete command (tool) names. You can also use it when working with the file-system, when changing directories, copying files et cetera.

There are also other lesser known ways to use automatic command completion (for example completing user names):1

ESC-Y (Y: special character)

• Will attempt to complete the command name for you. If it fails it will either list the possible completions (if they exist). If there are none it will simply beep (and/or) flash the screen.

CTRL-X-Y (Y: special character)

• Lists the possible completions (it won't attempt to complete it for you) or beep if there are no possible completions.
Special-characters: Use the following special characters combined with either ESC-Y or CTRL-X-Y , where Y is some special characters. For example ESC-$or CTRL-X-$ to complete an environment variable name.
• ~ (tilde) complete a user name
• @ (at sign) complete a machine name
• \$ (dollars sign) complete an environment variable name
• ! (exclamation mark) a magic character for completing a command name or a file name. The ! special character has the same function as the TAB key. It works in some other situations; for example when completing man page names.

alias

• The alias command will list your current aliases. You can use unalias to remove the alias (to disable it just for one command add a “\” (back-slash) before the command)... An alias allows one command to be substituted for another. This is used to make a command do something else or to automatically add certain options. This can be either be done during one session using the alias command (see below) or the information can be added to the .bashrc file (found in the users home directory). Below is an example of what an alias section (within your .bashrc file) might look like:
# my personal aliases
alias cp='cp -vi' #to prompt when copying if you want to overwrite and will tell you where information is going
alias rm='rm -i' #Prompts you if you really want to remove it.
alias mv='mv -i' #Prompts you if you are going to overwrite something

On any Mandriva GNU/Linux system the global aliases (for all users) are all in /etc/profile.d/alias.sh. The above listed commands already have aliases, as well as several other commonly used commands.

set -x

• set is one of bash's inbuilt commands, try looking in the bash manual for its many usage options. Using set with the -x option will make bash print out each command it is going to run before it runs it. This can be useful to find out what is happening with certain commands such as things being quoted that contain wildcards or special symbols that could cause problems, or complex aliases. Use set +x to turn this back off. Examples After using set -x you can run the command:
ls
The output printed before the command runs (for example):
+ ls -F --color=auto
Which means that the command is really an alias to run ls with the -F and --color=auto options. Use a “\” (backslash) before the command to run it without the alias.

\ (backslash)

• The backslash escape character can be used before a shell command to override any aliases. For example if rm was made into an alias for rm -i then typing “rm” would actually run rm -i. However, typing \rm lets the shell ignore the alias and just run rm (its runs exactly what you type), this way it won't confirm if you want to delete things.

Using rm

Please note that the alias for the remove command is there for a reason. Using it incorrectly could remove files which you don't want removed. Only use \rm if you know exactly what you are doing (recovering files is not easy, rm does not send things to a recycle bin).

The “\” character can be used before special characters (such as a space or a wildcard), to stop bash from trying to expand them. You can make a directory name with a space in it using a backslash before the space. For example you could type cd My\ Directory\ With\ Spaces which normally wouldn't work. The “\” character can also be used to stop bash from expanding certain symbols (as an alternative you could use single quotation marks, although you may need to use both).

The TAB Key

Please note that using the TAB key (automatic-command-completion) will automatically use escapes for spaces (so you don't have to type them manually).

script

• The “script” command creates a typescript, or "capture log" of a shell session - it writes a copy of your session to a file, including commands you type and their output.

~ (tilde character)

• The tilde character is used as an alias to a users home directory. For example, if your user-name was “fred”, instead of typing cd /home/fred you could simply type cd ~. Or to get to fred's tmp directory (under his home directory) you could type cd ~/tmp.

Home directory shortcut

~ (tilde) can also be used as a shortcut to other users home directories, simply type: ~user_name and it will take you to the users home directory. Note that you need to spell the username exactly correct, no wildcards.

set bell-style none

• This particular set command will turn off the system bell from the command-line (use xset -b for X windows). If you want the bell to stay off pernamently (no audible bell) then you can add this command to your “.bashrc” or “.bash_profile” (just add it to the same one you have your alises in...).

reset

• The reset command re-initializes your current terminal. This can be useful when the text from your terminal becomes garbled, simply type “reset” and this will fix your terminal.

exit

• Closes your current terminal (with x-terminals) or logs-out. Also try CTRL-D.

logout

• Logs out of a terminal, also try CTRL-D.

echo

• A little command that repeats anything you type. Example:
echo “hello world”
Simply displays “ hello world”. Example:
echo rm -R *
This will output what will be passed to the rm command (and therefore what would be deleted), putting echo before a command renders it harmless (it just expands wildcards so you know what it will do). Also try using the -e option with echo. This will allow you to use the escape character sequences to format the output of a line. Such as '\t' for tab, '\n' for newline etc.

Using echo to prevent accidents

Typing: echo command(s) could save you the trouble of accidentally doing something you didn't expect.

Using echo allows you to expand the wildcards to understand what will happen before you actually run the command.

### The command-line history

Using the command history

• Use the up and down key's to scroll through previously typed commands. Press [Enter] to execute them or use the left and right arrow keys to edit the command first. Also see history (below).

The history command

• The history command can be used to list Bash's log of the commands you have typed: This log is called the “history”. To access it type:
history n
This will only list the last n commands. Type “history” (without options) to see the the entire history list. You can also type !n to execute command number n. Use !! to execute the last command you typed. !-n will execute the command n times before (in other words !-1 is equivalent to !!). !string will execute the last command starting with that “string” and !?string? will execute the last command containing the word “string”. For example:
!cd
Will re-run the command that you last typed starting with “cd”. “ commandName !*” will execute the “commandName” with any arguments you used on your last command. This maybe useful if you make a spelling mistake, for example. If you typed:
emasc /home/fred/mywork.java /tmp/testme.java
In an attempt to execute emacs on the above two files this will obviously fail. So what you can do is type:
emacs !*
This will execute emacs with the arguments that you last typed on the command-line. In other words this is equivalent to typing:
emacs /home/fred/mywork.java /tmp/testme.java

Searching through the Command History ( CTRL-R )

• Use the CTRL-R key to perform a “reverse-i-search”. For example, if you wanted to use the command you used the last time you used snort, you would type:

CTRL-R then type “snort”. What you will see in the console window is:

(reverse-i-search)':

After you have typed what you are looking for, use the CTRL-R key combination to scroll backward through the history.

Use CTRL-R repeatedly to find every reference to the string you've entered. Once you've found the command you're looking for, use [Enter] to execute it. Alternatively, using the right or left arrow keys will place the command on an actual command-line so you can edit it.

### Other Key combinations

GNU/Linux shells have many shortcut keys which you can use to speed up your work, below is a rough list of some (also see CTRL-R in the history section of the commands, over here, Section 4.2).

CTRL-D

• the “end-of-file” (EOF) key combination can be used to quickly log out of any terminal. CTRL-D is also used in programs such as “at” to signal that you have finished typing your commands (the EOF command).

CTRL-Z

• key combination is used to stop a process. It can be used to put something in the background temporarily.

For example, if you were editing a file with vim or emacs just press CTRL-Z to regain control of the terminal do what you want and then type fg to bring it back. For further information please see Section 9.3.

If fg doesn't work

If fg doesn't work you may need to type jobs and then fg job_name or fg job_number

CTRL-A and CTRL-E

• These key combinations are used for going to the start and end of the line on the command line. Use CTRL-A to jump to the start of the line, and CTRL-E to jump to the end of the line.

CTRL-K

• This key combination can be used to cut or delete what is currently in front of the cursor.

CTRL-Y

• This key combination can be used to paste the last thing you deleted (using CTRL-K or CTRL-W ).

CTRL-W

• This key combination can be used to cut or delete the entire line that has being typed.

### Virtual Terminals and screen

Using the key combination ALT-F* keys you may change to different virtual terminals. You will have several (usually 6) virtual terminals setup with shells. Number 7 is usually setup with X you need to use CTRL-ALT-F* to change to a terminal from within X (X as in the X windowing system).

screen

• is a great program that allows you to switch between multiple virtual terminals on the one physical terminal that you are using. Its a command-line based window manager, clearly this isn't that useful if you do have virtual terminals, but its amazingly useful when you log into machines remotely, using ssh and similar, see Section 13.3. It works on key-combinations, you type
screen`

On the command-line to begin. Now you start with one virtual terminal by default, but using the key combination CTRL-A and then hitting "C" you can create another virtual terminal to use.

Use CTRL-N to go to the next virtual terminal and CTRL-P to go to the previous virtual terminal. Also try hitting CTRL-A to go backwards and forwards between two particular terminals. screen also has various other abilities that you can test out. The documentation and guides are well written so please feel free to read the manual page or try searching the internet.

1. This information was adopted (with editing) from Mandrakesoft's Command Line Manual, see [7] in the Bibliography for further information. (1)