VOOZH about

URL: https://www.digitalocean.com/community/tutorials/an-introduction-to-linux-i-o-redirection

⇱ An Introduction to Linux I/O Redirection | DigitalOcean


An Introduction to Linux I/O Redirection

Updated on June 3, 2022

By David Collazo

👁 An Introduction to Linux I/O Redirection

Introduction

The redirection capabilities built into Linux provide you with a robust set of tools to optimize many workflows. The “Unix philosophy” of software development was to make tools that each do one thing well, and this philosophy has been carried forward to modern command-line tools, which are individually powerful, and exponentially more so when combined. Whether you’re writing complex software or just working on the command line, knowing how to manipulate the different I/O streams in your environment will greatly increase your productivity.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

Tutorial Series: Getting Started with Linux

If you are new to Linux and its command line interface, it may seem like a daunting task to get started with it. This series will bring you up to speed with essential Linux basics, and provide a solid foundation for working with Linux servers. If you have little to no knowledge about using Linux, this is where you will want to start.

About the author

👁 David Collazo
David Collazo
Author
Category:

Still looking for an answer?

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Thanks for the useful info but there is an error in your article: you mention “Commands with a single bracket do not overwrite the destination’s existing contents.” but this should be “Commands with double brackets”.

Thank you for catching that. We have updated the article :)

Thank you very much! Awesome explanation.

echo Written to a new file > data.txt
echo Appended to an existing file's contents >> data.txt

This doesn’t seem to work unless you remove the

Thank you so much for great tutorial!

When I run the command ‘find /var lib | grep deb’ as demonstrated in the ‘command | command’ section, it shows files containing the string ‘deb’ in /var directory, followed by the error message ‘find: ‘lib’: No such file or directory’. What is missing is a ‘/’ between ‘/var’ and ‘lib’ in the command. To get the error-free result, execute the following command: ‘find /var/lib | grep deb’. (Note the ‘/’ symbol between ‘var’ and ‘lib’.)

man tee | less is bit redundant and also strip the colours and bold formatting. man already use less pager by default.

This pattern redirects the standard error stream of a command to a file, overwriting existing contents.

mkdir ‘’ 2> mkdir_log.txt

This redirects the error raised by the invalid directory name ‘’, and writes it to log.txt. Note that the error is still sent to the terminal and displayed as text.

This is an error.

As soon as you redirect with 2> , all the error messages are gone to that device or file. It won’t display anything on the terminal (i.e. the stdout) .

in the examples part, in the second last example, maybe you meant

find /var/lib | grep deb

not

find /var lib | grep deb

it was pretty confusing to me as a beginner, but then I realized you are giving two arguments to the find command which doesn’t make a lot of sense here

Is there a way to create a custom stream? Like this:

$ mksth /dev/mystrm
$ (/bin/some_program < /dev/mystrm > /output.log &)
$ echo "some_code" > /dev/mystrm #Pass some code to 'some_program' that it recognizes via custom stream
$ tail /output.log #Get results for 'some_code'
👁 Creative Commons
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
  • Deploy on DigitalOcean

    Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and AI-native businesses

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

© 2026 DigitalOcean, LLC.Sitemap.
Dark mode is coming soon.