Skip to content

KALI Linux – How to redirect output, errors and input

19/02/2014

Input: You may need to accept input from a file or the command line.

Output: You may need output sent to the screen or a file.

Errors: stderr carries high priory information such as error messages.  Often errors are sent to /dev/null.  If a program generates too many errors you can redirect and discard the error messages.

whine 2> /dev/null

******

Symbols you’ll see:

>

  • Creates a new file containing OUTPUT
  • Overwrites existing files

>>

  • Adds/appends OUTPUT to the existing file.
  • If the file doesn’t exist, it is created.

2>

  • Creates a new file containing ERROR messages.
  • Overwrites existing files.

2>>

  • Adds/appends ERRORS to the file.
  • If the file doesn’t exist, it is created.

&>

  • Creates a new file, with BOTH output and ERRORS.
  • Overwrites existing files.

<

  • Uses the contents of the file as INPUT.

<<

  • Accepts TEXT on the command line as INPUT.

<>

  • The file is used for BOTH input and output.

tee

  • tee splits standard input so that its displayed on the screen and saved to a file.  tee is used to “pipe” the output into storage.
  • whineyprogram | tee output.txt

********

PIPES

Data pipes redirect input, just like plumbing pipes redirect the flow of water.  The syntax is FROM > TO.

First | Second

ls -al /bin | less

ls | wc -l

dmesg | less

dmesg > tempfile1

First | Second | Third | Fourth | Fifth | Sixth

dmesg | sort -f | less

ls -al | less

ls -al | more

ls | wc -l > count.txt

From → KALI, Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: