How to break to new line in cygwin. How to execute a Linux command from Windows


Simple and basically good for everyone. Only the version of Git is not the latest, at least for now. But it is quite enough for everyday work with Git. If we look at the version, we will see:

$git --version
git version 1.9.5.msysgit.0

But if you suddenly need something more recent, you can install Git from Cygwin packages. To do this, of course, you need to install Cygwin itself. There is nothing complicated about this. Let's go here and download the installer. This is exactly installer, A not a distribution. Since it downloads all packages from the network. And besides, it must be used to update installed packages or install new ones.

And so we download

And launch the installer

Do one, two, three

In any case, if you need something later, you can download and install it. As you can see, the Git version in this package is 2.1.4, which is clearly more recent than 1.9.5. Although 2.3.1 is already available for Linux and Mac OS X.

Just in case, I’ll give you a couple more fast servers for downloading

This one is just a fairy tale

Well, that's all set

We launch and see that upon first launch we are told where the configuration files are located:

The picture on the right shows where the user's home directory is located. This is the installation folder (in my case C:\cigwin64), then the folder home, then username folder and it already contains config files .bashrc, .bash_profile, .inputrc And .profile.

All terminal configuration is done in these files. I will not describe this here, since this is a large separate topic.

Let me just note that the main bash settings are made in the file .bash_profile.

You can also note that the Git settings file – .gitconfig – will also be located in the home directory

In addition, you can customize the appearance of the terminal by clicking on the terminal icon in the upper left corner and selecting Options.

If you need any additional packages for Cygwin, you can search for them.

After all the settings, my Cygwin terminal window looks like this. And then we’ll see the version of installed Git.

Well, here we have a full-fledged Git. Now let's (quickly) check its operation on a real repository.

Everything is working.

P.S. What is worth noting once again is that the global and system (global, system) settings of msysGit and Git installed from Cygwin are stored in different places, and do not interfere or overlap each other, in my opinion this is convenient, since everything Windows tools try to write their settings into the global settings file.gitconfig and this can sometimes create inconvenience and confusion.

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. Microsoft Windows already has a similar cmd interface. You can open the command line using the Win+R key combination. But often, users have to do most of the Windows work 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 in Windows OS? That's right, absolutely nothing interferes. But this requires 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 the downloaded files will be stored until the next re-use. 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 the system drive, 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, nor the built-in font and text color, so I customized it. With these words I will end this article.

Tags: cygwin, for beginners

After Chris Kaspersky’s article “How to make Unix from Windows” in KG?3 dated January 23, 2001, I was eager to tell Windows users a little more about what Cygwin is. I have been using it for quite a long time and can no longer work effectively in Windows without Cygwin installed.

The word Cygwin consists of two components: Cygnus is the name of the company, and Windows, but it would be wrong to say that everything in Cygwin was written by the guys from Cygnus. Cygwin is a port of Gnu utilities for Windows, and Gnu (www.gnu.org) is a project of the Free Software Foundation (or simply FSF), with the goal of creating a non-profit, non-owned and free Unix system from licenses that restrict freedom of distribution and modification of software. As part of this project, almost all standard UNIX utilities were rewritten. The three most significant contributions of the FSF are gcc (the Gnu C Compiler, or Gnu Compiler Collection), Bash (the Bourne Again Shell), and Emacs. Without gcc there would be no Linux, and Bash is the standard shell for many modern Unix systems. People with experience say that the first thing system administrators do after installing commercial Unixes is to reinstall Gnu utilities. In principle, GNU and FSF themselves are a vast topic and deserve a separate detailed article.

The entire set of Gnu utilities is a set of small (usually) programs that cover most of the tasks that a user of a Unix system (and not only Unix) encounters every day; each such program performs one task, and performs it well. These programs can then be combined to solve various problems.

Attempts to port Gnu to other, non-Unix platforms have been made more than once, which, by the way, indicates their popularity.

It is worth mentioning the project of porting utilities to DOS - DJGPP. Go to http://www.delorie.com/djgpp/, it's really interesting.

Cygnus did not compile each utility separately, suffering each time to solve the same problems; instead, a kind of “spacer” was written between the GNU utilities and the operating system. This shim - cygwin1.dll (1 - version number) - provides emulation of UNIX system calls, which allows you to compile and execute Unix programs with little or no changes to the source code. Basically, this dll is Cygwin itself, and everything else is GNU software packages compiled to work with Cygwin.

The presence of gcc and libraries makes it possible to port a wide variety of applications to Windows and makes Cygwin a full-fledged platform - you can sometimes find the expression "Cygwin platform". Since the first beta versions of Cygwin, various people have compiled for Cygwin what they lacked for Windows, and the standard Cygwin distribution has gradually grown, including through these home-made compilations. For example, during Beta 20 I had to download the vim editor separately, but now it is installed along with the entire set.

How to install it all

Cygnus has written a convenient program for managing packages, slightly reminiscent of some similar programs from Linux OS distributions. The first step is to download it from the Cygnus website http://sources.redhat.com/cygwin/setup.exe. By launching it, you can download a standard set of packages from one of the many mirrors, and you can choose to do this selectively, skipping individual packages.

For the future - by launching this program later from the same directory, you will be able to see what new packages have appeared or new versions of existing packages.

The same program will install Cygwin for you, again asking you to decide what to install and what not to install. The installation will create directories for you that are common in the Unix file hierarchy - bin, usr, sbin, etc., so it is convenient to place them all in one directory so that they do not get confused with your Windows folders.

And how to use it all

When you start Cygwin, you will see a console window similar to a regular Windows console, command.com in Win9x or cmd.exe in NT. But no! On Windows you launched a glorious descendant of Unix command interpreters, which tried to imitate command.com with its BAT files. Bash and its older brother sh are the glue that binds the Unix system together; it can rightfully be called a programming language, that is, you can write in it.

Several basic commands and their equivalents in Windows

ls = dir - view the contents of the directory;
cd = chdir - move to another directory;
cp = copy - copy a file;
mv = mv - move/rename file;
rm = del - delete file;
mkdir = mkdir - create a directory;
pwd - display the current directory.

Remember - the big "A" is no longer equal to the small "a", the \ symbol must now be replaced with /. The cd / command in Cygwin will take you to the directory where bin, usr, etc. are located. In Unix there is nothing above /, but in Cygwin, in order to travel through Windows partitions, you can use the cd //c/ command (cd //d/MyDir, etc.).

One of the most convenient features of Bash is autocompletion. Let's create several files with the cat command:

cat > first_file ENTER

type something, then Ctr-C,

and the same for another file:

cat > second_file ENTER.

Make sure the files exist:

Now type any command, for example, ls, and the first letter of the first file. Press TAB. Bash will append the file name itself. If the files start the same, such as file_one and file_two, Bash will append only file_ and wait for you to type another letter to disambiguate it.

Several examples of using some utilities.

Let's say you have a text file in.txt. You can count the number of words in it like this:

Number of lines:

Find lines containing the character sequence Larry:

grep "Larry" in.txt

Split lines into words, replacing spaces with end-of-line characters:

cat in.txt | gawk "gsub(" +","\n")"

The gawk command "gsub(" +","\n")" means to replace one or more spaces (" +") with the end of line character ("\n").

Do the same, but with the possibility of convenient viewing (PageUp, PageDown, exit - q)

cat in.txt | gawk "gsub(" +","\n")" | less

Sort strings (words):

cat in.txt | gawk "gsub(" +","\n")" | sort | less

Remove identical lines (words):

cat in.txt | gawk "gsub(" +","\n")" | sort | uniq | less

cat in.txt | gawk "gsub(" +","\n")" | sort | uniq | wc -l

Remove identical lines (words), counting their number:

cat in.txt | gawk "gsub(" +","\n")" | sort | uniq --count | less

Sort again, thus obtaining a frequency dictionary of the text:

cat in.txt | gawk "gsub(" +","\n")" | sort | uniq --count | sort -r | less

The same thing, with the results output to a text file:

cat in.txt | gawk "gsub(" +","\n")" | sort | uniq --count | sort -r > out.txt

The same thing, with intermediate results saved in the intermediate.txt file:

cat in.txt | gawk "gsub(" +","\n")" | teeintermediate.txt | sort | uniq --count | sort -r | less

Now, using the power of Bash, you can repeat this command for multiple files. Type the script directly into the console, going to a new line as printed in the article - Bash will understand that the command is not finished and will change the prompt to ">":

for file in *.txt; do

cat $file | gawk "gsub(" +","\n")" | sort | uniq --count | sort -r > $file.out

Like this. Simple problems - simple solutions.

To find out how a particular command works, you can run it with the --help switch or use the man (manual) command - man awk, man grep. You can exit man using q.

WHAT ELSE IS IN CYGWIN

Compiler

A simple (people say - 1 day of training) word processing programming language, one of the ancestors of Perl

Stream editor

Parser generator in C

Parser generator in C

Programming language. Actually, it is not directly related to Gnu utilities; it was supported by the Sun corporation for some time. You can do cd /usr/share/tk8.0/demos and run the program widget -./widget. You will see a demonstration of the capabilities of Tk, a Tcl extension for creating GUIs.

Archiver

Powerful archiver

File comparison program

And a lot more. Just go to bin and see what you have there. Package deposits can be found at http://www.hirmke.de/software/develop/gnuwin32/cygwin/porters/Hirmke_Michael/GNUWin32-contents.html. There is also a lot of information and links on the topic on the Cygnus website http://sources.redhat.com/cygwin/.

How to set up CYGWIN

First, you don't have to run Bash if you're intimidated by the console. You can use all the programs from Far, Windows Commander, etc., you just need to specify the path to the bin directory. In Windows 9x this is done in the autoexec.bat file, in NT in My Computer / Properties / Environment you need to add the path to bin to the PATH environment variable.

For more convenient work in Bash, I advise you to do the following: if your Cygwin directories are located in c:\cygwin, create a directory c:\cygwin\root (mkdir /root) and add a line to the cygwin.bat file that is in c:\ cygwin:

HOME=d:\cygwin\root

In the root directory you should create 2 files starting with a dot: .inputrc and .bashrc. Both files are executed by Bash on startup, .inputrc is responsible for ensuring that all keys work correctly, and .bashrc contains various information. As an example, I’ll give my .bashrc:

export PS1="\w > "

export PATH=".:$PATH"

alias ls="ls --color"

alias untar="tar xvf"

echo Welcome to CygWin!

The first line specifies the Bash path. This is what Unix does with all interpreters. For example, if you have a hello.pl script in Perl, and the perl itself is in /usr/bin, you can write on the first line:

and run it like this:

This way, you can run programs without worrying about what they are written in.

PS1 is a variable that stores the Bash prompt, the invitation to work, as it is also called. \w is the current directory.

After adding this to PATH, you can do it the way Windows users are used to doing it:

Next, I use synonyms, or aliases. For example, the ls command by default does not color its output depending on what the files are; to do this, you need to run it with the --color switch. This is inconvenient. The alias ls="ls" command --color" I solve this problem. Now ls means ls --color. It is not necessary to use the same command name, you can do ll="ls --color" - and use the new ll command. This is approximately what I do when creating the untar command to unpack tar archives, instead of typing tar xvf every time.You can also put pipes (pipes, conveyors) in alias: alias sort_un_sort=" sort | uniq --count | sort -r ".

In reality, the scope for arranging a workplace here is limitless, and my examples are primitive and simple. There are also functions, interactive commands in .bashrc, functions that run from the prompt...

Cygwin is a set of Unix programs and libraries compiled for Windows OS and placed in the file system in the same way as in real Unix. Thanks to this, we get a complete equivalent of the Unix environment, starting from bash and up to the gcc compilers, which, without much porting of the source code, can be used to assemble projects for execution on Windows (a fairly large number of cross-platform applications use this approach, since it is the simplest and fastest) .

Installing Cygwin

You can download Cygwin for 32 or 64 bit versions on the website https://cygwin.com/install.html. The installation is very simple - you can simply click "Next" to the Select Packages window. Here a database of packages will open in front of you, some of them will already be marked for stopping (basic), others you can mark yourself. In order to mark a package for installation, you need to enter its name in the "Search" field, then expand the categories and find this package. Then click “Skip”, as a result of which the version that will be installed should appear instead of Skip. For further work, mark the package wget, you can leave the rest alone for now. Packages can be reinstalled or removed at any time by simply re-running the installer, but this is not entirely convenient, so later in the article I will tell you how to install packages from the command line (for this we will need wget).

By default, cygwin runs in a standard Windows terminal, which is not very convenient.

Terminal Console

Installing python packages using pip

Packages in python are often installed using pip, which is not available in the sigwin repositories.

Therefore, it must be installed separately:

MAN pages for libc functions

Cygwin already contains manual pages for standard commands, but man pages for libc functions can be installed separately:

By the way, Cygwin is in some way related to embedded systems, as it uses Newlib libc implementation, which is known to be widely used in various ARM toolchains.

Vim in Cygwin

Installation:

The configuration is done in the .vimrc file in the home directory:

I use these settings:

set backspace=indent,eol,start

Syntax enable

set shiftwidth=4

set tabstop=8

set softtabstop=4

set expandtab

set number

set showcmd

set cursorline

filetype indent plugin on

set wildmenu

set lazyredraw

set showmatch

set incsearch

Using the native Cygwin Terminal

The standard Cygwin installer provides its own mintty terminal (launched via the Cygwin Terminal icon). Compared to Console, it is slightly inferior in functionality (for example, it does not have tabs), but it also has good functionality, and there are fewer body movements. One of the nice features is support for 256-bit colors in the terminal:

This allows you to use convenient syntax highlighting themes for vim, such as badwolf:

To activate it, you need to add to .vimrc:

It will look like this:

How to save command history in bash cygwin?

In the .bashrc file you need to find add:

The first indicates the size of the history file (10 thousand commands), the second enables the removal of duplicate commands (if the entered command is already in the history, the old one is deleted to save space), and the third enables bash history maintenance.

How to navigate to a given path in Windows style in Cygwin?

To convert a win-like path into a unix-style path, you can use the cygpath utility.

As a result, the path will become "/cygdrive/d/projects/some/src" and passed as the cd argument.


The cygwin.bat script is executed from the DOS command line, installs the Cygwin environment and launches the bash interpreter under Windows. Cygwin does a great job of setting Unix environment variables to match Windows environment variables. For example, on my machine, I logged into Windows as user bjohnson. When I start Cygwin, it boots as user bjohnson by default.

Below is a window with some standard Unix commands in Cygwin.


Depending on the packages you have installed, you can easily run the corresponding Unix utilities. If you are a Unix user, you would no doubt wish that Windows had a ps command to view currently running processes without using Task Manager. If you use the -aW flag, you will be able to see Windows processes as well as any running Cygwin processes. Below is a list of Windows processes available by running the Cygwin command (ps -aW | less ).

PID PPID PGID WINPID TTY UID STIME COMMAND 3193213 0 0 4291774083 ? 0 Dec 31 C:\WINDOWS\SYSTEM\KERNEL32.DLL 63753 0 0 4294903543 ? 0 Dec 31 C:\WINDOWS\SYSTEM\MSGSRV32.EXE 60569 0 0 4294906727 ? 0 Dec 31 C:\WINDOWS\SYSTEM\MPREXE.EXE 77349 0 0 4294889947 ? 0 Dec 31 C:\WINDOWS\SYSTEM\RPCSS.EXE 196093 0 0 4294771203 ? 0 Dec 31 C:\WINDOWS\SYSTEM\mmtask.tsk 191237 0 0 4294776059 ? 0 Dec 31 C:\WINDOWS\EXPLORER.EXE 237709 0 0 4294729587 ? 0 Dec 31 C:\WINDOWS\TASKMON.EXE 230713 0 0 4294736583 ? 0 Dec 31 C:\WINDOWS\SYSTEM\SYSTRAY.EXE 217533 0 0 4294749763 ? 0 Dec 31 C:\PROGRAMFILES\DIRECTCD\DIRECTCD.EXE 5.1.

Directory structure and file permissions

Cygwin mounts your local drives in the /cygdrive directory. This includes hard drive partitions, floppy drives, CD readers, ZIP readers. Let's run the df command on my machine. We get a structure similar to the one below.

Bjohnson@BRADMAN $ df Filesystem 1k-blocks Used Available Use% Mounted on C:\cygwin\bin 2096832 0 2096832 0% /usr/bin C:\cygwin\lib 2096832 0 2096832 0% /usr/lib C:\cygwin 2096832 0 2096832 0% / c: 2096832 0 2096832 0% /cygdrive/c d: 670496 670496 0 100% /cygdrive/d

After installing Cygwin, I told the installer to save the files to the C:\cygwin\ directory. Cygwin used this directory as the root point file system mount. It mounted C:\cygwin\bin to /usr/bin and C:\cygwin\lib to /usr/lib . Cygwin (but not Windows) environment variables have been added to the /usr/bin , /bin , and /usr/local/bin directories. Directories from the Windows environment were imported into the Cygwin environment in order to be able to access them.

Cygwin also uses a smart permission system for Unix files. But what could this mean for all your Windows files? Who is the owner of the files, and what permissions are set by default? Let's run the ls -al command on several Windows files to get the answer.

bjohnson@BRADMAN /cygdrive/c/cyginstall $ ls -al total 273 drwxr-xr-x 1 bjohnson unknown 0 Mar 13 17:48 . drwxr-xr-x 1 bjohnson unknown 0 Dec 31 1969 .. drwxr-xr-x 1 bjohnson unknown 0 Mar 13 18:06 contrib drwxr-xr-x 1 bjohnson unknown 0 Mar 13 18:03 latest -rwxr-xr-x 1 bjohnson unknown 218112 Mar 13 17:48 setup.exe -rw-r--r-- 1 bjohnson unknown 60607 Mar 13 17:54 setup.ini

Cygwin will try to get the file's owners (user and group) information from Windows. While I was using a Windows 98 machine with one user, all the files were owned by me (bjohnson) with the group listed as "unknown". This set the permissions of all Windows directories and executables to 755 (read and execute for everyone, write for owner only) and set the permissions of all Windows files to 644 (read for everyone, write for owner only). The chmod command for Windows files is ignored.







2024 gtavrl.ru.