Posts Tagged history

Searching through your terminal buffer/history

For some reason I could have sworn this was as easy as pressing Ctrl-F but apparently it’s not.. Or maybe that’s something that was lost in the switch from Ubutntu to Debian.. Either way I needed a way to search a vast amount of terminal output quickly and easily and this is how I did it.

  1. Install screen – apt-get install screen
  2. run your commands from inside screen.  If you need to search through 1000′s of lines of output you’ll probably need to adjust the output buffer size by adding this line to your ~/.screenrc: defscrollback 5000
  3. After you’ve run your command(s) and it/they’ve spit out line upon line of output you need to go into copy mode to start searching through.. You do this with C-a [ .  I just did that to be a dick as I’ve seen it everywhere and no one bothers to explain what the bloody hell C-a is.  It means Ctrl+a , shorthand for those people too lazy to type the trl in Ctrl I guess..  Anyways press Ctrl-a and then [ and then you’ll be in copy mode
  4. Search backwards by pressing ? and then typing in your search term.  You can then press ‘n’ to go to the next instance
  5. Search forwards by pressing / and again n will go to the next instance

Easy peasy and way more 1337 than using ctrl-f .

 

PS – another really handy command in screen is Ctrl-a ? which brings up all the commands.  Enjoy and happy searching

Tags: , , , ,

Enabling Autocomplete by reverse searching history in Linux

Being a FreeBSD user I just got used to a very nice feature that would allow me to autocomplete commands based on my history.  So for example if 15 commands ago I had typed ‘cat filenames1 > filename2′ and I wanted to retype that command I could just type ‘cat’ and then press up and it would go through my history and bring up the last command I typed starting with ‘cat’ until I got back to the desired command, only bringing up those in my history starting with ‘cat’ of course.

Unfortunately this isn’t the way it works in linux, in linux pressing up, no matter how much you’ve typed so far will just take you back through the command history.  Sure you can press ctrl-r but I couldn’t be bothered to figure that out.  Besides there is a much cooler way to go about it.

what you  do is to edit /etc/inputrc:
vi gedit /etc/inputrc

somewhere around line 40 is the following:

# alternate mappings for “page up” and “page down” to search the history
#”\e[5~”: history-search-backward
#”\e[6~”: history-search-forward
Uncomment those lines, close term and open an new one and viola!  It works the same but with page up and down instead.  Beauty!  If you didn’t know about this at all go in there and turn it on right now because man this is a time saver and a half.  You’ll thank me later!

Tags: , , , , , ,

Page optimized by WP Minify WordPress Plugin