How Fast Can You Type? Develop a Tiny Utility in Bash to Find Out


If you spend most of your time typing on your keyboard (and I hope you don’t use that mouse very frequently, if you care for your wrists, that is), getting up to speed and practicing to become a better and faster typist is well worth the time and effort. And measuring something is the first step to improve it.

There are tons of applications which test your typing abilities and help you improve it, but wouldn’t it be nice to have a basic idea about your typing performance using nothing but good old Bash? After all, this is about DIY (Do It Yourself) approach and having fun; two notions that Linux Journal readers know very well.

The idea is actually very simple: Measuring the typing speed means basically measuring how many words you typed in a given amount of time. One of the most popular units used is wpm (words per minute). Maybe not very accurate and scientific, but we’re aiming for a ballpark figure here so some approximate measure will be fine for our purpose. Based on this information we can write the formula as:

typing_speed_in_wpm = num_words / ( (end_time - start_time) / 60 )

Now that we have our theoretical framework set up, it is time to build the practical computational part of the project. Before diving into code, let’s break down the above formula into pieces and see which GNU/Linux utilities can help us achieve various tasks:

  • date: This is our well-known utility and if you use it with the %s format specifier it returns the “seconds since 1970-01-01 00:00:00 UTC”. So if you run date +%s once at the beginning of your typing session and once at the end of it, you’ll have the end_time and start_time.
  • wc: This is yet another well-known utility that can give you the number of words in a file if invoked with -w option. And remember, in GNU/Linux almost everything is a file, including your input from the keyboard.
  • cat: Officially it concatenates files and print them on the standard output. Practically it can grab your input from the keyboard and via a pipe send that to the wc. In other words all we need to do to count the number of words we just typed is to issue the following command: cat | wc -w
  • bc: Officially it is an arbitrary precision calculator language. Practically it is a very handy utility if you want to do calculations within the command line. But you have to be careful and read its manual page. Why? Well, if you try these:
$ echo 1 + 1 | bc

everything seems fine but if you try the following:

$ echo 1 / 2 | bc

That’s not what you’d expect from a computer. Why doesn’t it return the correct answer, that is 0.5? According to its manual page “scale defines how some operations use digits after the decimal point. The default value of scale is 0.” Apparently it is not a very sensible default for our division operations which we’ll use later. The solution then is to tell bc what scale to use before doing the operation, e.g.:

$ echo “scale=2; 1 / 2” | bc

That’s much better. We have all the components in place and now it is time to glue them together using our favorite application development environment, Bash:

1  #!/bin/sh
2  # a very tiny utility to measure typing speed.
3  prompt="Start typing a piece of text. Press Ctrl-d twice to
4  echo "\n$prompt \n"
5  start_time=`date +%s`
6  words=`cat|wc -w`
7  end_time=`date +%s`
8  speed=`echo "scale=2; $words / ( ( $end_time - $start_time ) / 60
)" | bc`
9  echo "\n\nYou have a typing speed of $speed words per minute."

If you save the above shell script as and make it executable, you are ready to measure your typing speed. Oh, I forgot one thing, that is a piece of text to type. It is always good to have some text ready so that you’ll know what you type. In this case I prefer the first few lines of the Usenet message of Linus Torvalds in which he announced the birth of Linux:

$ ./

Start typing a piece of text. Press Ctrl-d twice to finish.

Hello everybody out there using minix -

I'm doing a (free) operating system (just a hobby, won't be big and
professional like gnu) for 386(486) AT clones. This has been brewing
since april, and is starting to get ready.

You have a typing speed of 43.33 words per minute.

Well, 43.33 words per minute is not a world record for sure (and I definitely had better scores, believe me!). According to the relevant Wikipedia article, “as of 2005, writer Barbara Blackburn was the fastest English language typist in the world, according to The Guiness Book of World Records. Using the Dvorak Simplified Keyboard, she has maintained 150 words per minute (wpm) for 50 minutes, and 170 wpm for shorter periods. She has been clocked at a peak speed of 212 wpm.” I don’t know, maybe it is time to switch to the Dvorak simplified keyboard but I have my doubts.

The tiny utility above helped me to have a rough idea about my typing speed. Certainly it lacks some important features. It would be nice if:

  • It included various texts and showed them in a random order so that the average performance of different typing sessions can be calculated. A single measurement is hardly a reliable indicator when it comes to this kind of benchmarking.
  • It had the option of getting sample texts from files.
  • It took into account the number of errors made by the typist. This calls for a small function that can compare the sample text and the input of the typist. It does not mean much if your performance is 1000 wpm but 90% of it includes terrible errors, typos, etc.

The three points above are left as an exercise to the Linux Journal reader.

Happy hacking and typing.


Emre Sevinç currently works as a software developer and researcher. He's been involved with GNU/Linux since 1994 when he first met it at the math department of Istanbul Technical University.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

i just can type with two

rafel's picture

i just can type with two finger until now...

Cool script! Thanks :)

mitsubishi klima's picture

I think you should replace "echo" with "echo -e".

Improved version

JD's picture

I agree with several of the posters, and found a couple of additional improvements. First, if you use wc -m, it will not bail out when you press a carriage return. Second, I've counted the characters, and incorporated an operation to compute the number of words (using the standards 5-characters-per-word). It could be rolled into one feed to "bc" but I've separated them to make it clearer. The computation equation in the article is also missing a closing parenthesis (which causes a syntax error) and a closing double-quote. Finally, if you do press a carriage return, the routine will exit with just one CTRL-D, giving a slightly more accurate measure. Here's the script.

# a very tiny utility to measure typing speed.
prompt="Start typing text. Press Ctrl-d twice to finish."
echo $prompt
start_time=`date +%s`
chars=`wc -m`
end_time=`date +%s`
words=`echo "scale=2; $chars / 5" | bc`
speed=`echo "scale=2; $words / ( ( $end_time - $start_time ) / 60)" | bc`
echo -e "\nYour typing speed was $speed words per minute."

I have to agree with acsaf,

Coco's picture

I have to agree with acsaf, "echo -e" will be good.

Coco -

script error?

acsaf's picture

I think you should replace "echo" with "echo -e".

Wrong words

Mockman's picture

For calculating typing speeds, a word is five characters.

And FWIW, I think the Wikipedia article that you reference is more of a marketing vehicle than anything else.

#!/bin/sh considered harmful

WaltS's picture

Beginning your Bash script with "#!/bin/sh", rather than "#!/bin/bash" limits Bash to sh-like behaviour, which is different.

Reg: the error in the script.

balaji's picture

balaji@balaji-laptop:~/Desktop$ bash
\nStart typing a piece of text. Press Ctrl-d twice to
finish. \n
Hi, this is Balaji.
(standard_in) 2: syntax error
\n\nYou have a typing speed of words per minute.

" I get this standard_in syntax error. Please help me on this issue. Thank you very much for this article. It is more helpful.

I use dvorak too

tzar's picture

I typed at 70WPM and made several attempts to switch to dvorak. On the third try, I stuck with it and regained my speed after about 3 months. Now, just over a year later, I type at 110WPM and have peaked at 120WPM with no practice, just normal typing from work (I'm a programmer). Dvorak makes you use your right pinky finger a hell of a lot more though, I remember it being very sore at times until my finger muscles trained :P

Dvorak indeed

Anonymous's picture

I switched to Dvorak about 8 years ago (wow, has it been that long?!), mainly due to some pain that was creeping into my wrists. I was reasonably fast on QWERTY, so I don't really type faster on Dvorak. But the optimized layout allows my fingers to do the same amount of typing with less work!

egregious use of CAT's picture

cat is unneeded in this script!

wc -w will happily take input from STDIN by default, so there's no need to add an additional command in front!

Most unix utilities accept input from STDIN. No need for cat up front!

See here for many many more examples:

dvorak > querty

nord's picture

Cool script! Thanks :)

"I don’t know, maybe it is time to switch to the Dvorak simplified keyboard but I have my doubts."

I had doubts too, but try it, and you'll discover its great potential.

setxkbmap -layout en -variant dvorak Thats all you need to do for English dvorak.. (on debian at least)
setxkbmap -layout no -variant dvorak gives the "Norwegian Dvorak layout". To get started aptituded the program "dvorak7min". I changed to dvorak a month ago and now speed is getting quite good. Almost on par with my querty typing, and still improving fast! Dvorak is extremely comfortable in comparison to querty!