0

I am running a command say nmap www.somesite.com>file.txt so that i can get the output to file.txt. But if I do so, I am not able to see the output of that command on terminal. Is it possible to make it visble on terminal also.

I know the usage of tee, but I wish to do this specifically in this way.

Anandu M Das
  • 2,303

3 Answers3

3

tee is designed to split STDIN into a file and back out to STDOUT.

In simple terms, just pipe it through, like so:

nmap www.somesite.com | tee file.txt

The current accepted alternative involves running nmap twice which is a horrible idea.
You'd be better off running it once to file and then outputting the file.

nmap www.somesite.com > file.txt; cat file.txt
Oli
  • 299,380
1

That is exactly what tee is for. Why do you not want to use that?

An alternative might be to capture the output, and echo it twice:

output=$(nmap localhost)
echo "$output"
echo "$output" > somefile.txt

However, in the special case of nmap, you can take advantage of it's output option -ox :

      OUTPUT:
         -oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,
            and Grepable format, respectively, to the given filename.

For example:

nmap -oN somefile.txt localhost

Seems to do exactly what you want: output to the terminal and also write to file.

mivk
  • 5,811
-1

It is not possible to have command line view and redirect process at the same time

But you can use the following command to use both the process in sequence

nmap www.somesite.com && nmap www.somesite.com > file.txt

First it will execute the command in terminal and then it will save the output as a file

Hope this helps!

BDRSuite
  • 3,196
  • 1
  • 13
  • 11