For UNIX itself, there are also various titles. IBM® mainframe users say a variety of jargon with the letter "Z", such as IBM z/os® and System z9 Virtual Machine (Z/VM), nested system developers use the word eCos, and other UNIX-like flavors mentioned in the chat, such as Linux ®, FreeBSD, Sun Solaris, and Mac OS x. Modern information technology uses a variety of dialects, almost like the story of the Betta of the Bible.
Of course, there are also many people who say Windows terminology, although most people only master the simple words "point and click". After 20 years of development, most Windows users have forgotten the old DOS terminology.
However, the functionality of the Windows command utility is really poor compared to a Unix shell, so UNIX users often think of windows as a frustrating platform. Windows is especially awkward for UNIX software developers who are accustomed to using a rich set of command-line toolsets. For UNIX developers, the use of Windows is almost as strange as a foreign country.
Fortunately, Cygwin (see Resources) provides a familiar piece of space in the Windows environment, as Americans find McDonald's in France.
Cygwin is a UNIX-like shell environment for Windows. It consists of two components: a UNIX API library that simulates many of the features offered by the UNIX operating system, as well as a rewrite version of the Bash shell and many UNIX utilities that provide a familiar UNIX command-line interface. The previous component is a Windows dynamic-link library (DLL). The latter component is a set of programs based on the Cygwin DLL, many of which are compiled with unmodified UNIX source code. They all come together to provide a familiar UNIX environment.
In this article we will install Cygwin, discuss its command line interface (CLI), and build an open source that is not included in the standard Cygwin release to realize how easy it is to migrate UNIX applications (at least a subset of UNIX applications) to this simulated environment.
Installing Cygwin
Unlike the other software described here, Cygwin uses Windows installer. Cygwin setup.exe files You can reinstall the software to add, modify, or upgrade components that are Cygwin configured.
Open the browser on the Windows system and download the Cygwin installer by accessing Http://cygwin.com/setup.exe. The installer itself is very small (about 600KB) because most of the Cygwin software is downloaded during the installation process. After the download is complete, follow these steps to install Cygwin:
- Run the Setup program. Figure 1 shows the Cygwin Welcome screen.
Figure 1. The first dialog box that appears during the installation of Cygwin
- Click Next to go to the next screen and select the type of installation you want to perform.
- Click Install from the Internet.
- Click Next, and then select an installation directory.
Configure the installation window as shown in Figure 2.
Figure 2. Cygwin Installation Options
In most cases, the recommended installation options are appropriate and can be customized, but note the following:
- Do not install Cygwin in the root directory of the Windows system (for example, C:). It is best to install Cygwin in its own subdirectory, such as the default directory (C:\cygwin) or C:\Program Files\cygwin. (The target directory you select will be the root of the emulated UNIX environment.) For example, if you install in C:\cygwin, the virtual/usr/bin is actually C:\cygwin\usr\bin).
- For the Install for option, do not select Just Me.
- Set the default Text file type to Unix to maximize compatibility with existing files stored on other Unix machines.
5. Click Next.
In the next window, select a directory that stores the data required for Cygwin. do not select the Cygwin directory that you selected in the previous step. if possible, create or select a directory on a drive with at least 1GB of free space.
6. Click Next again to select the type of Internet connection you are using. You should usually choose Direct Connection.
7. Click Next again.
Wait a moment, Cygwin will download the current list of mirror sites, allowing you to select a mirror site, as shown in Figure 3. If you are unsure which site you should choose, choose a site that is near your location.
Figure 3. Choose an installation site that you think is reliable or geographically close
After a brief delay, the installer displays a complete list of available categories and packages. Figure 4 shows some of the contents of a category. Click the plus sign (+) to expand the corresponding category, and click the loop flag to cycle through skip (ignoring this package) and all available versions of the package. If Cygwin provides multiple versions of a utility, you should choose an instance that meets your needs. By the way, if you choose Column B, you will download the binary package, and select S to download the source code.
Figure 4. Choose the package and instance that best suits your needs
There are more than 1,000 packages available in Cygwin, so you should only select the categories and packages you need. (Installing all Cygwin packages consumes more than 800MB of disk space.) You can add an entire category or a separate package at any time later: simply rerun the Cygwin Setup program. (You can also delete or update the package at any time with the same setup program). Search for a list of Cygwin packages (see resources) to check if your preferred UNIX utility is available in Cygwin.
8. After selecting the tool you need, click Next and start the download process!
The progress bar reflects the download progress, total download progress, and disk usage of each package, respectively. Figure 5 is a screen diagram that was intercepted during installation on my test computer.
Figure 5. Cygwin download a lot of software, so please wait patiently
Finally, the installer installs the software and (optionally) adds a shortcut to the Start menu and to the desktop. Click Finish
9. Start Cygwin by using the Start menu or by double-clicking the Cygwin icon (if you have added these shortcuts), or you can execute Cygwin scripts (such as C:\cygwin\Cygwin.bat) in the Cygwin directory.
Figure 6 shows what happens when you start Cygwin for the first time: it creates your home directory, executes the shell startup file, and displays the prompt. Now it's time to run UNIX commands!
Figure 6. You can now use UNIX commands in Windows!
For example, try ls-a or type touch. The latter command indicates that touch is an executable file/usr/bin/touch.
The advantage of UNIX in Windows (and vice versa)
Cygwin simulates a UNIX shell almost completely in Windows. In fact, it combines the two operating systems nicely together. For example, you can run the df-h command to display free disk space on the UNIX machine. Figure 7 shows the results.
Figure 7. is the UNIX file system on Windows, or the Windows file System on UNIX?
As mentioned earlier, the Cygwin installation directory acts as the root directory for the virtual UNIX system. Cygwin maps subdirectories in the installation directory to UNIX directories. It provides Windows drives in the form of a separate volume, such as/CYGWIN/C. You can use such a virtual path to start a Windows program. Please try entering
/cygwin/c/program\ files/internet\ Explorer/iexplore. Exe
Start Windows Internet Explorer® from the command line. (You can also use the Tab key to automatically expand the elements of the path.)
By the way, if you want to convert the Windows pathname to an equivalent UNIX pathname or vice versa, you can try the built-in command
Cygpath. By default, Cygpath produces a UNIX pathname. Use the-w option to produce a Windows path.
$ cygpath-w/cygwin/c/program\ files/internet\ Explorer/iexplore. EXE C:\Program files\internet Explorer\iexplore. Exe |
There are other features that help communicate these two environments:
- Cygwin provides its own LPR (/USR/BIN/LPR instead of Windows LPR. EXE), which can be printed directly from a simulated UNIX environment. Just set the PRINTER environment variable to a Cygwin UNC such as \\server\printer_name or//server/printer_name, both forward and backward slashes, as well as elsewhere in Cygwin.
- Symbolic links created in Cygwin with ln-s are interpreted as shortcuts in Windows. Similarly, Windows shortcuts are interpreted as symbolic links in Cygwin. Therefore, you can use Windows shortcuts to start UNIX commands with parameters.
- Because Cygwin provides a full Bash shell, you can use all of the above compatibility features (and other features) to write UNIX shell scripts to maintain windows!
For example, you can use the UNIX find
Search for data on the drive. Note One thing: spaces are often used in Windows filenames. In order to maintain the full file name (remember that UNIX parameters are separated by a space), be sure to use find-print0 and xargs-0.
See Figure 4. Expand the Devel category and use the loop control to select the highest version of the following packages:
autoconf2.1
automake1.10
Binutils
Gcc-core
Gcc4-core
Gdb
Pcre
Pcre-devel
After making a selection (in order to satisfy the dependency, other packages may be selected automatically), click Next to start the update. As before, the download and installation process takes some time (the development package is often quite large). Resources
Conclusion
Cygwin is not a perfect UNIX simulation environment, but it's pretty good. The documentation for the core components is perfect and particularly handy, and they describe the limitations and security risks in the emulated DLLs.
Perhaps the best feature of Cygwin is its integration with Windows. Using Cygwin and its UNIX command line to manipulate the system can greatly increase productivity. It is recommended that you include subdirectories in Windows program Files in your shell path variable, so that you can start any binaries in the path by simply entering the name of the application.
Even better, Cygwin can manage multiple jobs in the same window. Press Control-z to pause a running job, enter BG and FG to run the job in the background and foreground, and enter the jobs management job list. Of course, the Cygwin can also redirect inputs and outputs, which can be piped to send the output of one command to another command.
Cygwin how to use