Simple Unix Like commands using C#

This article presents some small toy console applications that emulate the Unix command like behavior on Windows.

Background

A while ago, my cousin (age: 10 years approx) came to me and asked me to install Unix on his computer. I asked him why he needed that, as a 10 year boy has little to do with Unix. He then told me that he needed to practice an assignment that involves running some Unix commands. He showed me a list of commands that he needed to run.

  • ls
  • cd
  • pwd
  • mkdir
  • rmdir
  • cp
  • mv
  • rm
  • cat
  • more
  • grep
  • whoami
  • ps

I was not ready to put Linux on his machine just to run these basic commands. I could give him something like “cygwin” or “coreutils” and he would be fine. Then I thought, Windows already has these commands but with some other names so why not just create a wrapper around those and/or write simple 2-3 line programs to emulate these commands. So I spent half an hour in front of the computer and created these basic commands. Although they are not a very good replacement for the real Unix environment, I guess it was good enough for that 10 year old boy’s assignment. So here I am sharing these small utilities.

Using the Code

After I was done with this small exercise, the status of commands was:

So let us look at the small code snippets written for these tiny programs.

ls

pwd

cp

mv

rm

cat

more

grep

whoami

ps

NOTE: Check out the source code for implementation.

IMPORTANT: The folder that contains these commands should be added in the PATHenvironment variable.

Points of Interest

At the end of this exercise, I thought about what I did and the only thing I could think of is that perhaps I should have used C++ to implement these commands. That way, I could relieve the users from the burden of having the .NET runtime on their system. But since it solved my purpose, I didn’t spend much time on it later. Perhaps, when I get time, I would like to do some more things like:

  • Having all the Unix commands implemented and not just these few
  • Write similar programs in C++
  • Perhaps write the wrappers for Unix like system calls to work on Windows

I will get to these activities once I get some free time from my “real” job.

Download sample code for this article: unixlike_src