Attributes cygwin installation. How to execute a Linux command from Windows. Using the native Cygwin Terminal

This article will be useful for novice Cygwin users. To begin with, we first need to answer a simple question. What is Cygwin? Cygwin is a UNIX-like environment and command line interface for Microsoft Windows. IN Microsoft system Windows already there is a similar cmd interface. Call command line You can use the Win+R key combination. But often most of the work Windows users has to be done manually. On the other side of Linux, the user has long written a bash script and sits drinking beer on the sidelines of the automated workflow.

So what prevents you from doing this on Windows? That's right, absolutely nothing interferes. But for this we need additional programs and libraries. Cygwin extends the capabilities of the standard Windows command line, allowing you to automate some processes and develop programs for Linux and other systems.

The Cygwin program can be downloaded from the official website: Link to the 32-bit version of the program and Link to the 64-bit version of the program.

Select the desired version, download and run the executable file setup-x86.exe and setup-x86_64.exe, respectively.

Installation window for the 64-bit version of the program


Window for selecting installation method


Package selection window

The installation window for the 32-bit version of the program looks exactly the same as the 64-bit one. The next step is the selection window. Where to install or download the program. There are three options in total. The first option is Install from Internet (downloaded files will be kept for future re-use) installation from the Internet and downloaded files will be stored until the next reuse. The second option is Download Without Installing. Download without installation. The third option is Install from Local Directory. Install from a local directory. Because We don’t have a local copy and we need to install it, so we select the first option. The next window will be to select the installation path. I recommend choosing system disk, for example, my Cygwin installation path is C:\cygwin64. The next window is to select the path where temporary files will be stored that will be downloaded during the installation process. For me it is C:\cygwin64\package. Then you need to choose whether to download through a proxy or directly. The next step is to select a download repository, select any one you come across or the default one and click Next. After clicking the button, the process of downloading the main configs will begin. Next you can choose what to install. To select a package, click Skip next to the package name. List of packages that will be useful to you:

  • gcc-core (under Devel)
  • gcc-g++ (in the Devel section)
  • make (in the Devel section)
  • cmake (in the Devel section)
  • automake (in the Devel section)
  • wget (in the Web section)
  • libiconv (in Devel and Libs sections)
  • openssh (in the Net section)
  • nano (in the Editors section)
  • bash (from the Base section)
  • base-cygwin (from the Base section)
  • base-files (from the Base section)
  • cygwin (from the Base section)
  • file (from the Base section)
  • gzip (from the Base section)
  • login (from the Base section)
  • mintty (from the Base section)
  • openssl (from the Base section)
  • run (from the Base section)
  • tar (from the Base section)
  • vim-minimal (from the Base section)
  • cron (from the Admin section)
  • shutdown (from the Admin section)
  • git (all packages from the Devel section)

I didn't like the background color or the built-in font and text color, so I customized it. With these words I will end this article.

Tags: cygwin, for beginners

In order to write applications for Unix it is not necessary to install it (under the word Unix I will think through everything *nix systems). This statement sounds rather paradoxical, but it is true, and in this article I will try to convince you of this.

If you are not a true Unix guru, then in order to write a couple of applications for this OS or compile existing programs you don't need to install at all Unix. An emulator is perfect for these purposes. Unix. There are many great programs that do this task perfectly, for example: UWin, MinGW, Cygwin and etc.

For compilation simple programs will do and MinGW, but for more complex ones it is not suitable. Uwin is a more advanced emulator, but its functionality is significantly inferior to another more popular emulator Cygwin.

Cygwin- it is very functional, free emulator Unix. It is distributed as a single file ( setup.exe), don't be fooled by the size of this file ( ~300 kb), this is not himself Cygwin, but only its installer. All necessary utilities and libraries will have to be downloaded separately during the installation process, or you can specify a local directory as the source if you already have the necessary files.

Cygwin includes a huge number of different utilities and libraries, many of which you will probably never need, but when installing Cygwin allows you to select only the components you need. Thus, if you only want to compile the program, then you will only need to install the compiler GCC, a set of necessary libraries and utilities make. Personally, I installed all the applications because Cygwin makes it easy to “get rid” of them at any time. In fact Cygwin consists of just one file cygwin1.dll, everything else is software packages GNU, specially recompiled to work with Cygwin.



I think there were no problems with the installation. Now let's look at a few subtleties in setting up and using Cygwin. After installation, the structure of the folder in which the program was installed will resemble the structure *nix systems. In order to launch Cygwin, just run BAT file, cygwin.bat, which is located in the root directory Cygwin(by root directory we mean the folder in which the Cygwin, in the future we will count from this catalogue). After launch BAT file will appear before you console application. This is the one Bash, which is link between Unix And Windows. Bash- this is not just an analogue cmd.exe. Bash is a full-fledged programming language in which you can write scripts to perform various tasks. This is precisely what makes it fundamentally different from cmd.exe (command.com).

Invitation Bash, practically no different from cmd.exe (~ - means your home directory). There are no logical drives here (A, C, D, etc.), the countdown is from the root directory designated " / ". You also need to remember that case is important here, so Etc And etc- two completely different catalogs. Let's try to go to the root directory, to do this, just run the command familiar to you " cd/" (~ should change to / ). After that, type the command " dir", or " ls", in order to view the contents of the root directory. I think that now you understand what the root directory is.





I can’t describe all the commands in this article, so let’s move straight to the most important stage, for which we actually set Cygwin. Let's try to compile some program. For compilation I chose the program Htop(http://freshmeat.net/projects/htop/), this is an improved version standard program top, which is console manager processes. The first step is to unpack the archive. You can do this as in Windows, and directly in Cygwin. IN Cygwin this is done with the command:

tar zxf htop-0.6.tar.gz

Of course, that in this moment you must be in the same directory where the archive is located htop-0.6.tar.gz. After unpacking, go to the created directory htop-0.6 and execute three standard commands to compile the application.

./configure
make
make install



That's it, the compilation is complete. Feel free to recruit a team htop and admire the result. The resulting "EXE" is located in the directory /usr/local/bin/.



Now let's try to write a simple program ourselves ( Hello world) and compile it with GCC. First we need to write the program itself, we will do this using the program cat. Enter the command cat new.c, Where new.c the name of the file containing the source code. After executing the command, write the following code:

#include
int main())(
printf("Hello World");
return 1;)

After the code is entered, press Ctrl+C. Now let's compile it using GCC. This is done with the command:

Gcc new.c -o new.exe

In the same directory where it was located new.c another file will appear - new.exe. When you run it, you will see the expected message " Hello World".



This could be the end of the article, but I decided to also talk about the graphical environment Cygwin so as not to return to this topic later. I think you noticed that when installing packages Cygwin suggests installing shells Gnome And KDE. In fact, these are not just shells, but their libraries, which are necessary to run applications. For example, a graphical version of the famous editor emacs, will run directly under Windows as if it were win32 application. In order not to be unfounded, let's try this one Emacs run. This is done with the command:

xemacs

This is what we will see.



As you can see, everything starts up and works fine. But this doesn't happen to everyone. The graphical environment is very capricious. Therefore, you need to be able to configure it. Setup Documentation X servers There are a lot of them on the Internet and you can easily find it.

In the end I would like to remind you that no matter how good Cygwin, it's just an emulator. And as you know, a copy cannot be better than the original, so if you want to become a real Unix guru, do not be lazy to install a full-fledged Unix distribution. In my opinion it is better to start with Linux. From all kinds of distributions I recommend you Slackware.

Cygwin is a unix-like environment for Windows. It is often needed to run programs that were developed for Unix-like operating systems. Many of these programs can be installed without Cygwin, but it provides convenient centralized installation and management. With Cygwin you can easily install programs such as OpenSSL, GnuPG, ImageMagick, gvim, gcc, bash, tcsh, emacs and many others.
So let's move on to the installation. First you need to download the installer. This is just a program that will download all the necessary packages and environment, and then install them. Installation is quite simple:




Using this menu you can select proxy settings if you use one.


The program will download a list of mirrors with packages for installation, after which it will allow you to select a mirror from where the packages will be downloaded.


Now you can select packages to install. To make it easier to find, they are grouped according to their purpose. You can also search by package name. Using this menu you can set how binary package(already compiled) and source code (uncompiled package). The Bin column contains the version of the selected binary package; the Src (source code) column can be selected if a binary package has already been selected. The source code will be the same version as the binary package. In order to select a package version in the New column, you need to click on it several times.
After you select all the packages that you need, you can click next and the installer will download and install them. While choosing the packages, I would recommend you these −

This article is intended for two
types of people: for those who do not understand
Linux, but can't install it on my computer
(there are different reasons), or for those who
knows a little about penguins 🙂 and wouldn’t mind
get to know them on a "neutral"
territory, that is, on Win98/NT.

The site has already described Cygwin as the best
take out the Linux emulator, but it was not said
nothing about installation, configuration and bugs of Cygwin.
Here I’ll tell you about it :) Actually, if
come to think of it, Cygwin is not an emulator at all, but
Just Linux distribution, written for Win32 😉

Stop rambling... Let's go to http://www.cygwin.com,
We take the installation program setup.exe from there. To her
we will pull already precompiled ones
binaries (in exe extension), do you remember rpm?
😉 from the developer’s website, or from a mirror.
I RECOMMEND this program only to download
We will install these files manually, because If
you install using setup.exe, gcc does not work - fig
knows why... Maybe the developers have already taken into account
this is a bug, but I don't know about it yet...

So, download all the main binaries (sources
you don’t have to download), and several
additional - who would refuse wget, lynx,
BitchX, Python :) But you don’t have to download Perl... I have
there was ActivePerl - an advanced Perl emulator. Download
available from http://www.acriveperl.com.
I didn’t observe any glitches :) (I’ll tell you how I
implemented it in cygwin).

Settings

And in the "group" file in the same "etc" folder:
root:x:0:root

If you want to encrypt your password, and
not "password" as I did in my example,
write a Perl script

#!/usr/bin/perl
chomp ($pass= );
print $crypt("SA",$pass);

Where, SA - salta, which will be used for encryption
password... you can make it random, but
This article will be off-topic.

Now edit the file "c:\cygwin\cygnus.bat" -
in it we change PATH, simply changing the path to
emulator and the path to the login.exe file. Let's launch
file.

Let's log in: in my example, "root": "password".
So we got into the emulator itself. I don't
I liked the input prompt. Let's change it
- variable PS1. Open (create) the file "c:\cygwin\etc\profile"
and write there:

# /etc/profile
PROFILE_LOADED=1
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/usr/local/sbin:$PATH"
unset DOSDRIVE
unset DOSDIR
unset TMPDIR
unset TMP
export HOSTNAME=test
PS1="[\u@$HOSTNAME \W]# "
LOGNAME=$USER
export PATH PS1 USER LOGNAME

Here... Then we’ll re-login, and everything will be on
place and beautiful :) The invitation will be: # - standard, Linux :)

That's it, the initial installation is complete.
Let's move on to installing services :)

The standard delivery includes thuja hucha
services. You need to run them like this:
/usr/sbin/inetd -R /usr/sbin/in.ftpd (example for ftpd).

It’s better to install SSHD yourself - it worked with a bang and
I drive from SecureCRT, legal on 127.0.0.1 -
completely different look :)

As for working with TCP/IP, I have no disadvantages
I noticed :) Everything connects and works like
necessary...

And now some tips:

1) Access to ALL disks is open. So be
careful. For example, drive d: is located here -
"/cygdrive/d".

2) Regarding Perl, create a symlink to the file
Perl.exe, for example, so "ln -s /cygdrive/c/perl/bin/perl.exe
/usr/bin/perl"

3) If for some reason you don’t have
installing a Linux application -
just fix the C code. May be,
will succeed.. (that's how I compiled
micq).

4) Follow Cygwin updates on the website http://www.cygwin.com
- binaries are updated frequently.

Questions? Write to me by E-Mail - I'll try
help...

If you sometimes still use a Microsoft operating system, you probably really need some Linux utilities in Windows. It would be very convenient to use standard command line utilities for filtering output, sorting, filtering and streaming editing, on Windows where such functions are not supported.

There are several solutions to implement this. In this article we will look at only two of them. The first one, which you may have already heard about, or maybe already use, is Cygwin. Second, something more interesting and new - Cash. Let's start with Cygwin. IN latest version Windows 10 has introduced a third solution - the ability to do it natively, using a special subsystem. Read about this in a separate article.

Cygwin is a set of tools that provides Unix-like environment on Windows. You cannot run existing Linux utilities here. To execute a Linux command from Windows Cygwin, it must first be recompiled.

Nevertheless, quite a lot of software has already been rebuilt. Cygwin gives you a Linux-like environment with many of the utilities you're already used to on Linux. It can be used both for standard utilities such as the cp windows command, and for connecting to remote server via ssh.

Installing Cygwin

Like others Windows programs, Cygwin is installed using an installer in .exe format. You can download it on the official website.

To install, you will have to go through several wizard steps; by default, the program will be installed in C:\Cygwin:

WITH installation package The full set of environments is not supplied. It will be downloaded during the installation process. In this window you need to select a server to download components:

You then need to select the packages to download and install. There are quite a lot of programs available and they are sorted into categories. If you don't know whether you need a particular package, leave the default value. You can install them later:

All that remains is to click Next to start the download and complete the installation.

Adding Cygwin to Path

After installation is complete, in order to execute linux commands in windows with maximum convenience, it is advisable to add the folder with Cygwin executable files to environment variable Path.

You can launch the Cygwin terminal by clicking on the shortcut on your desktop. A terminal will open with the folder C:\Cygwin\bin

Here you can execute all the necessary linux commands in windows, but you will not be able to execute them in another directory or another terminal.

To solve this problem, you need to add the Cygwin folder to variable Path. Open System Properties using a keyboard shortcut Win+Pause/Break, then select item Extra options systems on the left panel:

On the Advanced tab, select Environment Variables:

Find the Path variable in the list and click Change:

Add this entry to the end of the line:

Please note that all paths must be separated by semicolons. All you have to do is click OK and test the execution of Linux commands on Windows.

Cash

This is something completely new. Open utility source code Cash is a cross-platform implementation shell Linux on JavaScript. The goal of this project is to provide a more flexible, simpler alternative to Cygwin for those who want to feel as comfortable with WIndows as they are with Linux.

Once you install Cash, you can run a linux command from windows in any terminal emulator, including the standard Windows command line.

Currently only some are supported linux utilities for windows. Here is the list of supported ones:

  • alias
  • clear
  • export
  • false
  • mkdir
  • source
  • touch
  • unalias

Since the utility is still under development, the list of Linux commands in Windows will constantly increase. You can also vote to add the commands you need.

Here's how it works:

What's most interesting is that you can combine Windows and Linux commands. For example, you can do:

ipconfig | grep IPv4 | sort

And the team will work correctly. ipconfig will be executed first and then the result will be filtered using Grep.

Installing Cash on Windows

I will be installing Cash on Windows 10. It is very simple and works also on older ones Windows versions. Since Cash is JavaScript-based, you need to install Node.js for it to work. You can download Node.js on the official website:

After Node.js is installed, you can proceed to installing Cash. It can be installed in several modes:

  • Manual use of Cash - you need to execute cash to start running Linux commands
  • Global use - linux commands are available in all windows terminals
  • Install only some commands - you can select components to install if you do not want to install everything

To install Cash globally, open a command prompt Windows string using Win+R:

npm install cash-global -g

Installation may take a few minutes, depending on the speed of your Internet connection. Once the installation is complete, you can immediately test Linux commands on Windows.

conclusions

As I already said, the Cash project is still under development and there is a possibility that you will encounter errors. Don't forget to report any bugs you find to the developers to help improve the project. If stability is critical for you, it is better to use good old Cygwin.

Us, Linux users It is not often that you need to use unix commands in windows and such tools. We can use Linux commands directly on our system. But if for some reason you can't install Linux and still want to use linux commands, this can be a great solution.

about the author

Founder and administrator of the site, I am fond of open software And operating system Linux. I currently use Ubuntu as my main OS. In addition to Linux, I am interested in everything related to information technology and modern science.