Bash output redirection

There are 3 built-in file descriptors: stdin, stdout and stderr (std=standard).

Basic

    0/1/2 references stdin/stdout/stderr
    >/2> redirects stdout/stderr, where > is taken as 1>
    &1/&2 references stdout/stderr
    &> redirects everything
    > creates or overwrites a file
    >> creates or appends to a file
    < reads from a file, where < is taken as 0<

Note: You should be pretty sure of what a command is doing if you are going to wipe it's output.

Redirecting Examples

    stdout to file: ls -l > ls-l.txt
    stderr to file: grep da * 2> grep-errors.txt
    one to another: grep da * 1>&2
    everything: do_stuff &> /dev/null
    combined: command < input-file > output-file, reads from input-file and writes stdout to output-file
  • 0 Utilisateurs l'ont trouvée utile
Cette réponse était-elle pertinente ?

Articles connexes

Comment Configurer une Tâche Cron via CPanel

Ce tutoriel vous montrera comment facilement creer un tâche cron via cPanel. Vous pouvez définir...

Comment configurer une tâche planifiée (cron job) ?

Cron est une commande utilisée pour programmer des tâches devant être exécutées périodiquement,...

How to create custom error pages

This tutorial will teach how to create custom Error Pages. Create error pages for 404 Not Found...

Using Index Manager

This tutorial will teach about using the Index Manager. The Index Manager allows you to customize...

How to prevent Search Engine indexing on demo websites

As a system administrator or as a web devloper, you may need to create demo website or staging...