DEV Community

Luis Gomez
Luis Gomez

Posted on

Learning Terminal (Notes) Day #4 [Standard output]

Standard output

I just learned something very cool! You can save the command result just typing > name_archive.txt next to the command, ok this is not work for every command but works with the commands that provide a text output.

Example: If you want a list of your directories and save what do you have in just type ls directory_name > file_name.txt (I've just learned how to specific code here too ^^)

This command overwrite the text file every time you use it (if use the same file name) if you want to add text but no overwrite use the operator >> instead of >

Here let you more information about all of this

Pipe operator |

Pipe operator allows you run a command that his standard out put change as standard input to another command and this allow us to make another features.

echo: Generate an standard output from anything we type in terminal

Example: echo "Hello World"

With standard out put we can save the command's result to a file text but with pipe we can get that result and give it to another command like cat to visualize the result in out console command without save it.

Example: ls -lh | less

And if we want to save the result in another file like before but after seeing it with less we just to have add another pipe operator but with command tee.

Example: ls -lh | tee output.txt | less
(Like this generate the file first and then visualize it with less)

We can add filters too like sorting filter

Example: ls -lh | sort | tee output.txt | less

Top comments (0)