Linux in a NutshellLinux in a NutshellSearch this book

Chapter 3. Linux Commands

Contents:

Alphabetical Summary of Commands

This chapter presents the Linux user, programmer, and system administration commands. These are entered into a shell at the console or on a virtual terminal on a graphical desktop.

Each entry is labeled with the command name on the outer edge of the page. The syntax line is followed by a brief description and a list of available options. Many commands come with examples at the end of the entry. If you need only a quick reminder or suggestion about a command, you can skip directly to the examples.

Typographic conventions for describing command syntax are listed in the Preface. For help in locating commands, see the index at the back of this book.

We've tried to be as thorough as possible in listing options. The basic command information and most options should be correct; however, there are many Linux distributions and many versions of commands. New options are added and sometimes old options are dropped. You may, therefore, find some differences between the options you find described here and the ones on your system. When there seems to be a discrepancy, check the manpage. For most commands you can also use the option --help to get a brief usage message. (Even when it isn't a valid option, it will usually result in an "invalid option" error along with the usage message.)

Traditionally, commands take single-letter options preceded by a single hyphen, like -d. A more recent convention allows long options preceded by two hyphens, like --debug. Often, a feature can be invoked through either the old style or the new style of options.

3.1. Alphabetical Summary of Commands

aclocal

aclocal [options]

GNU autoconf tool. Place m4 macro definitions needed by autoconf into a single file. The aclocal command first scans for macro definitions in m4 files in its default directory (/usr/share/aclocal on some systems) and in the file acinclude.m4. It next scans for macros used in the configure.in file. It generates an aclocal.m4 file that contains definitions of all m4 macros required by autoconf.

Options

--acdir=dir
Look for macro files in directory dir instead of the default directory.

--help
Print help message, then exit.

--output=file
Save output to file instead of aclocal.m4.

--print-ac-dir
Print the name of the directory to be searched for m4 files, then exit.

--verbose
Print names of files being processed.

--version
Print version number, then exit.

-I dir
Additionally, search directory dir for m4 macro definitions.

addr2line

addr2line [options] [addresses]

Translate hexadecimal program addresses into filenames and line numbers for the executable given with the -e option, or a.out if -e is not specified. If addresses are given on the command line, display the filename and line number for each address. Otherwise, read the addresses from standard input and display the results on standard output (useful for use in a pipe). addr2line prints two question marks (??) if it cannot determine a filename, and 0 if it cannot determine the line number. addr2line is used for debugging.

Options

-b bfdname, --target=bfdname
Set the binary file format using its binary file descriptor name, bfdname. Use the -h option for a list of supported formats for your system.

-C, --demangle[=style]
Decode (demangle) low-level symbol names into user names. See the -h help output for a list of styles supported by your compiler.

-e file, --exe=file
Specify the filename of the executable to use. The default is a.out.

-f, --functions
Display function names in addition to filenames and line numbers.

-h, --help
Display help information and exit.

-s, --basenames
Strip directories off filenames and show only the basenames.

agetty

agetty [options] port baudrate [term]

System administration command. The Linux version of getty. Set terminal type, modes, speed, and line discipline. agetty is invoked by init. It is the second process in the series init-getty-login-shell, which ultimately connects a user with the Linux system. agetty reads the user's login name and invokes the login command with the user's name as an argument. While reading the name, agetty attempts to adapt the system to the speed and type of device being used.

You must specify a port, which agetty will search for in the /dev directory. You may use -, in which case agetty reads from standard input. You must also specify baudrate, which may be a comma-separated list of rates through which agetty will step. Optionally, you may specify the term, which is used to override the TERM environment variable.

Options

-f file
Specify the use of file instead of /etc/issue upon connection to terminal. It is overridden by -i.

-h
Specify hardware, not software, flow control.

-H hostname
Write login hostname into the utmp file. By default, no login host is specified.

-I string
Specify string to be sent to tty or modem.

-i
Suppress printing of /etc/issue before printing the login prompt.

-l program
Specify the use of program instead of /bin/login.

-m
Attempt to guess the appropriate baud rate.

-n
Don't prompt for a login name.

-t timeout
Specify that agetty should exit if the open on the line succeeds and there is no response to the login prompt in timeout seconds.

-L
Do not require carrier detect; operate locally only. Use this when connecting terminals.

-w
Wait for carriage return or linefeed before sending login prompt. Use when sending an initialization string.

anacron

anacron [options] [job]

System administration command. Normally started in a system startup file. Execute commands periodically. By default, the anacron command reads a list of jobs from a configuration file, /etc/anacrontab. The file consists of shell variables to use when running commands, followed by a list of tasks to run. Each task specifies how often in days it should be run, a delay in minutes to wait before running the task, a unique job identifier used to store a timestamp, and the shell command to execute. Timestamps for the last run of each task are stored in the /var/spool/anacron file. For each task, anacron compares the stored timestamp against the current time. If the command has not been executed within the specified frequency, the command is run. Upon completion anacron records the new date in the timestamp file. Limit anacron to a specified task by giving its unique job identifier on the command line.

The anacron command is often used to support the cron daemon on systems that are not run continuously.

Options

-d
Run in foreground rather than as a background process. Send messages to standard error.

-f
Run tasks ignoring timestamps.

-h
Print help message, then exit.

-n
Run tasks now, ignoring delay specifications.

-q
Suppress messages to standard error when using the -d option.

-s
Execute tasks serially. Do not start new task until previous task is completed.

-t file
Read tasks from file instead of from /etc/anacrontab.

-u
Update timestamps for tasks, but don't run them.

-V
Print version number, then exit.

apmd

apmd [options]

System administration command. apmd handles events reported by the Advanced Power Management BIOS driver. The driver reports on battery level and requests to enter sleep or suspend mode. apmd will log any reports it gets via syslogd and take steps to make sure that basic sleep and suspend requests are handled gracefully. You can fine-tune the behavior of apmd by specifying an apmd_proxy command to run when it receives an event.

Options

-c n, --check n
Set the number of seconds to wait for an event before rechecking the power level. Default is to wait indefinitely. Setting this causes the battery levels to be checked more frequently.

-P command, --apmd_proxy command
Specify the apmd_proxy command to run when APM driver events are reported. This is generally a shell script. The command will be invoked with parameters indicating what kind of event was received. The parameters are listed in the next section.

-p n, --percentage n
Log information whenever the power changes by n percent. The default is 5. Values greater than 100 will disable logging of power changes.

-V, --version
Print version and exit.

-v, --verbose
Verbose mode; all events are logged.

-W, --wall
Use wall to alert all users of a low battery status.

-w n, --warn n
Log a warning at ALERT level when the battery charge drops below n percent. The default is 10. Negative values disable low battery level warnings.

-q, --quiet
Disable low battery level warnings.

-?, --help
Print help summary and exit.

Parameters

The apmd proxy script will be invoked with the following parameters:

start
Invoked when the daemon starts.

stop
Invoked when the daemon stops.

suspend [ system | user ]
Invoked when a suspend request has been made. The second parameter indicates whether the request was made by the system or by the user.

standby [ system | user ]
Invoked when a standby request has been made. The second parameter indicates whether the request was made by the system or by the user.

resume [ suspend | standby | critical ]
Invoked when the system resumes normal operation. The second parameter indicates the mode the system was in before resuming. critical suspends indicate an emergency shutdown. After a critical suspend the system may be unstable, and you can use the resume command to help you recover from the suspension.

change power
Invoked when system power is changed from AC to battery or from battery to AC.

change battery
Invoked when the APM BIOS driver reports that the battery is low.

change capability
Invoked when the APM BIOS driver reports that some hardware that affects its capability has been added or removed.

apropos

apropos string ...

Search the short manual page descriptions in the whatis database for occurrences of each string and display the result on the standard output. Like whatis, except that it searches for strings instead of words. Equivalent to man -k.

apt

apt

The Advanced Package Tool, the Debian package management system. A freely available packaging system for software distribution and installation. For detailed information on apt and its commands, see Chapter 5.

ar

ar key [args] [posname] [count] archive [files]

Maintain a group of files that are combined into a file archive. Used most commonly to create and update static library files as used by the link editor (ld). Compiler frontends often call ar automatically. Only one key letter may be used, but each can be combined with additional args (with no separations between). posname is the name of a file in archive. When moving or replacing files, you can specify that they be placed before or after posname.

Keys

d
Delete files from archive.

m
Move files to end of archive.

p
Print files in archive.

q
Append files to archive.

r
Replace files in archive.

t
List the contents of archive or list the named files.

x
Extract contents from archive or only the named files.

Arguments

a
Use with r or m key to place files in the archive after posname.

b
Same as a, but before posname.

c
Create archive silently.

f
Truncate long filenames.

i
Same as b.

l
For backward compatibility; meaningless in Linux.

N
Use count parameter. Where multiple entries with the same name are found, use the count instance.

o
Preserve original timestamps.

P
Use full pathname. Useful for non-POSIX-compliant archives.

s
Force regeneration of archive symbol table (useful after running strip).

S
Do not regenerate symbol table.

u
Use with r to replace only files that have changed since being put in archive.

v
Verbose; print a description of actions taken.

V
Print version number.

Example

Replace mylib.a with object files from the current directory:

ar r mylib.a `ls *.o`
arch

arch

Print machine architecture type to standard output. Equivalent to uname -m.

arp

arp [options]

TCP/IP command. Clear, add to, or dump the kernel's Address Resolution Protocol (ARP) cache (/proc/net/arp). ARP is used to translate protocol addresses to hardware interface addresses. Modifying your ARP cache can change which interfaces handle specific requests. ARP cache entries may be marked with the following flags: C (complete), M (permanent), and P (publish). In kernels before 2.2, a published entry was used for creating an ARP proxy, a technique by which one system can act as a gateway to another system on the same subnet. While arp can create a proxy for a single system, subnet proxies are now handled by the arp kernel module. See the Linux 2.4 Advanced Routing HOWTO for details. We have retained the subnet proxy information here for older kernels.

Options

host option arguments may be given as either a hostname or an IP address. When using the -D option, they may also be given as a hardware interface address (e.g., eth0, eth1).

-a [hosts], --display [hosts]
Display entries for hosts or, if none are specified, all entries.

-d host, --delete host
Remove the specified host's entry.

-D, --use-device
Use the hardware address associated with the specified interface. This may be used with -s when creating a proxy entry.

-d host [pub], --delete host [pub]
Remove host's entry. To delete a proxy entry, use the pub argument and specify the interface associated with the proxy using -i.

-f file, --file file
Read entries from file and add them.

-H type, --hw-type type, -t type
Search for type entries when examining the ARP cache. type is usually ether (Ethernet), which is the default, but may be ax25 (AX.25 packet radio), arcnet (ARCnet), pronet (PROnet), or netrom (NET/ROM).

-i interface, --device interface
Select an interface. If you are dumping the ARP cache, this option will cause the command to display only the entries using that interface. When setting entries, this will cause the interface to be associated with that entry. If you do not use this option when setting an entry, the kernel will guess.

-n, --numeric
Display host IP addresses instead of their domain names.

-s host hardware-address [netmask mask] [pub], --set host hardware-address [netmask mask] [pub]
Add a permanent entry for host at hardware-address. A hardware-address for type ether hardware is 6 hexadecimal bytes, colon-separated. The pub argument can be used to set the publish flag, creating a proxy entry. On kernels before 2.2x, you can specify a netmask on behalf of which the current system should handle requests.

-v, --verbose
Verbose mode.

Examples

Display entry for host eris:

arp -a eris

Set a permanent cache entry for host illuminati, whose hardware address you know:

arp -s illuminati 00:05:23:73:e6:cf

Set an ARP proxy for host fnord using the eth0 interface's hardware address:

arp -Ds fnord eth0 pub

Remove the fnord ARP proxy:

arp -i eth0 -d fnord pub
as

as [options] files

Generate an object file from each specified assembly language source file. Object files have the same root name as source files but replace the .s suffix with .o. There may be some additional system-specific options.

Options

-- [ | files]
Read input files from standard input, or from files if the pipe is used.

-a[cdhlmns][=file]
With only the -a option, list source code, assembler listing, and symbol table. The other options specify additional things to list or omit:

-ac
Omit false conditionals.

-ad
Omit debugging directives.

-ah
Include the high-level source code, if available.

-al
Include an assembly listing.

-am
Include macro expansions.

-an
Suppress forms processing.

-as
Include a symbol listing.

=file
Set the listing filename to file.

--defsym symbol=value
Define the symbol to have the value value, which must be an integer.

-f
Skip whitespace and comment preprocessing.

--fatal-warnings
Treat warnings as errors.

--gstabs
Generate stabs debugging information.

--gdwarf2
Generate DWARF2 debugging information.

-o objfile
Place output in object file objfile (default is file.o).

--statistics
Print information time and space assembler uses.

-v
Display the version number of the assembler.

-I path
Include path when searching for .include directives.

-J
Don't warn about signed overflow.

-R
Combine both data and text in text section.

-W
Don't show warnings.

-Z
Generate object file even if there are errors.

at

at [options] time

Execute commands at a specified time and optional date. The commands are read from standard input or from a file. (See also batch.) End input with EOF. time can be formed either as a numeric hour (with optional minutes and modifiers) or as a keyword. It can contain an optional date, formed as a month and date, a day of the week, or a special keyword (today or tomorrow). An increment can also be specified.

The at command can always be issued by a privileged user. Other users must be listed in the file /etc/at.allow if it exists; otherwise, they must not be listed in /etc/at.deny. If neither file exists, only a privileged user can issue the command.

Options

-c job [job...]
Display the specified jobs on the standard output. This option does not take a time specification.

-d job [job...]
Delete the specified jobs. Same as atrm.

-f file
Read job from file, not from standard input.

-l
Report all jobs that are scheduled for the invoking user. Same as atq.

-m
Mail user when job has completed, regardless of whether output was created.

-q letter
Place job in queue denoted by letter, where letter is any single letter from a-z or A-Z. Default queue is a. (The batch queue defaults to b.) Higher-lettered queues run at a lower priority.

-V
Display the version number.

Time

hh:mm [modifiers]
Hours can have one digit or two (a 24-hour clock is assumed by default); optional minutes can be given as one or two digits; the colon can be omitted if the format is h, hh, or hhmm (e.g., valid times are 5, 5:30, 0530, 19:45). If modifier am or pm is added, time is based on a 12-hour clock. If the keyword zulu is added, times correspond to Greenwich Mean Time.

midnight | noon | teatime | now
Use any one of these keywords in place of a numeric time. teatime translates to 4:00 p.m.; now must be followed by an increment (described in a moment).

Date

month num[, year]
month is one of the 12 months, spelled out or abbreviated to its first three letters; num is the calendar date of the month; year is the four-digit year. If the given month occurs before the current month, at schedules that month next year.

day
One of the seven days of the week, spelled out or abbreviated to its first three letters.

today | tomorrow
Indicate the current day or the next day. If date is omitted, at schedules today when the specified time occurs later than the current time; otherwise, at schedules tomorrow.

Increment

Supply a numeric increment if you want to specify an execution time or day relative to the current time. The number should precede any of the keywords minute, hour, day, week, month, or year (or their plural forms). The keyword next can be used as a synonym of + 1.

Examples

In typical usage, you run at and input commands that you want executed at a particular time, followed by EOF.

$ at 1:00 am tomorrow
at> ./total_up > output
at> mail joe < output
at> <EOT>            Entered by pressing Ctrl-D
job 1 at 2003-03-19 01:00

The two commands could also be placed in a file and submitted as follows:

$ at 1:00 am tomorrow < scriptfile

More examples of syntax follow. Note that the first two commands are equivalent.

$ at 1945 December 9
$ at 7:45pm Dec 9
$ at 3 am Saturday
$ at now + 5 hours
$ at noon next day
atd

atd options

System administration command. Normally started in a system startup file. Execute jobs queued by the at command.

Options

-b n
Wait at least n seconds after beginning one job before beginning the next job. Default is 60.

-d
Print error messages to standard error instead of using syslog.

-l average
When system load average is higher than average, wait to begin a new job. Default is 0.8.

-s
Process queue once, then exit.

atq

atq [options]

List the user's pending jobs, unless the user is a privileged user; in that case, list everybody's jobs. Same as at -l, and related to batch and atrm.

Options

-q queue
Query only the specified queue and ignore all other queues.

-v
Show jobs that have completed but have not yet been deleted.

-V
Print the version number.

atrm

atrm [options] job [job...]

Delete jobs that have been queued for future execution. Same as at -d.

Options

-q queue
Remove job from the specified queue.

-V
Print the version number and then exit.

audiosend

audiosend [email@address]

Send an audio recording as an email from a properly equipped workstation (Sun and Sony, with microphones). After prompting for address, subject, and Cc: fields, the program asks the user to record a message, then allows him to re-record, send, or cancel.

autoconf

autoconf [options] [template_file]

Generate a configuration script from m4 macros defined in template_file, if given, or in a configue.ac or configure.in file in the current working directory. The generated script is almost invariably called configure.

Options

-d, --debug
Don't remove temporary files.

-f, --force
Replace files generated previously by autoconf.

-h, --help
Print help message, then exit.

-i, --initialization
When tracing calls with the -t option, report calls made during initialization.

-o file, --output=file
Save output to file.

-t macro, --trace=macro
Report the list of calls to macro.

-v, --verbose
Verbosely print information about the progress of autoconf.

-I dir, --include=dir
Search in directory dir for input files.

-V, --version
Print version number, then exit.

-W category, --warnings=category
Print any warnings related to category. Accepted categories are:

cross
Cross compilation.

obsolete
Obsolete constructs.

syntax
Questionable syntax.

all
All warnings.

no-category
Turn off warnings for category.

none
Turn off all warnings.

error
Treat warnings as errors.

autoheader

autoheader [options] [template_file]

GNU autoconf tool. Generate a template file of C #define statements from m4 macros defined in template_file, if given, or in a configue.ac or configure.in file in the current working directory. The generated template file is almost invariably called config.h.in.

Options

-d, --debug
Don't remove temporary files.

-f, --force
Replace files generated previously by autoheader.

-h, --help
Print help message, then exit.

-o file, --output=file
Save output to file.

-v, --verbose
Verbosely print information about the progress of autoheader.

-I dir, --include=dir
Search in directory dir for input files.

-V, --version
Print version number, then exit.

-W category, --warnings=category
Print any warnings related to category. Accepted categories are:

obsolete
Obsolete constructs.

all
All warnings.

no-category
Turn off warnings for category.

none
Turn off all warnings.

error
Treat warnings as errors.

automake

automake [options] [template_file]

GNU automake tool. Creates GNU standards-compliant Makefile.in files from Makefile.am template files and can be used to ensure that projects contain all files and install options required to be standards-compliant. Note that Versions 1.4 and 1.6 differ enough that many distributions include an automake14 package for backward compatibility.

Options

-a, --add-missing
Add any missing files automake requires to the directory by creating symbolic links to automake's default versions.

-c, --copy
Used with the -a option. Copy missing files instead of creating symbolic links.

--cygnus
Specifies project has a Cygnus-style source tree.

-f, --force-missing
Used with the -a option. Replace required files even if a local copy already exists.

--foreign
Treat project as a non-GNU project. Check only for elements required for proper operation.

--gnu
Treat project as a GNU project with the GNU project structure.

--gnits
A stricter version of --gnu, performing more checks to comply with GNU project structure rules.

--help
Print help message, then exit.

-i, --ignore-deps
Disable automatic dependency tracking.

--libdir=dir
Used with the -a option. Search in directory dir for default files.

--no-force
Update only Makefile.in files that have updated dependents.

-v, --verbose
List files being read or created by automake.

--version
Print version number, then exit.

-Werror
Treat warnings as errors.

autoreconf

autoreconf [options]

GNU autoconf tool. Update configure scripts by running autoconf, autoheader, aclocal, automake, and libtoolize in specified directories and subdirectories. This command is seldom invoked manually. It is usually called automatically from other autoconf tools.

Options

-d, --debug
Don't remove temporary files.

-f, --force
Remake all configure scripts, even when newer than their template files.

-h, --help
Print help message, then exit.

-i, --install
Add any default files missing from package by copying versions included with autoconf and automake.

-s, --symlink
Used with the -i option. Create symbolic links to default files instead of copying them.

-v, --verbose
Verbosely print information about the progress of autoreconf.

-I dir, --include=dir
Search in directory dir for input files.

-V, --version
Print version number, then exit.

-W category, --warnings=category
Print any warnings related to category. Accepted categories are:

cross
Cross compilation.

obsolete
Obsolete constructs.

syntax
Questionable syntax.

all
All warnings.

no-category
Turn off warnings for category.

none
Turn off all warnings.

error
Treat warnings as errors.

autoscan

autoscan [options] [directory]

GNU autoconf tool. Create or maintain a preliminary configure.ac file named configure.scan based on source files in specified directory, or current directory if none given. If a configure.ac file already exists, autoconf will check it for completeness and print suggestions for correcting any problems it finds.

Options

-d, --debug
Don't remove temporary files.

-h, --help
Print help message, then exit.

-v, --verbose
Verbosely print information about the progress of autoscan.

-I dir, --include=dir
Search in directory dir for input files. Use multiple times to add multiple directories.

-B dir, --prepend-include=dir
Search dir for input files before searching in other directories. Use multiple times to add multiple directories.

-V, --version
Print version number, then exit.

autoupdate

autoupdate [options] [file]

GNU autoconf tool. Update the configure template file file, or configure.ac if no file is specified. This command is seldom invoked manually. It is usually called automatically from other autoconf tools.

Options

-d, --debug
Don't remove temporary files.

-f, --force
Remake all configure scripts, even when newer than their template files.

-h, --help
Print help message, then exit.

-v, --verbose
Verbosely print information about the progress of autoupdate.

-I dir, --include=dir
Search in directory dir for input files.

-V, --version
Print version number, then exit.

badblocks

badblocks [options] device block-count

System administration command. Search device for bad blocks. You must specify the number of blocks on the device (block-count).

Options

-b blocksize
Expect blocksize-byte blocks.

-c blocksize
Test blocksize-byte blocks at a time. Default is 16.

-f
Force a read/write or nondestructive write test on a mounted device. Use only when /etc/mtab incorrectly reports a device as mounted.

-i file
Skip test of known bad blocks listed in file.

-n
Perform a nondestructive test by writing to each block and then reading back from it while preserving data.

-o file
Direct output to file.

-p number
Repeat search of device until no new bad blocks have been found in number passes. Default is 0.

-v
Verbose mode.

-w
Test by writing to each block and then reading back from it.

banner

banner [option] [characters]

Print characters as a poster. If no characters are supplied, banner prompts for them and reads an input line from standard input. By default, the results go to standard output, but they are intended to be sent to a printer.

Option

-w width
Set width to width characters. Note that if your banner is in all lowercase, it will be narrower than width characters. If -w is not specified, the default width is 132. If -w is specified but width is not provided, the default is 80.

Example

/usr/games/banner -w50 Happy Birthday! |lpr
basename

basename name [suffix]
basename option

Remove leading directory components from a path. If suffix is given, remove that also. The result is printed to standard output.

Options

--help
Print help message and then exit.

--version
Print the version number and then exit.

Examples

 basename /usr/lib/libm.a
libm.a

% basename /usr/lib/libm.a .a
libm
bash

bash [options] [file [arguments]]
sh [options] [file [arguments]]

Standard Linux shell, a command interpreter into which all other commands are entered. For more information, see Chapter 7.

batch

batch [options] [time]

Execute commands entered on standard input. If time is omitted, execute commands when the system load permits (when the load average falls below 0.8). Very similar to at, but does not insist that the execution time be entered on the command line. See at for details.

Options

-f file
Read job from file, not standard input.

-m
Mail user when job has completed, regardless of whether output was created.

-q letter
Place job in queue denoted by letter, where letter is one letter from a-z or A-Z. The default queue is b. (The at queue defaults to a.) Higher-lettered queues run at a lower priority.

-V
Print the version number and then exit.

-v
Display the time a job will be executed.

bc

bc [options] [files]

bc is a language (and compiler) whose syntax resembles that of C, but with unlimited-precision arithmetic. bc consists of identifiers, keywords, and symbols, which are briefly described in the following entries. Examples are given at the end.

Interactively perform arbitrary-precision arithmetic or convert numbers from one base to another. Input can be taken from files or read from the standard input. To exit, type quit or EOF.

Options

-h, --help
Print help message and exit.

-i, --interactive
Interactive mode.

-l, --mathlib
Make functions from the math library available.

-s, --standard
Ignore all extensions, and process exactly as in POSIX.

-w, --warn
When extensions to POSIX bc are used, print a warning.

-q, --quiet
Do not display welcome message.

-v, --version
Print version number.

Identifiers

An identifier is a series of one or more characters. It must begin with a lowercase letter but may also contain digits and underscores. No uppercase letters are allowed. Identifiers are used as names for variables, arrays, and functions. Variables normally store arbitrary-precision numbers. Within the same program you may name a variable, an array, and a function using the same letter. The following identifiers would not conflict:

x
Variable x.

x[i]
Element i of array x. i can range from 0 to 2047 and can also be an expression.

x(y,z)
Call function x with parameters y and z.

Input-output keywords

ibase, obase, scale, and last store a value. Typing them on a line by themselves displays their current value. You can also change their values through assignment. The letters A-F are treated as digits whose values are 10-15.

ibase = n
Numbers that are input (e.g., typed) are read as base n (default is 10).

obase = n
Numbers that are displayed are in base n (default is 10). Note: once ibase has been changed from 10, use A to restore ibase or obase to decimal.

scale = n
Display computations using n decimal places (default is 0, meaning that results are truncated to integers). scale is normally used only for base-10 computations.

last
Value of last printed number.

Statement keywords

A semicolon or a newline separates one statement from another. Curly braces are needed when grouping multiple statements.

if (rel-expr) {statements} [else {statements}]
Do one or more statements if relational expression rel-expr is true. Otherwise, do nothing, or if else (an extension) is specified, do alternative statements. For example:

if (x=  =y) {i = i + 1} else {i = i - 1}
while (rel-expr) {statements}
Repeat one or more statements while rel-expr is true; for example:

while (i>0) {p = p*n; q = a/b; i = i-1}
for (expr1; rel-expr; expr2) {statements}
Similar to while; for example, to print the first 10 multiples of 5, you could type:

for (i=1; i<=10; i++) i*5

GNU bc does not require three arguments to for. A missing argument 1 or 3 means that those expressions will never be evaluated. A missing argument 2 evaluates to the value 1.

break
Terminate a while or for statement.

print list
GNU extension. It provides an alternate means of output. list consists of a series of comma-separated strings and expressions; print displays these entities in the order of the list. It does not print a newline when it terminates. Expressions are evaluated, printed, and assigned to the special variable last. Strings (which may contain special characters, i.e., characters beginning with \) are simply printed. Special characters can be:

a
Alert or bell

b
Backspace

f
Form feed

n
Newline

r
Carriage return

q
Double quote

t
Tab

\
Backslash

continue
GNU extension. When within a for statement, jump to the next iteration.

halt
GNU extension. Cause the bc processor to quit when executed.

quit
GNU extension. Cause the bc processor to quit whether line is executed or not.

limits
GNU extension. Print the limits enforced by the local version of bc.

Function keywords

define f(args) {
Begin the definition of function f having the arguments args. The arguments are separated by commas. Statements follow on successive lines. End with }.

auto x, y
Set up x and y as variables local to a function definition, initialized to 0 and meaningless outside the function. Must appear first.

return(expr)
Pass the value of expression expr back to the program. Return 0 if (expr) is left off. Used in function definitions.

sqrt(expr)
Compute the square root of expression expr.

length(expr)
Compute how many significant digits are in expr.

scale(expr)
Same as length, but count only digits to the right of the decimal point.

read( )
GNU extension. Read a number from standard input. Return value is the number read, converted via the value of ibase.

Math library functions

These are available when bc is invoked with -l. Library functions set scale to 20.

s(angle)
Compute the sine of angle, a constant or expression in radians.

c(angle)
Compute the cosine of angle, a constant or expression in radians.

a(n)
Compute the arctangent of n, returning an angle in radians.

e(expr)
Compute e to the power of expr.

l(expr)
Compute the natural log of expr.

j(n, x)
Compute the Bessel function of integer order n.

Operators

These consist of operators and other symbols. Operators can be arithmetic, unary, assignment, or relational:

arithmetic
+ - * / % ^

unary
- ++ --

assignment
=+ =- =* =/ =% =^ =

relational
< <= > >= = = !=

Other symbols

/* */
Enclose comments.

( )
Control the evaluation of expressions (change precedence). Can also be used around assignment statements to force the result to print.

{ }
Use to group statements.

[ ]
Indicate array index.

"text"
Use as a statement to print text.

Examples

Note in these examples that when you type some quantity (a number or expression), it is evaluated and printed, but assignment statements produce no display.

ibase = 8       Octal input
20              Evaluate this octal number
16              Terminal displays decimal value
obase = 2       Display output in base 2 instead of base 10
20              Octal input
10000           Terminal now displays binary value
ibase = A       Restore base-10 input
scale = 3       Truncate results to 3 decimal places
8/7             Evaluate a division
1.001001000     Oops!  Forgot to reset output base to 10
obase=10        Input is decimal now, so A isn't needed
8/7
1.142           Terminal displays result (truncated)

The following lines show the use of functions:

define p(r,n){  Function p uses two arguments
auto v          v is a local variable
v = r^n         r raised to the n power
return(v)}      Value returned

scale=5
x=p(2.5,2)      x = 2.5 ^ 2
x               Print value of x
6.25
length(x)       Number of digits
3
scale(x)        Number of places right of decimal point
2
biff

biff [arguments]

Notify user of mail arrival and sender's name. biff operates asynchronously. Mail notification works only if your system is running the comsat(8) server. The command biff y enables notification, and the command biff n disables notification. With no arguments, biff reports biff's current status.

bison

bison [options] file

Given a file containing context-free grammar, convert into tables for subsequent parsing while sending output to file.c. This utility is to a large extent compatible with yacc, and in fact is named for it. All input files should use the suffix .y; output files will use the original prefix. All long options (those preceded by --) may instead be preceded by +.

Options

-b prefix, --file-prefix=prefix
Use prefix for all output files.

-d, --defines
Generate file.h, producing #define statements that relate bison's token codes to the token names declared by the user.

-r, --raw
Use bison token numbers, not yacc-compatible translations, in file.h.

-k, --token-table
Include token names and values of YYNTOKENS, YYNNTS, YYNRULES, and YYNSTATES in file.c.

-l, --no-lines
Exclude #line constructs from code produced in file.c. (Use after debugging is complete.)

-n, --no-parser
Suppress parser code in output, allowing only declarations. Assemble all translations into a switch statement body and print it to file.act.

-o file, --output-file=file
Output to file.

-p prefix, --name-prefix=prefix
Substitute prefix for yy in all external symbols.

-t, --debug
Compile runtime debugging code.

-v, --verbose
Verbose mode. Print diagnostics and notes about parsing tables to file.output.

-V, --version
Display version number.

-y, --yacc, --fixed-output-files
Duplicate yacc's conventions for naming output files.

bootpd

bootpd [options] [configfile [dumpfile]]

TCP/IP command. Internet Boot Protocol server. bootpd normally is run by /etc/inetd by including the following line in the file /etc/inetd.conf:

bootps dgram udp wait root /etc/bootpd bootpd

This causes bootpd to be started only when a boot request arrives. It may also be started in standalone mode, from the command line. Upon startup, bootpd first reads its configuration file, /etc/bootptab (or the configfile listed on the command line), then begins listening for BOOTREQUEST packets.

bootpd looks in /etc/services to find the port numbers it should use. Two entries are extracted: bootps (the bootp server listening port) and bootpc (the destination port used to reply to clients).

If bootpd is compiled with the -DDEBUG option, receipt of a SIGUSR1 signal causes it to dump its memory-resident database to the file /etc/bootpd.dump or the dumpfile specified on the command line.

Options

-c directory
Force bootpd to work in directory.

-d level
Specify the debugging level. Omitting level will increment the level by 1.

-t timeout
Specify a timeout value in minutes. A timeout value of 0 means wait forever.

Configuration file

The bootpd configuration file has a format in which two-character, case-sensitive tag symbols are used to represent host parameters. These parameter declarations are separated by colons. The general format is:

hostname:tg=value:tg=value:tg=value

where hostname is the name of a bootp client and tg is a tag symbol. The currently recognized tags are listed in the following section.

Tags

Tag

Meaning

bf

Bootfile

bs

Bootfile size in 512-octet blocks

cs

Cookie server address list

ds

Domain name server address list

gw

Gateway address list

ha

Host hardware address

hd

Bootfile home directory

hn

Send hostname

ht

Host hardware type (see Assigned Numbers RFC)

im

Impress server address list

ip

Host IP address

lg

Log server address list

lp

lpr server address list

ns

IEN-116 name server address list

rl

Resource location protocol server address list

sm

Host subnet mask

tc

Table continuation

to

Time offset in seconds from UTC

ts

Time server address list

vm

Vendor magic cookie selector

There is also a generic tag, Tn, where n is an RFC 1048 vendor field tag number. Generic data may be represented as either a stream of hexadecimal numbers or as a quoted string of ASCII characters.

bootpgw

bootpgw [options] server

TCP/IP command. Internet Boot Protocol Gateway. Maintain a gateway that forwards bootpd requests to server. In addition to dealing with BOOTREPLY packets, also deal with BOOTREQUEST packets. bootpgw is normally run by /etc/inetd by including the following line in the file /etc/inetd.conf:

bootps dgram udp wait root /etc/bootpgw bootpgw

This causes bootpgw to be started only when a boot request arrives. bootpgw takes all the same options as bootpd, except -c.

bootptest

bootptest [options] server [template]

TCP/IP command. Test server's bootpd daemon by sending requests every second for 10 seconds or until the server responds. Read options from the template file, if provided.

Options

-f file
Read the boot filename from file.

-h
Identify client by hardware address, not IP address.

-m magic-number
Provide magic-number as the first word of the vendor options field.

bzcmp

bzcmp [options] file1 file2

Apply cmp to the data from files in the bzip2 format without requiring on-disk decompression. See bzip2 and cmp for usage.

bzdiff

bzdiff [options] file1 file2

Apply diff to data from files in the bzip2 format without requiring on-disk decompression. See bzip2 and cmp for usage.

bzgrep

bzgrep [options] pattern [file...]

Apply grep to data from files in the bzip2 format without requiring on-disk decompression. See bzip2 and grep for usage.

bzip2

bzip2 [options] filenames
bunzip2 [options] filenames
bzcat [option] filenames
bzip2recover filenames

File compression and decompression utility similar to gzip, but uses a different algorithm and encoding method to get better compression. bzip2 replaces each file in filenames with a compressed version of the file and with a .bz2 extension appended. bunzip2 decompresses each file compressed by bzip2 (ignoring other files, except to print a warning). bzcat decompresses all specified files to standard output, and bzip2recover is used to try to recover data from damaged files.

Additional related commands include bzcmp, which compares the contents of bzipped files; bzdiff, which creates diff (difference) files from a pair of bzip files; bzgrep, to search them; and the bzless and bzmore commands, which apply the more and less commands to bzip output as bzcat does with the cat command. See cat, cmp, diff, and grep for information on how to use those commands.

Options

--
End of options; treat all subsequent arguments as filenames.

-dig
Set block size to dig × 100KB when compressing, where dig is a single digit from 1 to 9.

-c, --stdout
Compress or decompress to standard output.

-d, --decompress
Force decompression.

-f, --force
Force overwrite of output files. Default is not to overwrite. Also forces breaking of hard links to files.

-k, --keep
Keep input files; don't delete them.

-L, --license, -V, --version
Print license and version information and exit.

-q, --quiet
Print only critical messages.

-s, --small
Use less memory, at the expense of speed.

-t, --test
Check the integrity of the files, but don't actually compress them.

-v, --verbose
Verbose mode. Show the compression ratio for each file processed. Add more -v's to increase the verbosity.

-z, --compress
Force compression, even if invoked as bunzip2 or bzcat.

--repetitive-fast, --repetitive-best
Sometimes useful in versions earlier than 0.9.5 (which has an improved sorting algorithm) for providing some control over the algorithm.

bzless

bzless [options] file

Applies less to data files in the bzip2 format without requiring on-disk decompression. See bzip2 and less for usage.

bzmore

bzmore [options] file

Applies more to data files in the bzip2 format without requiring on-disk decompression. See bzip2 and more for usage.

c++

c++ [options] files

See g++.

c++filt

c++filt [options] [symbol]

Decode the specified C++ or Java function name symbol, or read and decode symbols from standard input if no symbol is given. This command reverses the name mangling used by C++ and Java compilers to support function overloading, multiple functions that share the same name.

Options

-_, --strip-underscores
Remove initial underscores from symbol names.

--help
Print usage information, then exit.

-j, --java
Print names using Java syntax.

-n, --no-strip-underscores
Preserve initial underscores on symbol names.

-s format, --format=format
Expect symbols to have been coded in the specified format. Format may be one of the following:

arm
C++ Annotated Reference Manual.

edg
EDG (Intel) compiler.

gnu
Gnu compiler (the default).

gnu-new-abi
Gnu compiler with the new application binary interface (for gcc 3.x.)

hp
HP compiler.

lucid
Lucid compiler.

--version
Print version number, then exit.

cal

cal [options] [[month] year]

Print a 12-month calendar (beginning with January) for the given year, or a one-month calendar of the given month and year. month ranges from 1 to 12. year ranges from 1 to 9999. With no arguments, print a calendar for the current month.

Options

-j
Display Julian dates (days numbered 1 to 365, starting from January 1).

-m
Display Monday as the first day of the week.

-y
Display entire year.

Examples

cal 12 1995
cal 1994 > year_file
cardctl

cardctl [options] command

System administration command. Control PCMCIA sockets or select the current scheme. The current scheme is sent along with the address of any inserted cards to configuration scripts (by default located in /etc/pcmcia). The scheme command displays or changes the scheme. The other commands operate on a named card socket number, or all sockets if no number is given.

Commands

config [socket]
Display current socket configuration.

eject [socket]
Prepare the system for the card(s) to be ejected.

ident [socket]
Display card identification information.

insert [socket]
Notify system that a card has been inserted.

reset [socket]
Send reset signal to card.

resume [socket]
Restore power to socket and reconfigure for use.

scheme [name]
Display current scheme or change to specified scheme name.

status [socket]
Display current socket status.

suspend [socket]
Shut down device and cut power to socket.

Options

-c directory
Look for card configuration information in directory instead of /etc/pcmcia.

-f file
Use file to keep track of the current scheme instead of /var/run/pcmcia-scheme.

-s file
Look for current socket information in file instead of /var/run/stab.

cardmgr

cardmgr [options]

System administration command. The PCMCIA card daemon. cardmgr monitors PCMCIA sockets for devices that have been added or removed. When a card is detected, it attempts to get the card's ID and configure it according to the card configuration database (usually stored in /etc/pcmcia/config). By default, cardmgr does two things when it detects a card: it creates a system log entry and it beeps. Two high beeps mean it successfully identified and configured a device. One high beep followed by one low beep means it identified the device, but was unable to configure it successfully. One low beep means it could not identify the inserted card. Information on the currently configured cards can be found in /var/run/stab.

Options

-c directory
Look for the card configuration database in directory instead of /etc/pcmcia.

-d
Use modprobe instead of insmod to load the PCMCIA device driver.

-f
Run in the foreground to process the current cards, then run as a daemon.

-m directory
Look in directory for card device modules. Default is /lib/modules/RELEASE, where RELEASE is the current kernel release.

-o
Configure the cards present in one pass, then exit.

-pfile
Write cardmgr's process ID to file instead of /var/run/cardmgr.pid.

-q
Run in quiet mode. No beeps.

-s file
Write current socket information to file instead of /var/run/stab.

-v
Verbose mode.

-V
Print version number and exit.

cat

cat [options] [files]

Read (concatenate) one or more files and print them on standard output. Read standard input if no files are specified or if - is specified as one of the files; input ends with EOF. You can use the > operator to combine several files into a new file or >> to append files to an existing file.

Options

-A, --show-all
Same as -vET.

-b, --number-nonblank
Number all nonblank output lines, starting with 1.

-e
Same as -vE.

-E, --show-ends
Print $ at the end of each line.

-n, --number
Number all output lines, starting with 1.

-s, --squeeze-blank
Squeeze down multiple blank lines to one blank line.

-t
Same as -vT.

-T, --show-tabs
Print TAB characters as ^I.

-u
Ignored; retained for Unix compatibility.

-v, --show-nonprinting
Display control and nonprinting characters, with the exception of LINEFEED and TAB.

Examples

cat ch1               Display a file
cat ch1 ch2 ch3 > all Combine files
cat note5 >> notes    Append to a file
cat > temp1           Create file at terminal; end with EOF
cat > temp2 << STOP   Create file at terminal; end with STOP
cc

cc [options] files

See gcc.

cdda2wav

cdda2wav [options] [output.wav]

Convert Compact Disc Digital Audio (CDDA) to the WAV format. This process is often called "ripping" a CD-ROM, and is generally performed before using an encoder to convert the file to a compressed music format such as OGG or MP3. By default, cdda2wav reads data from the /dev/cdrom device and outputs one WAV file per track.

Options

Some of the following op