Windows based programmers... Stop hating CLIs (Command Line Interfaces)
August 18th, 2008
If you are a unix/linux lover, this article may not be of interest to you, because you should be knowing the power of CLIs in *nix operating systems. But, for a windows programmer CLIs are kind of a derogatory thing. They usually have the perception that, "If you don't have a nice looking, user-friendly GUI, then it's not for me". I agree that to some extent for a regular, non-savvy windows user. But, I don't think it makes sense to someone who has some knowledge of developing or maintaining software. I should admit, I have been like that for many years, until I realized the power of CLIs and how it can help leverage the day to day task in a software development environment.
Just like most of the developers, I consult to a client whose workstations are windows based. But, my personal PC & servers at home are primarily Linux based. The scope of this article is only to emphasize the usage on CLIs and not to compare Windows against Unix based OS's, so that a windows user can benefit from the best of both worlds.
Alright, let's get to the real story here. A colleague of mine was working on a project where he had problems updating code from CVS. He uses IntelliJ IDE for development. For some reason he couldn't update the codebase either thro IntelliJ or WinCVS client. He has to copy the entire codebase from someone who had successfully updated the codebase and manually change the CVS metadata info with his user id, so that he could successfully commit the files he modified. Needless to say it's a very painful and tedious process. I am sure, anyone who had used version control systems like CVS or Subversion would have encountered problems similar to this. So, what's the solution. Well, you can search the project folder for text containing the other person's user id and manually edit those files to update his user id. It would take considerable amount of time to do this depending on the number of files that needs to be updated. And also, the chance of making errors are quite high.
I offered him a solution where he can perform this tedious task in 2 easy commands. Thanks to cygwin for making this possible. I really like to thanks cygwin's team for providing this wonderful tool for people like me who works on windows systems and able to get the best of command line support offered by Unix based operating systems. Here are the 2 commands he has to run to replace his user id(For ex. A) with some one else's user-id(For ex. B). You can do this in one line command, but for him to know which files got modified, I wanted to do this as a 2 step process.
# Command to update CVS Root metadata (replace user A with user B) find . -type f -name 'Root' | xargs perl -pi -e 's/:pserver:A/:pserver:B/g' # Delete the .bak files after the change find . -name 'Root.bak' | xargs rm -f
This is just a tip of the iceberg. You can do much more things in command line using Cygwin. I know its little annoying to go thro man pages and find out the options you need for a command. But, if you figure out the command once and you can use it whenever you need. I am sure Cygwin would be a very valuable addition to a windows based developer's toolbox.
So, that incident inspired me to write an article on CLIs. I have been compiling the list of commands that would be useful for windows programmers. Here are some.
# Cleanup the codebase by removing all the CVS metadata files
find . -name ".cvs" -type d -exec rm -rf {} \;
# Cleanup the codebase by removing all the Subversion metadata files
find . -name ".svn" -type d -exec rm -rf {} \;
# Print the list of files that was modified in the past 1 day
find . -mtime 1 -print
# Command to watch tomcat's log file in realtime without the need to refresh.
# Will be very useful when you are trying to debug or test something
tail -f $CATALINA_HOME/logs/catalina.out
# Find files larger than 1 Mb in current directory
find . -size 1M -type f
# Count no. of .java files in the current codebase
find . -name \*.java -print|wc -l
# List tomcat log files which are older than 30 days
find $CATALINA_HOME/logs -type f -mtime 30 -print
# Move tomcat log files to 'C:\archive' which are older than 30 days
find $CATALINA_HOME/logs -type f -mtime 30 -exec mv {} /cygdrive/c/archive/ \;
Please feel free to add more commands by posting them in the comments section.
2 Responses to “Windows based programmers... Stop hating CLIs (Command Line Interfaces)”
Sorry, comments are closed for this article.

August 19th, 2008 at 07:04 AM Cygwin rocks! That usage of "xargs perl" is very useful.
August 19th, 2008 at 07:37 AM I wrote a couple of posts some time back on pimping up the CLI on Windows. One was on how to use ZSH and the other was to tweak the default cygwin installation.