1

Some background, I am making the mental effort to start using command line interface for all my work, on Windows, Mac OSX, and LINUX systems. It is true that we have a lot more flexibility in the command prompt over GUIs, and I can readily see this.

My problem is that I am rapidly getting lost in the forest of terms, CLIs, this system working with that system issues, etc etc. I usually google/wiki a particular program, but I am having a hard time 'glueing' all of them together.

I would appreciate someone glueing them coherently.

For example: On my Mac OSX, I have setup 'Iterm2' as my command line interface. On my LINIX system, I understand that 'Terminator' is a good one to use, and I plan to use that. Since I also want to use CLI on windows, I installed 'conEmu', which has been good thus far.

Now...here is where it gets confusing for me...: On my windows system I have also installed git via mysgit. This gives me a 'gitBash'. In the gitBash I can use LINUX commands, but not windows DOS commands. In the Windows command prompt, I can use DOS commands, not LINUX commands. However I would like to use LINUX commands in windows only, and so (I am told) that Cygwin is a good contender? But why have that when I have gitBash? Does it matter? Can I run any windows command through a LINUXy emulator like gitBash/Cygwin?

You can see the knot that I am trying to un-knot here, I am not sure how they all 'fit' together.

My ultimate goal is to simply be able to use LINUX commands on my windows machine, from a command line interface, without any fuss, if possible. I am getting lost in all the detail.

Thank you.

6
  • if you have cygwin installed you probably don't need gitbash which i guess is installed when you install windows git. My suggestion is to uninstall all the unixy programs like git that you installed without cygwin, then install them via cygwin and stick with cygwin. then do a tutorial on the unix command line. a quick google yielded this link: ee.surrey.ac.uk/Teaching/Unix/unix1.html Commented May 29, 2014 at 13:52
  • but even better would be to install a proper unix/linux environment. you could do that in a virtual machine if you don't want to dual boot or overwrite your windows install Commented May 29, 2014 at 13:55
  • Thanks @JasonLewis. When you say 'install them via cygwin' - I get a little confused. As far as I am aware, we can install stuff via package managers and such... so what do you mean install via cygwin? Thanks! Commented May 29, 2014 at 14:01
  • re-run the cygwin setup.exe command and select anything you want that is missing, for example git stackoverflow.com/questions/15692890/… Commented May 29, 2014 at 14:03
  • superuser.com/questions/304541/… Commented May 29, 2014 at 14:03

1 Answer 1

2

If you want to do as you've stated, I would recommend using CYGWIN.

The installer is mature and lets you choose what commands and functions you want. The defaults will get you pretty much anything you would need and then you can extend and tweak later on.

First you need to understand the difference between a Terminal and a command environment (AKA "shell"). The former allows access to a remote or local system at a low level, the latter is what is run when you connect via the terminal. This is true across all systems it is just rather better hidden in some than others. It is also worth noting that command environments contain built-in commands such as the UNIXy ls and the DOSy dir but that all systems have other "command line" tools, for example ifconfig on Linux and ipconfig.exe on Windows. It can be hard to differentiate between them but you will sometimes get tripped up when trying to execute a UNIXy command on Windows. Many of the best UNIXy command line tools are also available for Windows however, either through CYGWIN itself or via native versions. For example, the excellent exiftool that I use for batch renaming photo's on both Linux and Windows.

So you are able to replace the terminal with something more fully featured if you need it such as Lterm2 on your Mac, even Windows has a couple of alternatives though personally I wouldn't bother - more trouble than its worth.

On Windows (newer versions anyway), the default command environment is cmd.exe. It is nowhere near a featureful as it's Linux equivalent BASH. On Linux, BASH is the most common standard but you may come across others such as ASH, Korn Shell, SH and others. Windows actually provides several other command shells, the most common and powerful being PowerShell. PowerShell is so powerful because it is able to use and expose interfaces for most of the .NET libraries of which there are a great many doing all sorts of clever things. It is also Microsoft's chosen administrative shell so you use it for maintaining remote systems (both servers and clients) and even cloud services such as Office 365 and Azure. If you want to be a Windows system GURU, PowerShell is essential learning.

Back to your question though. You can easily run BASH via CYGWIN which installs it and a number of supporting commands. CYGWIN not only gives you a UNIXy way of interacting with drives, files and folders on Windows machines, it also makes available things like the Windows Registry in like manner.

Of course, there are other limits. For starters, the folder layout on Windows will always be different to Linux or MAC hosts and you will have to allow for that in any scripts that you write if you want them to work across all platforms.

You can, of course, continue to use gitBASH but you are likely to find that it doesn't have some of the commands you might expect to be available. You would have to just try it and see. If you do go down that path, when you find a missing command, you can just search for it online, it may be available as a native Windows executable and therefore should be usable from gitBASH if placed in a folder on your PATH.

Clarification 1: If you are used to Linux, you will be familiar with the fact that each distribution has a "package manager" that helps with the installation of software from recognised & (hopefully) trusted sources. They help ensure that you have all of the components and dependencies required. CYGWIN uses its "installer" for the same purpose though it is a lot simpler. Remember, most Linux tools are compiled for use on Linux (generally you need to know the type of processor you are using plus you need a load of internal dependencies from the Linux "Kernel"). To use Linux commands on Windows requires that they all get recompiled to work on a Windows platform. There is a helper library that allows this to be relatively painless (MSYS? anyway, you don't really need to know that).

You are correct in saying that Chocolatey is an attempt at a package manager for Windows. One of Windows' great failings is the lack of a single, trusted, recognised package source - or "App Store" as is now the craze for calling these things! With W8, Microsoft are trying (not all that well it has to be said) to rectify that but currently it is very limited - aimed at mobile and ModernUI apps.

However, many Windows developers have long used a tool called NUGET to help package up applications for installing on Windows. NUGET makes use of PowerShell behind the scenes. Chocolately is a set of scripts built using PowerShell and NUGET to help automate installations. It works OK but still doesn't command the widespread support it should probably have. It is easy enough to create install packages for Chocolatey, I did my first a couple of weeks ago for the Open Source Freeplane mind-mapping tool.

But, as you say, there is no connection at all between Chocolatey (using PowerShell) and BASH on CYGWIN. In your example, you will need to decide where and how you want to use VIM. If you only ever want to use it in the context of CYGWIN then install it via the CYGWIN installer. However, if you want to use it as a general Windows editor, you might be better off installing via Chocolatey. Unfortunately, there is no easy way to predict which would be best. You might even end up doing both. On the other hand, you might find some Windows applications also work fine when called from BASH and others won't!! Pain huh!

UPDATE 2: Did I mention you should stick to PowerShell!! Welcome to the world of cross platform working. CYGWIN wants its own Python package installing to satisfy internal dependencies. Using native Windows Python (such as installed through Chocolately, or manually) might work but then again might not. No easy way of telling but it is highly likely that you will hit a problem eventually if you don't have the Cygwin package installed. This is why someone else recommended using a virtual machine instead so that you keep things clean and separate.

Honestly, you might be better off accepting that you need to learn different tools for different platforms. It isn't that hard. It really depends on what you want to do. If you want to learn Linux command line, use a virtual machine. If you want to automate Windows tasks, learn PowerShell or alternatively, if you already know Python, use that instead! So many options!

4
  • Thank you for the rundown Julian, much appreciated. May you please expand your answer vis-a-vis the myriad number of package installers? For example: Let us say I have installed Cygwin, and of course, I have cmd.exe. Now, through cmd, I have installed chocolatey. It seems to me that I CANT use chocolatey if I was on Cygwin. However if I was to go to cmd, I would be able to use it, correct? By the same token, let us say I want to use the program 'vim', that I know is on LINUX. Can I now only use it via CYGWIN, and not cmd? Thanks Commented May 29, 2014 at 16:25
  • Updated as requested! Commented May 29, 2014 at 17:01
  • Thanks once again Julian, I have accepted your answer! By the by, since you have used chocolatey before, might you try your hand at this question of mine? Many thanks! Commented May 29, 2014 at 17:06
  • Julian - here is a good example: I have already installed Python34 on my machine. However now in the process of installig Cygwin, it is asking me if I would like to install 'The python package'. ... I do not know what to do here. Why is it asking me about Python at all? If indeed it is wondering if I want python, then should I install python through cygwin so that I can use it through cygwin? Or since I already have it, should I be able to use it anyway? ... :-/ Commented May 29, 2014 at 17:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .