Search documentation of stdlib

# View Source c (stdlib v6.2)

Command line interface module.

This module enables users to enter the short form of some commonly used commands.

> #### Note

> These functions are intended for interactive use in the Erlang shell only. The module prefix can be omitted.

## See Also

`filename`, `compile`, `erlang`, `yecc`, `xref`

# Summary

## Types

cmd_line_arg()
h_return()
hcb_return()
hf_return()
ht_return()

## Functions

bt(Pid)

Stack backtrace for a process. Equivalent to `erlang:process_display(Pid, backtrace)`.

c(Module)

Works like `c(Module, [])`.

c(Module, Options)

Compiles and then purges and loads the code for a module. `Module` can be either a module name or a source file path, with or without `.erl` extension.

c(Module, Options, Filter)

Compiles and then purges and loads the code for module `Module`, which must be an atom.

cd(Dir)

Changes working directory to `Dir`, which can be a relative name, and then prints the name of the new working directory.

erlangrc(PathList)

Search `PathList` and load `.erlang` resource file if found.

flush()

Flushes any messages sent to the shell.

h(Module)

Print the documentation for `Module`

h(Module, Function)

Print the documentation for all `Module:Function`s (regardless of arity).

h(Module, Function, Arity)

Print the documentation for `Module:Function/Arity`.

hcb(Module)

Print the callback documentation for `Module`

hcb(Module, Callback)

Print the callback documentation for all `Module:Callback`s (regardless of arity).

hcb(Module, Callback, Arity)

Print the callback documentation for `Module:Callback/Arity`.

help()

Displays help information: all valid shell internal commands, and commands in this module.

ht(Module)

Print the type documentation for `Module`

ht(Module, Type)

Print the type documentation for `Type` in `Module` regardless of arity.

ht(Module, Type, Arity)

Print the type documentation for `Type/Arity` in `Module`.

i()

Equivalent to `ni/0`.

i(X, Y, Z)

Displays information about a process, Equivalent to `process_info(pid(X, Y, Z))`, but location transparent.

l(Module)

Purges and loads, or reloads, a module by calling `code:purge(Module)` followed by `code:load_file(Module)`.

lc(Files)

Compiles a list of files by calling `compile:file(File, [report_errors, report_warnings])` for each `File` in `Files`.

lm()

Reloads all currently loaded modules that have changed on disk (see `mm/0`). Returns the list of results from calling `l(M)` for each such `M`.

ls()

Lists files in the current directory.

ls(Dir)

Lists files in directory `Dir` or, if `Dir` is a file, only lists it.

m()

Displays information about the loaded modules, including the files from which they have been loaded.

m(Module)

Displays information about `Module`.

memory()

Memory allocation information. Equivalent to `erlang:memory/0`.

memory(TypeSpec)

Memory allocation information. Equivalent to `erlang:memory/1`.

mm()

Lists all modified modules. Shorthand for `code:modified_modules/0`.

nc(File)

Equivalent to `nc/2`.

nc(File, Options)

Compiles and then loads the code for a file on all nodes. `Options` defaults to `[]`. Compilation is equivalent to

ni()

`i/0` displays system information, listing information about all processes. `ni/0` does the same, but for all nodes in the network.

nl(Module)

Loads `Module` on all nodes.

nregs()

Equivalent to `regs/0`.

pid(X, Y, Z)

Converts `X`, `Y`, `Z` to pid `<X.Y.Z>`. This function is only to be used when debugging.

pwd()

Prints the name of the working directory.

q()

This function is shorthand for `init:stop()`, that is, it causes the node to stop in a controlled fashion.

regs()

`regs/0` displays information about all registered processes. `nregs/0` does the same, but for all nodes in the network.

uptime()

Prints the node uptime (as specified by `erlang:statistics(wall_clock)`) in human-readable form.

xm(ModSpec)

Finds undefined functions, unused functions, and calls to deprecated functions in a module by calling `xref:m/1`.

y(File)

Generates an LALR-1 parser. Equivalent to

y(File, Options)

Generates an LALR-1 parser. Equivalent to

# Types

Link to this type

# cmd_line_arg()

View Source (not exported)

    -type cmd_line_arg() :: atom() | string().

Link to this type

# h_return()

View Source (not exported)

    -type h_return() :: ok | {error, missing | {unknown_format, unicode:chardata()}}.

Link to this type

# hcb_return()

View Source (not exported)

    -type hcb_return() :: h_return() | {error, callback_missing}.

Link to this type

# hf_return()

View Source (not exported)

    -type hf_return() :: h_return() | {error, function_missing}.

Link to this type

# ht_return()

View Source (not exported)

    -type ht_return() :: h_return() | {error, type_missing}.

# Functions

Link to this function

# bt(Pid)

View Source

    -spec bt(Pid) -> ok | undefined when Pid :: pid().

Stack backtrace for a process. Equivalent to `erlang:process_display(Pid, backtrace)`.

Link to this function

# c(Module)

View Source

    -spec c(Module) -> {ok, ModuleName} | error when Module :: file:name(), ModuleName :: module().

Works like `c(Module, [])`.

Link to this function

# c(Module, Options)

View Source

    -spec c(Module, Options) -> {ok, ModuleName} | error
               when
                   Module :: file:name(),
                   Options :: [compile:option()] | compile:option(),
                   ModuleName :: module().

Compiles and then purges and loads the code for a module. `Module` can be either a module name or a source file path, with or without `.erl` extension.

If `Module` is a string, it is assumed to be a source file path, and the compiler will attempt to compile the source file with the options `Options`. If compilation fails, the old object file (if any) is deleted.

If `Module` is an atom, a source file with that exact name or with `.erl` extension will be looked for. If found, the source file is compiled with the options `Options`. If compilation fails, the old object file (if any) is deleted.

If `Module` is an atom and is not the path of a source file, then the code path is searched to locate the object file for the module and extract its original compiler options and source path. If the source file is not found in the original location, `filelib:find_source/1` is used to search for it relative to the directory of the object file.

The source file is compiled with the the original options appended to the given `Options`, the output replacing the old object file if and only if compilation succeeds.

Notice that purging the code means that any processes lingering in old code for the module are killed without warning. For more information, see the `code` module.

Link to this function

# c(Module, Options, Filter)

View Source (since OTP 20.0)

    -spec c(Module, Options, Filter) -> {ok, ModuleName} | error
               when
                   Module :: atom(),
                   Options :: [compile:option()],
                   Filter :: fun((compile:option()) -> boolean()),
                   ModuleName :: module().

Compiles and then purges and loads the code for module `Module`, which must be an atom.

The code path is searched to locate the object file for module `Module` and extract its original compiler options and source path. If the source file is not found in the original location, `filelib:find_source/1` is used to search for it relative to the directory of the object file.

The source file is compiled with the the original options appended to the given `Options`, the output replacing the old object file if and only if compilation succeeds. The function `Filter` specifies which elements to remove from the original compiler options before the new options are added. The `Filter` fun should return `true` for options to keep, and `false` for options to remove.

Notice that purging the code means that any processes lingering in old code for the module are killed without warning. For more information, see the `code` module.

Link to this function

# cd(Dir)

View Source

    -spec cd(Dir) -> ok when Dir :: file:name().

Changes working directory to `Dir`, which can be a relative name, and then prints the name of the new working directory.

Example:

    2> cd("../erlang").
    /home/ron/erlang

Link to this function

# erlangrc(PathList)

View Source (since OTP 21.0)

    -spec erlangrc(PathList) -> {ok, file:filename()} | {error, term()}
                      when PathList :: [Dir :: file:name()].

Search `PathList` and load `.erlang` resource file if found.

Link to this function

# flush()

View Source

    -spec flush() -> ok.

Flushes any messages sent to the shell.

Link to this function

# h(Module)

View Source (since OTP 23.0)

    -spec h(module()) -> h_return().

Print the documentation for `Module`

Link to this function

# h(Module, Function)

View Source (since OTP 23.0)

    -spec h(module(), function()) -> hf_return().

Print the documentation for all `Module:Function`s (regardless of arity).

Link to this function

# h(Module, Function, Arity)

View Source (since OTP 23.0)

    -spec h(module(), function(), arity()) -> hf_return().

Print the documentation for `Module:Function/Arity`.

Link to this function

# hcb(Module)

View Source (since OTP 23.0)

    -spec hcb(module()) -> h_return().

Print the callback documentation for `Module`

Link to this function

# hcb(Module, Callback)

View Source (since OTP 23.0)

    -spec hcb(module(), Callback :: atom()) -> hcb_return().

Print the callback documentation for all `Module:Callback`s (regardless of arity).

Link to this function

# hcb(Module, Callback, Arity)

View Source (since OTP 23.0)

    -spec hcb(module(), Callback :: atom(), arity()) -> hcb_return().

Print the callback documentation for `Module:Callback/Arity`.

Link to this function

# help()

View Source

    -spec help() -> ok.

Displays help information: all valid shell internal commands, and commands in this module.

Link to this function

# ht(Module)

View Source (since OTP 23.0)

    -spec ht(module()) -> h_return().

Print the type documentation for `Module`

Link to this function

# ht(Module, Type)

View Source (since OTP 23.0)

    -spec ht(module(), Type :: atom()) -> ht_return().

Print the type documentation for `Type` in `Module` regardless of arity.

Link to this function

# ht(Module, Type, Arity)

View Source (since OTP 23.0)

    -spec ht(module(), Type :: atom(), arity()) -> ht_return().

Print the type documentation for `Type/Arity` in `Module`.

Link to this function

# i()

View Source

    -spec i() -> ok.

Equivalent to `ni/0`.

Link to this function

# i(X, Y, Z)

View Source

    -spec i(X, Y, Z) -> [{atom(), term()}]
               when X :: non_neg_integer(), Y :: non_neg_integer(), Z :: non_neg_integer().

Displays information about a process, Equivalent to `process_info(pid(X, Y, Z))`, but location transparent.

Link to this function

# l(Module)

View Source

    -spec l(Module) -> code:load_ret() when Module :: module().

Purges and loads, or reloads, a module by calling `code:purge(Module)` followed by `code:load_file(Module)`.

Notice that purging the code means that any processes lingering in old code for the module are killed without warning. For more information, see `code/3`.

Link to this function

# lc(Files)

View Source

    -spec lc(Files) -> ok | error when Files :: [File :: cmd_line_arg()].

Compiles a list of files by calling `compile:file(File, [report_errors, report_warnings])` for each `File` in `Files`.

For information about `File`, see `file:filename/0`.

Link to this function

# lm()

View Source (since OTP 20.0)

    -spec lm() -> [code:load_ret()].

Reloads all currently loaded modules that have changed on disk (see `mm/0`). Returns the list of results from calling `l(M)` for each such `M`.

Link to this function

# ls()

View Source

    -spec ls() -> ok.

Lists files in the current directory.

Link to this function

# ls(Dir)

View Source

    -spec ls(Dir) -> ok when Dir :: file:name().

Lists files in directory `Dir` or, if `Dir` is a file, only lists it.

Link to this function

# m()

View Source

    -spec m() -> ok.

Displays information about the loaded modules, including the files from which they have been loaded.

Link to this function

# m(Module)

View Source

    -spec m(Module) -> ok when Module :: module().

Displays information about `Module`.

Link to this function

# memory()

View Source

    -spec memory() -> [{Type, Size}] when Type :: atom(), Size :: non_neg_integer().

Memory allocation information. Equivalent to `erlang:memory/0`.

Link to this function

# memory(TypeSpec)

View Source

    -spec memory(Type) -> Size when Type :: atom(), Size :: non_neg_integer();
                (Types) -> [{Type, Size}] when Types :: [Type], Type :: atom(), Size :: non_neg_integer().

Memory allocation information. Equivalent to `erlang:memory/1`.

Link to this function

# mm()

View Source (since OTP 20.0)

    -spec mm() -> [module()].

Lists all modified modules. Shorthand for `code:modified_modules/0`.

Link to this function

# nc(File)

View Source

    -spec nc(File) -> {ok, Module} | error when File :: file:name(), Module :: module().

Equivalent to `nc/2`.

Link to this function

# nc(File, Options)

View Source

    -spec nc(File, Options) -> {ok, Module} | error
                when
                    File :: file:name(),
                    Options :: [Option] | Option,
                    Option :: compile:option(),
                    Module :: module().

Compiles and then loads the code for a file on all nodes. `Options` defaults to `[]`. Compilation is equivalent to:

    compile:file(File, Options ++ [report_errors, report_warnings])

Link to this function

# ni()

View Source

    -spec ni() -> ok.

`i/0` displays system information, listing information about all processes. `ni/0` does the same, but for all nodes in the network.

Link to this function

# nl(Module)

View Source

    -spec nl(Module) -> abcast | error when Module :: module().

Loads `Module` on all nodes.

Link to this function

# nregs()

View Source

    -spec nregs() -> ok.

Equivalent to `regs/0`.

Link to this function

# pid(X, Y, Z)

View Source

    -spec pid(X, Y, Z) -> pid() when X :: non_neg_integer(), Y :: non_neg_integer(), Z :: non_neg_integer().

Converts `X`, `Y`, `Z` to pid `<X.Y.Z>`. This function is only to be used when debugging.

Link to this function

# pwd()

View Source

    -spec pwd() -> ok.

Prints the name of the working directory.

Link to this function

# q()

View Source

    -spec q() -> no_return().

This function is shorthand for `init:stop()`, that is, it causes the node to stop in a controlled fashion.

Link to this function

# regs()

View Source

    -spec regs() -> ok.

`regs/0` displays information about all registered processes. `nregs/0` does the same, but for all nodes in the network.

Link to this function

# uptime()

View Source (since OTP 18.0)

    -spec uptime() -> ok.

Prints the node uptime (as specified by `erlang:statistics(wall_clock)`) in human-readable form.

Link to this function

# xm(ModSpec)

View Source

    -spec xm(module() | file:filename()) -> XRefMRet :: term().

Finds undefined functions, unused functions, and calls to deprecated functions in a module by calling `xref:m/1`.

Link to this function

# y(File)

View Source

    -spec y(file:name()) -> YeccFileRet :: term().

Generates an LALR-1 parser. Equivalent to:

    yecc:file(File)

For information about `File = name()`, see `filename`. For information about `YeccRet`, see `yecc:file/2`.

Link to this function

# y(File, Options)

View Source

    -spec y(file:name(), [yecc:option()]) -> YeccFileRet :: yecc:yecc_ret().

Generates an LALR-1 parser. Equivalent to:

    yecc:file(File, Options)

For information about `File = name()`, see `filename`. For information about `Options` and `YeccRet`, see `yecc:file/2`.