Skip to content
Built-in Commands

Built-in Commands

The aesh-builtins module provides ready-to-use POSIX-like command implementations for common shell operations. Instead of building basic commands from scratch, you can register these pre-built, tested commands in your CLI application.

Installation

Maven

<dependency>
    <groupId>org.aesh</groupId>
    <artifactId>aesh-builtins</artifactId>
    <version>3.17.5</version>
</dependency>

Gradle

implementation 'org.aesh:aesh-builtins:3.17.5'

Available Commands

File System Commands

CommandClassDescription
catorg.aesh.builtins.cat.CatDisplay file contents
cdorg.aesh.builtins.cd.CdChange working directory
lsorg.aesh.builtins.ls.LsList directory contents with colors
mkdirorg.aesh.builtins.mkdir.MkdirCreate directories
mvorg.aesh.builtins.mv.MvMove or rename files
rmorg.aesh.builtins.rm.RmRemove files and directories
touchorg.aesh.builtins.touch.TouchCreate files or update timestamps
pwdorg.aesh.builtins.pwd.PwdPrint working directory
pushdorg.aesh.builtins.pushd.PushdPush directory onto stack
popdorg.aesh.builtins.pushd.PopdPop directory from stack

Text Processing

CommandClassDescription
greporg.aesh.builtins.grep.GrepSearch text with regex, colored output
echoorg.aesh.builtins.echo.EchoPrint text to output

Display

CommandClassDescription
lessorg.aesh.builtins.less.LessFile viewer with paging, search
clearorg.aesh.builtins.clear.ClearClear terminal screen

Usage

Register the commands you need in your application:

import org.aesh.AeshConsoleRunner;
import org.aesh.builtins.cat.Cat;
import org.aesh.builtins.cd.Cd;
import org.aesh.builtins.clear.Clear;
import org.aesh.builtins.echo.Echo;
import org.aesh.builtins.grep.Grep;
import org.aesh.builtins.less.Less;
import org.aesh.builtins.ls.Ls;
import org.aesh.builtins.mkdir.Mkdir;
import org.aesh.builtins.pwd.Pwd;
import org.aesh.builtins.rm.Rm;

public class MyShell {
    public static void main(String[] args) {
        AeshConsoleRunner.builder()
                .command(Cat.class)
                .command(Cd.class)
                .command(Clear.class)
                .command(Echo.class)
                .command(Grep.class)
                .command(Less.class)
                .command(Ls.class)
                .command(Mkdir.class)
                .command(Pwd.class)
                .command(Rm.class)
                // Add your own commands here
                .command(MyCommand.class)
                .addExitCommand()
                .prompt("[myshell]$ ")
                .start();
    }
}

You can register all of them or just the ones your application needs.

Command Details

cat

Display one or more file contents:

[myshell]$ cat file1.txt file2.txt

grep

Search for patterns in piped input or (when piped) standard input:

[myshell]$ grep -i "error" /var/log/app.log
[myshell]$ cat file.txt | grep pattern

Options: -i (case insensitive), -c (count matches), -l (list filenames), -n (line numbers), -e (pattern).

less

View files with paging, search, and navigation:

[myshell]$ less large-file.txt

Key bindings:

  • Space / PgDn: Page down
  • b / PgUp: Page up
  • Enter / Down: Line down
  • Up: Line up
  • /pattern: Search forward
  • n / N: Next / previous match
  • g / G: Go to start / end
  • h: Help
  • q: Quit

Less also reads from piped input:

[myshell]$ cat file.txt | less

ls

List directory contents with color-coded file types:

[myshell]$ ls
[myshell]$ ls -la /tmp

pushd / popd

Directory stack for quick navigation:

[myshell]$ pushd /tmp
[myshell]$ pushd /var/log
[myshell]$ popd           # returns to /tmp
[myshell]$ popd           # returns to original directory

Legacy Extensions

The aesh-extensions repository contains additional commands that have not been moved to aesh-builtins, including matrix (terminal animation) and harlem (audio demo). These require the legacy aesh-extensions artifact:

<dependency>
    <groupId>org.aesh</groupId>
    <artifactId>aesh-extensions</artifactId>
    <version>1.8</version>
</dependency>