Jump to content

Saving Shell Commands and Ouput to a Text File


Recommended Posts

When running a console in a gui I can run a series of commands with resulting ouput and if I want to save what I've done to a text file, I can highlight all the text I want to save with the mouse and copy it to a text file by creating an empty text file and copying with a wheel click. Is there any way to do this from a shell? For a single command I can redirect the output to a text file with ">" but I can't figure out how to select text from within a shell to save to a text file particularly when running a series of commands with output. Ideally, I'd like to know how to save the entire shell session to a text file for later review. I'm sure there's a way to do it; I just can't figure it out.

Link to comment
Share on other sites

http://docs.mandragor.org/files/Programmin..._en/x11830.html

 

I know you can pipe your standard output & or standard error to a file but then i think it wont appear in the console which would be a problem. I don't know how to pipe to a file and still display in the console, but there are plenty here who are more experienced than me with bash so someone will know.

Link to comment
Share on other sites

Thanks johnnyv but that's not what I'm looking for. That's just using "<" and ">" to redirect stdin or stdout from or to a text file. I don't know what I'm going to run in advace so I can't create a text file for stdin and ">" is limited to one command at a time and redirects the output to a text file and as you said you can't read the ouput on the screen. I was feeling pretty stupid for not knowing how to do this but maybe it's not as simple as I thought. Maybe some kind of screen capture could do it but that way seems like a real kludge and I'm not even sure it's possible.

Link to comment
Share on other sites

I've heard something about editing the scripts/files (d/k which ones that would be) that open virtual consoles, or something, using the same '>' so that everytime that vt is opened the output is recorded to a 'specified in the script' file. Something to look into anyway. I d/k... inittab, or /etc/bashrc or both.....how about a console.perm file or whatever?

Link to comment
Share on other sites

johnnyv, you da man :headbang::headbang: Script is just what I was looking for. The only limitation I can see is that if you run something that ouputs formatted text in rows and columns like the "ls" command you get a bunch of garbage in your save text file, probably formatting metadata, but I can live with that. Thanks :D

Link to comment
Share on other sites

yes there is some junk but it is a limited set of junk have not seen more than 8 different occurances so you could just filter your text file to remove them.

 

One thing you can't help is when you type a mistake the backspace to delete it and start again, script records all you typing, which can look odd.

Link to comment
Share on other sites

When you're in the shell, have you tried the 'save history as' option on the edit menu?

 

You only get that in when running X with terminal emulators like konsole or xterm. Running from a shell is like booting to text mode or doing Ctrl-Alt-F1. There's no window with an edit menu; it's just you and the command prompt.

 

Re the garbage appearing with script, I've only seen it with the ls command and the backspace problem you mentioned so far. I think the ls problem is related to the color coding on the ls output more than any thing else.

Edited by pmpatrick
Link to comment
Share on other sites

I don't know how to pipe to a file and still display in the console, but there are plenty here who are more experienced than me with bash so someone will know.

I'm not sure I qualify, but I have found the tee command, which does this. With the ls command, it strips out the colour on screen and in the file.

ls -l | tee -a teefile

This example also suppresses the wide format -

ls ~ | tee -a teefile

Just thought you'd like to know...

 

:zzz:

Edited by spinynorman
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
 Share

×
×
  • Create New...