LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 04-22-2016, 04:55 PM   #1
schuey6
LQ Newbie
 
Registered: Apr 2016
Posts: 6

Rep: Reputation: Disabled
Terminal


I am wondering how to output all the commands i just( making a user, ifconfig, ping google.com) made into a .txt file. Help would be greatly appreciated
 
Old 04-22-2016, 05:02 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
like this:
Code:
history > commands.txt
?

You won't have the output of the commands, just the commands themselves. If you want the output you could copy/paste from your terminal, or if you have some notice you can enable session logging before you run the commands to record both the commands and their output (can't do this after-the-fact).

Last edited by suicidaleggroll; 04-22-2016 at 05:03 PM.
 
Old 04-22-2016, 05:16 PM   #3
schuey6
LQ Newbie
 
Registered: Apr 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
i dont understand. This is for a class im taking. We did it in class but i cant remember how to output the commands we did to a .txt
 
Old 04-22-2016, 05:22 PM   #4
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,166
Blog Entries: 10

Rep: Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979
Quote:
Originally Posted by schuey6 View Post
i dont understand. This is for a class im taking. We did it in class but i cant remember how to output the commands we did to a .txt
Open a terminal and issue this command:
Code:
history > ~/commands.txt
bash_history will be written to ~/.commands.txt

There are dozens of ways to accomplish things in Linux, so if this doesn't "fit" with what you've studied, I wouldn't worry.
The Teacher may even be surprised that you found a solution he (or she) did not teach you.
 
Old 04-22-2016, 05:23 PM   #5
schuey6
LQ Newbie
 
Registered: Apr 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
when we did it it didnt just show the commands it showed all the results of the commands as well. I really nedd help with this. Its the only thing im struggling with.
 
Old 04-22-2016, 05:29 PM   #6
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,166
Blog Entries: 10

Rep: Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979
Quote:
Originally Posted by schuey6 View Post
when we did it it didnt just show the commands it showed all the results of the commands as well.
Never seen that. Class or no class.
Well, I have but does the Teacher know what I know?
May want to ask your Officiator, or a classmate.
 
Old 04-22-2016, 05:30 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
You can use "script" to record all commands and their output, but this needs to be run before you run the commands, not after.

Is it possible that what you did was not a shell command, but was instead some shortcut for the terminal emulator you were using to dump the current history to a file? Whatever that key combination was would of course depend on the terminal emulator you were using.

Last edited by suicidaleggroll; 04-22-2016 at 05:32 PM.
 
Old 04-22-2016, 05:38 PM   #8
schuey6
LQ Newbie
 
Registered: Apr 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
This is what we submitted on our blackboard when he was showing us how to do it. we had to copy and paste the .txt file into blackboard. I would say screw it and not worry about it but its part of my final exam.






PING www.google.com (216.58.192.132) 56(84) bytes of data.
64 bytes from ord36s01-in-f132.1e100.net (216.58.192.132): icmp_seq=1 ttl=53 time=11.6 ms
64 bytes from ord36s01-in-f132.1e100.net (216.58.192.132): icmp_seq=2 ttl=53 time=11.4 ms
64 bytes from ord36s01-in-f132.1e100.net (216.58.192.132): icmp_seq=3 ttl=53 time=10.9 ms

--- www.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 10.928/11.323/11.606/0.300 ms

traceroute to www.google.com (172.217.4.4), 30 hops max, 60 byte packets
1 172.22.0.3 (172.22.0.3) 1.002 ms 0.951 ms 0.901 ms
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
traceroute to www.google.com (216.58.192.132), 30 hops max, 60 byte packets
1 172.22.0.3 (172.22.0.3) 33.650 ms 33.599 ms 33.590 ms
2 172.20.100.2 (172.20.100.2) 0.558 ms 0.629 ms 0.757 ms
3 router.monroeccc.edu (50.202.65.81) 3.590 ms 3.611 ms 3.651 ms
4 xe-11-0-2-0-sur06.taylor.mi.michigan.comcast.net (68.86.167.18) 4.089 ms 4.136 ms 4.076 ms
5 te-0-0-0-17-ar02.pontiac.mi.michigan.comcast.net (68.87.191.57) 6.763 ms te-0-0-0-14-ar02.pontiac.mi.michigan.comcast.net (68.87.190.38) 6.703 ms te-0-0-0-17-ar02.pontiac.mi.michigan.comcast.net (68.87.191.57) 8.269 ms
6 be-33668-cr02.350ecermak.il.ibone.comcast.net (68.86.90.45) 14.366 ms 14.315 ms 14.259 ms
7 68.86.85.34 (68.86.85.34) 13.224 ms 12.146 ms 12.077 ms
8 as40009-2-c.1950stemmons.tx.ibone.comcast.net (75.149.231.2) 11.813 ms 11.325 ms 11.439 ms
9 209.85.254.149 (209.85.254.149) 11.379 ms 11.237 ms 209.85.143.135 (209.85.143.135) 11.203 ms
10 216.239.42.153 (216.239.42.153) 11.595 ms 216.239.42.149 (216.239.42.149) 11.474 ms 216.239.42.153 (216.239.42.153) 11.348 ms
11 ord36s01-in-f4.1e100.net (216.58.192.132) 11.290 ms 11.459 ms 11.395 ms
www.google.com has address 216.58.192.132
www.google.com has IPv6 address 2607:f8b0:4009:80c::2004
 
Old 04-22-2016, 05:45 PM   #9
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
That doesn't have the commands that were run, it only has the output. When you ran the commands did you perhaps pipe them to tee or similar, or simply redirect the output to the file? eg:
Code:
ping -c 3 www.google.com | tee output.txt
traceroute www.google.com | tee -a output.txt
or
Code:
ping -c 3 www.google.com > output.txt
traceroute www.google.com >> output.txt

Last edited by suicidaleggroll; 04-22-2016 at 05:47 PM.
 
Old 04-22-2016, 05:49 PM   #10
schuey6
LQ Newbie
 
Registered: Apr 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
idk what tee is. I know w we used the > and >> and echo
 
Old 04-22-2016, 05:51 PM   #11
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Ok. How about you try using some of the suggestions that have been provided to you and see if they will/won't work for your application, and if not, why not.

So far you have history, script, tee, simple I/O redirection, and of course the ever-so-simple copy-and-paste-from-the-terminal-emulator. Surely one of them will accomplish your goal?

Last edited by suicidaleggroll; 04-22-2016 at 05:52 PM.
 
Old 04-22-2016, 06:12 PM   #12
schuey6
LQ Newbie
 
Registered: Apr 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
so i figured out how to get all the commands to output except for when i do useradd. Thats the only one that does not show up in the .txt
 
Old 04-22-2016, 09:05 PM   #13
GaryWeaton
LQ Newbie
 
Registered: Apr 2016
Posts: 7

Rep: Reputation: Disabled
Quote:
Originally Posted by schuey6 View Post
so i figured out how to get all the commands to output except for when i do useradd. Thats the only one that does not show up in the .txt
As suicidaleggroll suggested, use script to record all terminal sessions. I did a test for you to show that using script can record the command syntax and the responses. I tested the commands useradd and passwd which are in bold. The response output is in italics.


Quote:
Script started on Fri 22 Apr 2016 08:08:09 PM EDT
^[[36l^[>^[]0;garyw@localhost:/home/garyw^G^[[01;31m[root@localhost garyw]#^[[00m useradd -m -s /bin/bash Billy^M
^[]0;garyw@localhost:/home/garyw^G^[[01;31m[root@localhost garyw]#^[[00m passwd Billy^M
Changing password for user Billy.^M
New password: ^M
Retype new password: ^M
passwd: all authentication tokens updated successfully.^M
^[]0;garyw@localhost:/home/garyw^G^[[01;31m[root@localhost garyw]#^[[00m exit^M
exit^M

Script done on Fri 22 Apr 2016 08:09:05 PM EDT
However, it doesn't echo the password you type.

Here's how to use script. In a terminal type

Code:
script mycommnads.txt
Then start typing. When you are done, type exit to quit script.

If you want to do a quick record and exit, do this

Code:
script -c "ps aux" mycoommands.txt
To append more commands and it's output to mycommands.txt, use the -a switch.

Code:
script -a mycommands.txt 

or

script -c "who" -a mycoommands.txt
If you use the first code, be sure to type exit when done.

The second code will automatically exit after the command is executed and written to the mycommands.txt file.

PS: Don't let script to be an one all to end all tool. Sometimes you will need to use other tools and methods to redirect certain types of output. Use the best tool for the job. This will be second nature to you once you are more familiar with linux.

To view your mycommands.txt file, use a text editor like vi, nano, vim etc.

For some unknown reason, the cat command can not view this file. Perhaps it's the ^M in the file.

Last edited by GaryWeaton; 04-22-2016 at 09:44 PM.
 
Old 04-22-2016, 11:51 PM   #14
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mint, OpenBSD
Posts: 11,346
Blog Entries: 12

Rep: Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731
Quote:
idk what tee is
See

Code:
# man tee
From the man file:

Quote:
tee - read from standard input and write to standard output and files
Aside: Man files are not good learning tools, because, like an encyclopedia, they are not designed to teach; they are designed to answer questions. Teaching yourself to use them will help you answer many questions on your own. Here's a good tutorial: http://www.mcmcse.com/linux/man_pages.shtml

I have found the single most useful command related to man pages to be

Code:
# apropos [some subject]
See

Code:
# man apropos
for more.

You can see some examples of using tee here.

Also, please do not use text speak, such as "idk" (which I am guessing means, "I don't know"). Even beyond the fact that English comes in many different variations (it has been said that England and the United States are two countries separated by a common language), for many LQers, English is a second, possibly a third language. Using standard English makes ideas clearer for everyone.

Last edited by frankbell; 04-22-2016 at 11:59 PM.
 
1 members found this post helpful.
Old 04-23-2016, 10:13 AM   #15
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by schuey6 View Post
so i figured out how to get all the commands to output except for when i do useradd. Thats the only one that does not show up in the .txt
You still haven't told us what you used or why it doesn't work. If useradd's output doesn't "show up" in the file, then where does it go and how is this different from the other commands?
 
  


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
Running JMRI/Decoder Pro - Run in Terminal - Terminal flashes and dissappears. HarrisCreekCentral Linux - Newbie 2 06-08-2015 12:59 AM
LXer: Linux Terminal: Reptyr attach a running process to a new terminal LXer Syndicated Linux News 0 08-07-2014 10:20 PM
[SOLVED] Gnome terminal 2.1.0, centos 5 - how to 'find' text listed on terminal screen linuxquestions_forum_use Linux - Newbie 2 12-21-2010 09:35 PM
gnome-terminal:keyboard shortcut launches terminal with / directory default! deepclutch Linux - Desktop 1 06-21-2010 12:48 PM


All times are GMT -5. The time now is 08:34 AM.

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