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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep a sh_history

Status
Not open for further replies.

sumgirl

IS-IT--Management
Mar 19, 2003
55
US
Anyone know how to grep a sh_history file? Apparently the internal format of these files isnt plain text or something, because I cant get grep to return anything. Silly question probably, but its seems like pretty straight forward thing so I am not sure exactly how I could be doing anything wrong.
 
Did you try cat .sh_history | grep string ? It works fine on 5.2. Do you have permission to read the file?

Time to make the Java...
[morning] needcoffee
 
Hi,
what about this command

your_prompt#: cat -v /path/to/.sh_history |grep "pattern"

Regards
 
can you cat the file and see normal text?

There are special characters in the file, but your command history is in plain text. (well, it is on every flavour of *nix I've worked on)

Maybe the string you're grepping for doesn't exist. Aged out, maybe? What's your HISTSIZE set to ?

I'm assuming this is korn shell.
 
Hi,

Try this:

fc -l -number | grep string. Where number display the last number of commands in the .sh_history file and string is the word you are looking for. e.g.

fc -l -100 | grep chmod

Look for the word chmod in the last 100 commands in the .sh_history file.

I hope this help you. Bye.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top