![]() |
VOOZH | about |
By David Collazo
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.
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.
Browse Series: 4 tutorials
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'
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.