How can I save the commands typed in a shell?

How can I save the commands typed in a shell?

am 02.10.2007 16:09:11 von Wei Wang

I use "$ history" to get the last few commands typed in the shell
window, but it is not so convenient, just wondering whether there are
some better ways, though I believe there must be...:-) thanks ...-Wei

Re: How can I save the commands typed in a shell?

am 02.10.2007 16:12:14 von Lew Pitcher

On Oct 2, 10:09 am, Wei Wang wrote:
> I use "$ history" to get the last few commands typed in the shell
> window, but it is not so convenient, just wondering whether there are
> some better ways, though I believe there must be...:-) thanks ...-Wei

Take a look in your ~/.bash_history file (presuming that you use bash)

Re: How can I save the commands typed in a shell?

am 02.10.2007 16:19:07 von Janis Papanagnou

On 2 Okt., 16:09, Wei Wang wrote:
> I use "$ history" to get the last few commands typed in the shell
> window, but it is not so convenient,

The history command just displays the command history. What exactly
do you find inconvenient?

> just wondering whether there are
> some better ways, though I believe there must be...:-) thanks ...-Wei

In what respect better? You didn't say what you'd like. Guessing...
Recall and edit the history? Have you a favourite editor (vi or
emacs)? Type one of the commands (whatever you prefer)
set -o vi
or
set -o emacs
and try using the respective editor commands to search back in the
command history, jump from word to word, modify the line, etc.

Janis

Re: How can I save the commands typed in a shell?

am 02.10.2007 19:09:48 von Bill Marcum

On 2007-10-02, Wei Wang wrote:
> I use "$ history" to get the last few commands typed in the shell
> window, but it is not so convenient, just wondering whether there are
> some better ways, though I believe there must be...:-) thanks ...-Wei
>
In most shells you can use the up and down arrow keys. If you are using
the ancient ksh in some versions of Solaris, you may need to define
aliases for __A, __B, __C and __D.

Re: How can I save the commands typed in a shell?

am 02.10.2007 22:41:38 von wayne

Wei Wang wrote:
> I use "$ history" to get the last few commands typed in the shell
> window, but it is not so convenient, just wondering whether there are
> some better ways, though I believe there must be...:-) thanks ...-Wei
>

It isn't clear to me what you are requesting. However try this:

$ help fc
or
$ man fc

The fc command allows a lot of control of what parts of your history
to display, whether or not to show line numbers, to write the
current history to the saved history file on disk, or to re-load
the history from the saved file. (the current session's history is
kept in RAM).

fc is defined for all POSIX shells including ksh, bash, and others.

-Wayne

Re: How can I save the commands typed in a shell?

am 03.10.2007 14:36:17 von Wei Wang

On Oct 2, 3:09 pm, Wei Wang wrote:
> I use "$ history" to get the last few commands typed in the shell
> window, but it is not so convenient, just wondering whether there are
> some better ways, though I believe there must be...:-) thanks ...-Wei

What I tried to do was to retrieve the useful commands typed in a
shell and compile those successful commands into a script. So I can
run the script later when I need to do the same job again, instead of
typing all those commands (some of them are not easy to remember and
error prone) one by one again. What I normally do is to find those
commands by typing "history" and display the last few commands in a
shell, what I want to do is whether I can keep all the commands typed
in shell in a seperate file, such as .bash_history( thanks Lew for
pointing this out), and then retieve the useful commands in a text
editor (such as vim or xemacs). Many thanks for all those replied and
they were very useful! -Wei

Re: How can I save the commands typed in a shell?

am 03.10.2007 14:40:07 von Joachim Schmitz

"Wei Wang" schrieb im Newsbeitrag
news:1191414977.023897.322700@g4g2000hsf.googlegroups.com...
> On Oct 2, 3:09 pm, Wei Wang wrote:
>> I use "$ history" to get the last few commands typed in the shell
>> window, but it is not so convenient, just wondering whether there are
>> some better ways, though I believe there must be...:-) thanks ...-Wei
>
> What I tried to do was to retrieve the useful commands typed in a
> shell and compile those successful commands into a script. So I can
> run the script later when I need to do the same job again, instead of
> typing all those commands (some of them are not easy to remember and
> error prone) one by one again. What I normally do is to find those
> commands by typing "history" and display the last few commands in a
> shell, what I want to do is whether I can keep all the commands typed
> in shell in a seperate file, such as .bash_history( thanks Lew for
> pointing this out), and then retieve the useful commands in a text
> editor (such as vim or xemacs). Many thanks for all those replied and
> they were very useful! -Wei
Tried the 'script' command?

Bye, Jojo

Re: How can I save the commands typed in a shell?

am 03.10.2007 15:03:54 von Wei Wang

On Oct 3, 1:40 pm, "Joachim Schmitz"
wrote:
> "Wei Wang" schrieb im Newsbeitragnews:1191414977.023897.322700@g4g2000hsf.googlegr oups.com...
>
>
>
> > On Oct 2, 3:09 pm, Wei Wang wrote:
> >> I use "$ history" to get the last few commands typed in the shell
> >> window, but it is not so convenient, just wondering whether there are
> >> some better ways, though I believe there must be...:-) thanks ...-Wei
>
> > What I tried to do was to retrieve the useful commands typed in a
> > shell and compile those successful commands into a script. So I can
> > run the script later when I need to do the same job again, instead of
> > typing all those commands (some of them are not easy to remember and
> > error prone) one by one again. What I normally do is to find those
> > commands by typing "history" and display the last few commands in a
> > shell, what I want to do is whether I can keep all the commands typed
> > in shell in a seperate file, such as .bash_history( thanks Lew for
> > pointing this out), and then retieve the useful commands in a text
> > editor (such as vim or xemacs). Many thanks for all those replied and
> > they were very useful! -Wei
>
> Tried the 'script' command?
>
> Bye, Jojo- Hide quoted text -
>
> - Show quoted text -

Tried, it's full of ESC and ^M, as well as output from commands which
I do not need.

Re: How can I save the commands typed in a shell?

am 03.10.2007 18:15:16 von Old Man

"Wei Wang" wrote in message
news:1191416634.676578.73700@n39g2000hsh.googlegroups.com...
> On Oct 3, 1:40 pm, "Joachim Schmitz"
> wrote:
> > "Wei Wang" schrieb im
Newsbeitragnews:1191414977.023897.322700@g4g2000hsf.googlegr oups.com...
> >
> >
> >
> > > On Oct 2, 3:09 pm, Wei Wang wrote:
> > >> I use "$ history" to get the last few commands typed in the shell
> > >> window, but it is not so convenient, just wondering whether there are
> > >> some better ways, though I believe there must be...:-) thanks ...-Wei
> >
> > > What I tried to do was to retrieve the useful commands typed in a
> > > shell and compile those successful commands into a script. So I can
> > > run the script later when I need to do the same job again, instead of
> > > typing all those commands (some of them are not easy to remember and
> > > error prone) one by one again. What I normally do is to find those
> > > commands by typing "history" and display the last few commands in a
> > > shell, what I want to do is whether I can keep all the commands typed
> > > in shell in a seperate file, such as .bash_history( thanks Lew for
> > > pointing this out), and then retieve the useful commands in a text
> > > editor (such as vim or xemacs). Many thanks for all those replied and
> > > they were very useful! -Wei
> >
> > Tried the 'script' command?
> >
> > Bye, Jojo- Hide quoted text -
> >
> > - Show quoted text -


>
> Tried, it's full of ESC and ^M, as well as output from commands which
> I do not need.
>

Really! Well, have you ever tried using an editor to remove those things?

I know that their presence could be devastating, but a small effort will
get them out of your face. A suggestion would be the 'sed' or 'vi'
commands.

Until the new history, hist, and fc commands are rewritten with special
flags
that read your mind, guess what you want, do the work for you, etc, you may
have to put a little more of your effort into the task that you have chosen
to do.

This forum is supported by gurus who didn't get that way by having others
do the work for them or expect everything for nothing. Remember that
"practice makes perfect" and "never do for a man what he could do for
himself". Try and try again; you will be proud of yourself when finished.

Old Man

Re: How can I save the commands typed in a shell?

am 03.10.2007 23:46:42 von Wei Wang

On Oct 3, 5:15 pm, "Old Man" wrote:
> "Wei Wang" wrote in message
>
> news:1191416634.676578.73700@n39g2000hsh.googlegroups.com... > On Oct 3, 1:40 pm, "Joachim Schmitz"
> > wrote:
> > > "Wei Wang" schrieb im
>
> Newsbeitragnews:1191414977.023897.322700@g4g2000hsf.googlegr oups.com...
>
>
>
>
>
>
>
> > > > On Oct 2, 3:09 pm, Wei Wang wrote:
> > > >> I use "$ history" to get the last few commands typed in the shell
> > > >> window, but it is not so convenient, just wondering whether there are
> > > >> some better ways, though I believe there must be...:-) thanks ...-Wei
>
> > > > What I tried to do was to retrieve the useful commands typed in a
> > > > shell and compile those successful commands into a script. So I can
> > > > run the script later when I need to do the same job again, instead of
> > > > typing all those commands (some of them are not easy to remember and
> > > > error prone) one by one again. What I normally do is to find those
> > > > commands by typing "history" and display the last few commands in a
> > > > shell, what I want to do is whether I can keep all the commands typed
> > > > in shell in a seperate file, such as .bash_history( thanks Lew for
> > > > pointing this out), and then retieve the useful commands in a text
> > > > editor (such as vim or xemacs). Many thanks for all those replied and
> > > > they were very useful! -Wei
>
> > > Tried the 'script' command?
>
> > > Bye, Jojo- Hide quoted text -
>
> > > - Show quoted text -
>
> > Tried, it's full of ESC and ^M, as well as output from commands which
> > I do not need.
>
> Really! Well, have you ever tried using an editor to remove those things?
>
> I know that their presence could be devastating, but a small effort will
> get them out of your face. A suggestion would be the 'sed' or 'vi'
> commands.
>
> Until the new history, hist, and fc commands are rewritten with special
> flags
> that read your mind, guess what you want, do the work for you, etc, you may
> have to put a little more of your effort into the task that you have chosen
> to do.
>
> This forum is supported by gurus who didn't get that way by having others
> do the work for them or expect everything for nothing. Remember that
> "practice makes perfect" and "never do for a man what he could do for
> himself". Try and try again; you will be proud of yourself when finished.
>
> Old Man- Hide quoted text -
>
> - Show quoted text -

The last was a quick reply right after seeing the post. I really
appreciate the inputs received from all replies on this post, and good
news is the problem has now been solved, many thanks to all who
replied!