Redirecting Input and Output with File Descriptors
Learn how to redirect input and output with file descriptors.
We'll cover the following
The history
command
Let’s take a look at how the history
command works and how we can use its output. When we execute the history
command, the program’s output is displayed on the screen. The history command writes its output to standard output, and standard output is mapped to our terminal screen by default.
We’ve already used >
and >>
to redirect a program’s output to a file. For example, we can save the contents of our shell history to a file:
$ history > commands.txt
We also know that using >>
appends text to an existing file. For example, we can append today’s date to the file we just created:
$ date >> commands.txt
To refresh our knowledge of these concepts, let’s try these commands in the terminal below.
Get hands-on with 1200+ tech skills courses.