Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command line question: History

Status
Not open for further replies.

GSMike

Programmer
Feb 7, 2001
143
US
I am new to UNIX.
I was typing "history" at the command line to pull up my command history. It pulled up about 20 of the most previous commands.
Then I learned that I could just type "h" and it would scroll through every command for the session (I think; like about 2000 commands). The question is, is there a way to put an option on the "h" command to have it return only those commands that meet the criteria of the option?
For example, I am running SAS batch code, so I often type:
emacs mysasfile.sas
to create a batch program.

then I just type:
sas mysasfile
to execute the batch program.

then I type:
emacs mysasfile.log
to look at the log of the execution.

Is there a way to say:
h|*.log
so that the command list history contains only those commands that ended in .log??

Thanking you in advance.
Mike K
 
I would guess that h has been set as an alias for history in your shell. Anyway, an easy way to do what you want is to combine the h or history command with grep. For example,
jupiter84: history |grep htm
73 mv index2.sav index2.htm
74 cp index2.htm index3.htm
77 cp test.htm index.htm
79 cp index.htm index.html
84 history | grep htm

This just returned those commands that had htm in them.
If you are new to unix, one of the first commands you will want to get to know is man, which will give you help on many functions. For instance, man history will tell you alot about the command. Depending on your shell, you can rerun frequent commands. In my example, I could type !74 to rerun the cp.index2.htm command.

Anyhow, welcome to the wonders of Unix!
pt
 
Hi ptwork,
Yep, that works great.
I was trying history|grep *.log, etc. and having no luck.
history (or h in my case also)|grep log works great.

Thanks a million. Mike K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top