A few zsh tricks

Computers, Linux, Ubuntu 1 Comment »

I’ve started playing around with the zsh shell, and I like it a lot more than bash. A few weeks ago I participated in the “history meme” where I used this command in zsh:

cat ~/.histfile|awk '{a[$1]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head

to print out my top 10 used commands.

A slightly shorter command in zsh is:

history 1|awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head

which works for anyone, even if they have their history file in a different location. The command “history 1″ prints all commands in the history from the 1st one.

Everyone, whether they are new to Linux or a guru forgets to put “sudo” in front of system commands once in a while. I often forget when I want to edit a file in /etc or need to use apt-get. Typing out the command again can be long-winded, as can pressing up to get the command again, and then reverse tabbing to the beginning of the line to type “sudo “. zsh gives an easier way:

sudo !!

Adding “!!” after anything will simply put whatever you type before the !! at the beginning of the last used command, and then execute it. It’s much faster. Additionally, just executing “!!” on the command line will execute the last command, without any prefix. You can use !! to prefix any command you want.

Finally, if you use a lot of terminals at once (like myself) it will be useful to share the history across them. Usually only the most recently opened terminal saves history. Adding these to your .zshrc file will enable all instances of zsh to store history, and update their history every time a command is executed.

setopt EXTENDED_HISTORY
setopt SHARE_HISTORY
setopt APPEND_HISTORY
setopt INC_APPEND_HISTORY

Popularity: 3% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl

Shell History

Computers, Linux, Ubuntu No Comments »

Seems like a lot of Linux bloggers have been doing this recently so I thought I’d follow suit! The following command (in bash) will print the top ten commands in your shell history:

history|awk ‘{a[$2]++ } END{for(i in a){print a[i] ” ” i}}’|sort -rn|head

Of course, since I use zsh instead of bash, I had to make a few changes:

cat ~/.histfile|awk '{a[$1]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head

And my results:

88 ls
70 cd
64 sudo
64 petris
36 plato
30 vim
29 cat
26 echo
20 wine
20 make

ls, cd, and sudo are pretty standard commands that are used so it’s not surprising they come first. I clearly play petris (a tetris clone) way too often. “plato” is a custom command to connect me to my university servers. vim, cat, and echo are also pretty standard commands. I have recently begun using wine a lot to play PC games, and make to compile a load of programs :D

Popularity: 3% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Login