How To Save Command Output In A File
When working on Linux operating systems we have multiple options on commands that are available at the support, management or information level.
With the commands we can assign the output of a command to a variable, define multiple commands to execute a task or redirect the results of a command for analysis at a certain time.
This tutorial in this opportunity will analyze how we can redirect the results of a command to a file for later administrative analysis.
Display Output of a Command & Save the Output in Linux
For this example, we will use the df command, thanks to which we will display a complete summary of the space on the hard disk available and used by the file system.
When executing this command this will be the result:
If we use this command with the -h parameter we will see this result in a human-readable format, as they usually call it, that is, it displays details of the statistics in bytes, mega bytes and gigabytes:
If we want this information to be displayed on screen and at the same time be written in a file for analysis later, we will execute the following lines:
df -h | tee df.log cat df.log
This will be the result obtained:
If we want to know in detail more help on these commands we can execute the following lines:
man df man tee
As simple as that we can save the results of a command in a Linux file and always have them available for analysis