Subscribe to How-To Geek

Recommended: Click Here to Run a Free Scan for Common PC Errors   [Sponsored Link]

How to display a list of recent commands in Ubuntu Linux

Linux has a rich command line experience that can sometimes be a little daunting for people switching over from Windows. Displaying the list of recent commands is pretty simple, though:

> history

1 ps -ef
2 kill 24188
3 ps -ef
4 tail logfile.log

If you want to find a command that you used before but you have a huge history list, you can quickly find it by passing it through grep. Let's say we remember typing the ftp command, but can't remember the domain name of the server:

> history | grep ftp

321 ftp ftp.cdrom18.com

Pretty simple stuff! What if we want to display the list of items that we use the most often?  We can use a much more complicated command like this:

> history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r

114 ls
105 ./runreports.sh
97 cd
24 uptime
15 mysql
13 vi

The last command was thanks to Lifehacker, which is a great site you should definitely subscribe to.

The techniques used in the last command are useful in other contexts. I'll be posting more similar commands going forwards.

The Geek is the founder of How-To Geek and a geek enthusiast. When he's not coming up with great how-to articles, he's probably writing at his personal blog. This article was written on 10/4/06 and tagged with: Ubuntu, SysAdmin

Leave a Comment




Leave your friendly comment here. If you have a computer help question, leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Copyright © 2006-2008 HowToGeek.com. All Rights Reserved.