Jump to content

SSH/Shell - How to save results to a file?


ianh

Recommended Posts

Hi everyone,

 

I want to know how I can save results generated from a Shell command to a file?

 

For example I have entered the Shell command..

 

netstat -lnptu

 

..to show me the active ports on my server. How can I save this list of ports to a text file?

 

Your help much appreciated.

Link to comment
Share on other sites

I think you can just do:

 

netstat -lnptu > ports.txt

 

Thanks Maq, but where would ports.txt get saved to?

How would I save it to a specific directory?

 

As you can tell I'm a complete Shell newbie :-)

Link to comment
Share on other sites

Thanks Maq, but where would ports.txt get saved to?

 

The command I gave you saves ports.txt in the current directory you're in.

 

How would I save it to a specific directory?

 

You have to specify what directory you want to save it in.

 

i.e.

 

netstat -lnptu > /home/tim/ports.txt

 

This would save ports.txt into my home directory.  You can hard code a path but that's dangerous if you ever use this script on a different server.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.