Skip to main content

Unix cat

In Unix, the `cat` command is a utility that reads files and writes them to standard output. You can use Deno to mimic the behavior of the `cat` command.

In this program each command-line argument is assumed to be a filename, the file is opened, and printed to stdout (e.g. the console).

Edit on Github
Create a script that reads the contents of one or more files and writes them to standard output.
for (const filename of Deno.args) {
  const file = await Deno.open(filename);
  await file.readable.pipeTo(Deno.stdout.writable, { preventClose: true });
}

Run this example locally using the Deno CLI:

deno run --allow-read cat.ts file1 file2

Did you find what you needed?

Privacy policy