Linux processes generally take input from standard input (keyboard), write output to standard out (screen) and may write to standard error if there are any error message which need to be displayed. Among the various powerful functions of Linux systems is the ability to redirect both input and output of commands.

The > symbol redirects output of a command. For example, cal command prints the calendar to screen. Using > we can save this calendar into a file.

cal > calendar.txt
cat calendar.txt

If the file calendar.txt already exists, its contents would be replaced. If you wish to append content to an existing file, use the >> symbol instead.

ls >> calendar.txt
cat calendar.txt

You can also use cat to concatenate files:

cal 2017 > 2017
cal 2018 > 2018
cat 2017 2018 > calendar.txt

By master