or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

file-operations.mdindex.mdlogic-math.mdmisc-utilities.mdpath-utilities.mdsystem-utilities.mdtext-processing.md
tile.json

misc-utilities.mddocs/

Miscellaneous Utilities

Additional utility programs for various specialized tasks including process control, file searching, data processing, and output management. These utilities provide essential functionality for system administration and data manipulation tasks.

Capabilities

Process Control

Control timing and execution flow.

/**
 * Delay execution for specified time
 * WebAssembly binary: dist/wasm/bin/sleep
 * 
 * Usage patterns:
 * - sleep number[suffix]
 * - Suffixes: s (seconds), m (minutes), h (hours), d (days)
 * - Default unit is seconds
 * - Pauses execution for the specified duration
 */

Temporary File Creation

Create temporary files and directories securely.

/**
 * Create temporary files and directories
 * WebAssembly binary: dist/wasm/bin/mktemp
 * 
 * Usage patterns:
 * - mktemp [options] [template]
 * - Supports -d (directory), -p (directory prefix), -t (template)
 * - Creates secure temporary files with unique names
 * - Default template: tmp.XXXXXXXXXX
 */

Command Execution

Execute commands with arguments from standard input.

/**
 * Execute commands with arguments from input
 * WebAssembly binary: dist/wasm/bin/xargs
 * 
 * Usage patterns:
 * - xargs [options] [command [initial-arguments]]
 * - Supports -n (max args), -I (replace string), -0 (null delimiter)
 * - Builds command lines from standard input
 * - Handles argument limits and parallel execution
 */

Continuous Output

Generate continuous output streams.

/**
 * Repeatedly output strings
 * WebAssembly binary: dist/wasm/bin/yes
 * 
 * Usage patterns:
 * - yes [string]
 * - Default outputs "y" repeatedly
 * - Outputs specified string infinitely until terminated
 * - Useful for automating interactive prompts
 */

File Printing

Format files for printing with pagination and headers.

/**
 * Format files for printing
 * WebAssembly binary: dist/wasm/bin/pr
 * 
 * Usage patterns:
 * - pr [options] [file...]
 * - Supports -n (line numbers), -h (header), -l (page length)
 * - Creates paginated output with headers and page breaks
 * - Multiple column formatting options
 */

Output Duplication

Write output to multiple destinations simultaneously.

/**
 * Write output to multiple destinations
 * WebAssembly binary: dist/wasm/bin/tee
 * 
 * Usage patterns:
 * - tee [options] [file...]
 * - Supports -a (append), -i (ignore interrupts)
 * - Copies input to both stdout and specified files
 * - Essential for logging and debugging pipelines
 */

File System Search

Search for files and directories with complex criteria.

/**
 * Search for files and directories
 * WebAssembly binary: dist/wasm/bin/find
 * 
 * Usage patterns:
 * - find [path...] [expression]
 * - Supports -name, -type, -size, -mtime, -exec actions
 * - Complex search expressions with logical operators
 * - Powerful file system traversal and filtering
 */

Topological Sorting

Perform topological sort on input data.

/**
 * Topological sort of input
 * WebAssembly binary: dist/wasm/bin/tsort
 * 
 * Usage patterns:
 * - tsort [file]
 * - Reads pairs of items and outputs topological ordering
 * - Useful for dependency resolution and ordering
 * - Detects cycles in dependency graphs
 */

Usage Examples

Process timing and control:

const { path } = require("@cowasm/coreutils");
const { join } = require("path");

// Access miscellaneous utility binaries
const binPath = join(path, "bin");
const sleepBinary = join(binPath, "sleep");
const mktempBinary = join(binPath, "mktemp");
const xargsBinary = join(binPath, "xargs");

// These would be executed via your WebAssembly runtime

Sleep and timing:

# Basic delays
sleep 5                      # Sleep for 5 seconds
sleep 2m                     # Sleep for 2 minutes
sleep 1h                     # Sleep for 1 hour
sleep 0.5                    # Sleep for half a second

# In scripts
echo "Starting process..."
sleep 3
echo "Process started"

Temporary file management:

# Create temporary file
temp_file=$(mktemp)
echo "Temporary file: $temp_file"

# Create temporary directory
temp_dir=$(mktemp -d)
echo "Temporary directory: $temp_dir"

# Custom template
temp_file=$(mktemp /tmp/myapp.XXXXXX)

# Secure temporary file in specific directory
temp_file=$(mktemp -p /var/tmp mydata.XXXXXX)

Command execution with xargs:

# Basic usage
echo "file1 file2 file3" | xargs ls -l

# Process files one by one
find . -name "*.txt" | xargs -n 1 wc -l

# Replace string pattern
find . -name "*.bak" | xargs -I {} mv {} /backup/

# Handle filenames with spaces (null delimiter)
find . -name "*.txt" -print0 | xargs -0 grep "pattern"

# Parallel execution
find . -name "*.jpg" | xargs -P 4 -I {} convert {} {}.thumbnail.jpg

Continuous output:

# Default "y" output
yes | head -5                # Outputs: y y y y y

# Custom string
yes "hello" | head -3        # Outputs: hello hello hello

# Automate interactive commands
yes | apt-get upgrade        # Automatically answer "yes" to prompts
yes n | rm -i *.tmp         # Automatically answer "no" to prompts

Output duplication with tee:

# Save output to file and display
command | tee output.log

# Append to file
command | tee -a logfile.txt

# Multiple files
command | tee file1.txt file2.txt

# Complex pipelines
command | tee intermediate.log | process | tee final.log

File searching with find:

# Basic searches
find . -name "*.txt"         # Find all .txt files
find /path -type d           # Find all directories
find . -size +100M           # Find files larger than 100MB

# Time-based searches
find . -mtime -7             # Modified in last 7 days
find . -atime +30            # Accessed more than 30 days ago

# Execute commands on results
find . -name "*.log" -exec rm {} \;
find . -type f -exec chmod 644 {} \;

# Complex expressions
find . \( -name "*.jpg" -o -name "*.png" \) -and -size +1M

File formatting with pr:

# Basic formatting
pr filename.txt              # Add page headers and numbers

# Custom headers
pr -h "My Document" file.txt

# Line numbering
pr -n file.txt

# Multiple columns
pr -2 file.txt               # Two-column format

# Custom page length
pr -l 60 file.txt            # 60 lines per page

Topological sorting:

# Dependency sorting
echo -e "a b\nb c\nc d" | tsort    # Returns: a b c d

# Build order resolution
cat dependencies.txt | tsort       # Resolves build dependencies

# Cycle detection
echo -e "a b\nb c\nc a" | tsort    # Detects circular dependency

Advanced Usage Patterns

Batch Processing

# Process all files in parallel
find . -name "*.data" | xargs -P $(nproc) -I {} process_file.sh {}

# Create batch temporary files
for i in $(seq 1 10); do
    temp_file=$(mktemp /tmp/batch.$i.XXXXXX)
    echo "Processing batch $i in $temp_file"
done

Logging and Debugging

# Log all output while processing
complex_command 2>&1 | tee full.log | grep ERROR | tee errors.log

# Time-stamped logging
while true; do
    date
    system_status_command
    sleep 60
done | tee -a system.log

Automated Testing

# Automated test responses
test_command() {
    echo -e "option1\nyes\n3\nquit" | interactive_program
}

# Timeout with sleep
timeout_command() {
    command &
    local pid=$!
    sleep 10
    kill $pid 2>/dev/null
}

File System Maintenance

# Clean up old temporary files
find /tmp -name "*.tmp" -mtime +7 -exec rm {} \;

# Archive old logs
find /var/log -name "*.log" -mtime +30 | xargs gzip

# Backup with temporary staging
backup_dir=$(mktemp -d)
find . -name "*.important" -exec cp {} "$backup_dir" \;
tar -czf backup.tar.gz -C "$backup_dir" .
rm -rf "$backup_dir"

Dependency Management

# Build order from Makefile dependencies
grep "^[^#].*:" Makefile | sed 's/:/ /' | tsort > build_order.txt

# Package dependency resolution
cat package_deps.txt | tsort | tac > install_order.txt

Performance Considerations

xargs Optimization

  • Use -P for parallel execution when appropriate
  • Consider -n to limit arguments per command invocation
  • Use -0 with find -print0 for filenames with spaces

find Efficiency

  • Use -type early in expressions for faster filtering
  • Combine tests efficiently with -and and -or
  • Consider -prune to skip directories

tee Usage

  • Multiple tee processes can impact performance
  • Consider buffering implications in real-time logging
  • Use -a to avoid overwriting existing files

Return Values and Exit Codes

sleep

  • Success: Exit code 0
  • Invalid time format: Exit code 1

mktemp

  • Success: Exit code 0, outputs filename
  • Cannot create: Exit code 1

xargs

  • Success: Exit code 0
  • Command failed: Exit code of last failed command
  • Internal error: Exit code 125

find

  • Success: Exit code 0
  • Some files inaccessible: Exit code 1
  • Fatal error: Exit code 2

tee

  • Success: Exit code 0
  • Write error: Exit code 1

tsort

  • Success: Exit code 0
  • Cycle detected: Exit code 1

These utilities provide essential functionality for system automation, file processing, and data management within the WebAssembly environment.