x32x01
  • by x32x01 ||
When you run a script or command it generates an output on a terminal for viewing. It can be stored in a file, sometimes it can be useful because you won’t need to copy/paste from the terminal.

#1 Using Redirection To Save Command Output To A File in Linux
We can use a redirection operator to save script OR command output to a file.
  1. “>” Operator redirects command output and replaces existing content on a file.
  2. “>>” Operate add command output at the end of the existing content in the file.
Code:
ping -c 3 google.com > output.txt
output.png
It will generate an output.txt file automatically and store the output of the command. If we use the similar command again it will replace the content.

Let’s use the redirection operator in append mode “>>”
Code:
ping -c 3 bing.com >> output.txt
redirection-operator.png
This double redirection operator “>>” would not replace your output instead it will append the output to the existing content, which can be sometimes helpful.

To avoid output errors you can use postfix 2>&1:
Code:
ping -c 3 bing.com >> output.txt 2>&1

#2 Using tee Command To Display Output And Save It
Now, we’re going to use tee command to display the output on the terminal and save the output this would do both, unlike the redirection operator which we used previously.

Let’s use tee command:
Code:
nslookup hacktoday.net | tee output.txt
tee-command.png
The file would be created if doesn’t exist already.

These simple commands can be useful in different scenarios, can be used to save the important output while running the commands instead of spending time savings output. Especially for Pen-testers and Linux devs where they need to save important outputs to a file.
 

Similar Threads

x32x01
Replies
0
Views
36
x32x01
x32x01
x32x01
Replies
0
Views
132
x32x01
x32x01
x32x01
Replies
0
Views
386
x32x01
x32x01
x32x01
Replies
0
Views
552
x32x01
x32x01
x32x01
Replies
0
Views
191
x32x01
x32x01
TAGs: Tags
linux commands save terminal output

Register & Login Faster

Forgot your password?

Latest Resources

Forum Statistics

Threads
517
Messages
518
Members
44
Latest Member
Zodiac
Back
Top