LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-30-2014, 10:03 AM   #1
ursuniel
LQ Newbie
 
Registered: Jan 2014
Posts: 2

Rep: Reputation: Disabled
Question what is the command to store a list of commands and their outputs in a file


Hello Everyone,
I am a newbie to LINUX.
I need a command that will store all the commands I type on terminal after that and their corresponding output into a file, so that I can use them later on.

Please help as after searching on Google for hours I couldn't get the answer.
 
Old 01-30-2014, 10:12 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,149

Rep: Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887
i dont think a single command can do that but maybe this can give you an idea:
Code:
(echo uname: && uname -a -m -p && echo lspci: && lspci && echo lsusb: && lsusb && echo lsmod: && lsmod && echo ifconfig: && ifconfig && echo ifconfig -a: && ifconfig -a && echo iwconfig: && iwconfig && echo resolv.conf: && cat /etc/resolv.conf && echo route: && route -n) &> commands.lst
notice that i am using echo to print the command and redirecting all the output to a file.
 
Old 01-30-2014, 10:18 AM   #3
ursuniel
LQ Newbie
 
Registered: Jan 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Smile Thanks schneidz

Thanks schneidz
 
Old 01-30-2014, 10:41 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
To list out all commands, you can use history command:
Code:
~$ history
To store result of history command into a file named history.txt:
Code:
~$ history > /path/to/history.txt
Then to erase all history:
Code:
~$ history -c
 
Old 01-30-2014, 12:56 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,711

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Quote:
Originally Posted by ursuniel View Post
Hello Everyone,
I am a newbie to LINUX.
I need a command that will store all the commands I type on terminal after that and their corresponding output into a file, so that I can use them later on.

Please help as after searching on Google for hours I couldn't get the answer.
You want the "script" utility.

It creates a pseudoterminal with a shell - and copies everything sent to the terminal.

Note: it copies EVERYTHING ... including carrage return/line feed sequences. If you plan to use it in documentation (which is what I do sometimes), you have to convert the escape sequences/carrage return characters... to something you want rather than what was saved.
 
1 members found this post helpful.
Old 01-30-2014, 02:10 PM   #6
Habitual
LQ 5k Club
 
Registered: Jan 2011
Location: Nowhere near you, thank God.
Distribution: OSX Sierra
Posts: 8,573
Blog Entries: 15

Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
You want the "script" utility.

...If you plan to use it in documentation (which is what I do sometimes), you have to convert the escape sequences/carrage return characters...
You have some code kungfu for that operation you'd like to share?

I have avoided script because cleansing the output is rather laborious and I've not taken up the challenge of doing a "cleaning" of the output.
Can't the script utility also "playback" the saved output without performing the actions in the output file?

Thank you.
 
Old 01-30-2014, 03:12 PM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,825
Blog Entries: 12

Rep: Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008
Hmm .. that's a toughie. Please note that I don't think many have answered what the OP was asking:
Quote:
I need a command that will store all the commands I type on terminal after that and their corresponding output into a file, so that I can use them later on.
What I got doesn't work yet. Maybe though other's can chime in to improve and get it correct:
Code:
ls *qna &>> temp.txt
is an example where you can issue the ls command here looking for *qna which won't be found, so as a result the temp.txt file will be either created if it doesn't exist or have appended to the end of it the error output of the ls command. Whereas if you did:
Code:
ls *.c &>> temp.txt
You'd get a listing of C files, providing there were any. In short, you'd get stdout and stderr both into that file.

The problem is, you don't get your original command listed. There.

I have two problems with that:
  1. If one can get the original command, it should go above the outputs
  2. How does one get the original command? I tried using $0 and that gave me "bash", I don't know the command line substitution for that last line, excepting to use history somehow
 
Old 01-30-2014, 03:23 PM   #8
Habitual
LQ 5k Club
 
Registered: Jan 2011
Location: Nowhere near you, thank God.
Distribution: OSX Sierra
Posts: 8,573
Blog Entries: 15

Rep: Reputation: Disabled
and there's http://showterm.io/
but I'm not sure that's an appropriate solution for the OP.
 
Old 01-30-2014, 04:14 PM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,711

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Quote:
Originally Posted by Habitual View Post
You have some code kungfu for that operation you'd like to share?

I have avoided script because cleansing the output is rather laborious and I've not taken up the challenge of doing a "cleaning" of the output.
Can't the script utility also "playback" the saved output without performing the actions in the output file?

Thank you.
For the most part (even long logs) I just use vi. :1,$s/^V^M// (a : to go to command mode, 1,$ - process the file from first line to last line, s/^V^M// - substitute (control V to enter a control character, control M is a return) and replace the return with nothing.

The problem with escape characters is only caused when you record an editing function, or have the shell setup to do oddball things with colors (which I mostly don't like). These vary depending on the terminal type, application, AND what you are doing...

Not an easy thing to deal with.
 
Old 01-30-2014, 04:29 PM   #10
Habitual
LQ 5k Club
 
Registered: Jan 2011
Location: Nowhere near you, thank God.
Distribution: OSX Sierra
Posts: 8,573
Blog Entries: 15

Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
For the most part (even long logs) I just use vi. :1,$s/^V^M// (a : to go to command mode, 1,$ - process the file from first line to last line, s/^V^M// - substitute (control V to enter a control character, control M is a return) and replace the return with nothing.

The problem with escape characters is only caused when you record an editing function, or have the shell setup to do oddball things with colors (which I mostly don't like). These vary depending on the terminal type, application, AND what you are doing...

Not an easy thing to deal with.
You got that right. Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where do I go to get a list of the command prompt commands. dickcdavis Linux - Newbie 7 10-14-2011 10:23 AM
[SOLVED] curl -K command outputs weird symbols instead of downloading URL from file meridionaljet Linux - Newbie 7 05-16-2011 09:13 PM
Store line from text file into list C++ lalhad21 Programming 2 02-06-2011 11:30 AM
i need to store the outputs of 2 commands in 2 variables and compare the two variable anurupr Linux - Newbie 10 03-04-2010 06:05 AM
Store into a file the list of executable files of a system directory jianelisj Linux - Newbie 3 03-17-2008 01:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration