Skip to content

Entrada YSalida

Redirigir stdin/stdout/stderr, encadenar con pipes y duplicar salida con tee.


ConceptoSignificado
0 stdinEntrada (teclado por defecto).
1 stdoutSalida normal.
2 stderrErrores.

> equivale a 1>. Descriptores 3+ para casos avanzados.

ComandoQué haceEjemplo
>Sobrescribe stdout.echo hola > out.txt
>>Append stdout.echo mundo >> out.txt
<Archivo como stdin.cat < in.txt
2>Solo stderr.ls x 2> err.txt
> file 2>&1stdout+stderr a file.cmd > todo.txt 2>&1
&>Atajo bash: ambos.cmd &> todo.txt
|Pipe stdout → stdin.ls | grep .txt
Terminal window
echo "hola," > ./salida.txt
echo "mundo!" >> ./salida.txt
ls noExiste 2> errores.txt
comando > todo.txt 2>&1 # errores al mismo sitio que la salida
ls carpeta_inexistente &> salida.txt
ls | grep .txt

Terminal window
cat archivo.txt
cat a.txt b.txt > c.txt
cat > nuevo.txt # escribir; CTRL+D para terminar
echo "Hola mundo" | tee salida.txt # pantalla + archivo
ls | tee -a lista.txt # append
ls | tee a.txt b.txt # varios archivos
ConceptoSignificado
catVer, unir o crear por stdin.
teeEscribe a archivo y sigue mostrando en pantalla.
tee -aAppend.

Docs: Redirections (Bash).