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 Els usuaris han Trobat Això Útil
Ha estat útil la resposta?

Articles Relacionats

How do I configure a cron job ?

Cron jobs are commands used to schedule tasks that must run periodically, for instance: from...

How To Install and Uninstall FrontPage Extensions

This tutorial will show you how to install and uninstall FrontPage extensions. Please note that...

Mod PageSpeed

You can install Mod PageSpeed by using following stepswget...

How To Set Up A Cron Job via CPanel

This tutorial is going to show you how to setup a cron job in cPanel the easy way. You can set a...

GeoIP

How to get mod_geoip to work on cPanel (Country and City)   mod_geoip allows you to look...