Skip to main content

Syntax

cat [FILE...]

Description

The cat command reads one or more files and writes their contents to standard output. When called without arguments, it reads from standard input and echoes it to standard output, making it useful in pipelines.
In Nash, cat operates entirely within the virtual filesystem (VFS). It never accesses the host system unless you’ve mounted a directory with --bind.

Parameters

FILE
string
Path to file(s) to read. Can be relative to current directory or absolute. If omitted, reads from standard input.

Behavior

  • No arguments: Reads from stdin and writes to stdout (pass-through mode)
  • One or more files: Concatenates all files in order and writes to stdout
  • Flags: Any arguments starting with - are silently ignored
  • Error handling: If any file cannot be read, returns exit code 1 with error message

Examples

Display a single file

cat welcome.txt
Welcome to Nash!

Nash is a sandboxed bash-like shell written in Rust.

Concatenate multiple files

cat header.txt body.txt footer.txt > page.html

Use as stdin pass-through

echo "hello world" | cat | grep hello
hello world

Create a file from stdin

cat > newfile.txt
Type your content here
Press Ctrl-D when done

Append to a file

cat additional.txt >> existing.txt

Error Handling

File not found

cat nonexistent.txt
cat: nonexistent.txt: No such file or directory
Exit code: 1

Permission denied (read-only mount)

# If /data is mounted read-only
cat /data/protected.txt
If the file exists but cannot be read, cat will return an error describing the issue.

Implementation Details

  • Source: src/builtins/cat.rs
  • Reads entire file contents into memory using vfs.read_to_string()
  • Processes files sequentially in the order provided
  • Concatenates outputs without separators
  • Flags starting with - are filtered out but not validated
Unlike Unix cat, Nash’s implementation doesn’t support flags like -n (line numbers), -b (number non-blank lines), or -v (show non-printing characters). These are silently ignored.

Differences from Unix cat

FeatureUnix catNash cat
Multiple files✅ Supported✅ Supported
Stdin passthrough✅ Supported✅ Supported
-n (line numbers)✅ Supported❌ Ignored
-b (number non-blank)✅ Supported❌ Ignored
-v (show non-printing)✅ Supported❌ Ignored
-E (show line ends)✅ Supported❌ Ignored
Large filesStreamsLoads into memory

Use Cases

View file contents

cat config.json

Combine multiple files

cat part1.txt part2.txt part3.txt > complete.txt

Pipeline processing

cat data.txt | grep ERROR | sort | uniq -c

Here document simulation

cat > script.sh
#!/bin/nash
echo "Hello from Nash"
  • head - Display first lines of a file
  • tail - Display last lines of a file
  • grep - Filter file contents by pattern
  • file - Determine file type
  • stat - Display file status information

Build docs developers (and LLMs) love