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:
You Can, Log in or Register To View Codes Content !
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:
You Can, Log in or Register To View Codes Content !
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:
You Can, Log in or Register To View Codes Content !

#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:
You Can, Log in or Register To View Codes Content !
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
48
x32x01
x32x01
x32x01
Replies
0
Views
173
x32x01
x32x01
x32x01
Replies
0
Views
471
x32x01
x32x01
x32x01
Replies
0
Views
119
x32x01
x32x01
x32x01
  • x32x01
Replies
0
Views
99
x32x01
x32x01
TAGs: Tags
linux commands save terminal output

Register & Login Faster

Forgot your password?

Latest Resources

Forum Statistics

Threads
507
Messages
508
Members
42
Latest Member
Mustafa123
Back
Top