gpt4 book ai didi

How to use Cygwin version of find rather than Windows version(如何使用Cygwin版本的Find而不是Windows版本)

转载 作者:bug小助手 更新时间:2023-10-25 14:55:20 30 4
gpt4 key购买 nike



I have got Cygwin installed in my machine and set its bin folder in my PATH.

我已经在我的机器上安装了Cygwin,并将它的bin文件夹设置在我的路径中。



I can use all the Cygwin commands in the Windows command prompt.

我可以在Windows命令提示符下使用所有Cygwin命令。



However, one problem I encountered is that both Cygwin an Windows have a command "find". Whenever I use find, the Windows version is picked up.

然而,我遇到的一个问题是,Cygwin和Windows都有一个命令“Find”。每当我使用Find时,都会拿起Windows版本。



Is there anyway I can force using the Cygwin version of find rather than the Windows version?

有没有什么办法可以强制我使用Cygwin版本的Find而不是Windows版本?


更多回答
优秀答案推荐

Make sure the the cygwin executables folder /usr/bin is ahead of the cmd executables folder c:\Windows\system32 in the PATH variable for both the cmd and bash shells to be sure you run cygwin's find instead of windows's find command.

在cmd和bash外壳程序的PATH变量中,确保cygwin可执行文件文件夹/usr/bin位于cmd可执行文件文件夹c:\windows\system32的前面,以确保您运行的是cygwin的find而不是windows的find命令。



Use which -a find in the cygwin shell to list executable files found via the bash shell's PATH variable.

在cygwin外壳中使用Which-a Find列出通过bash外壳的PATH变量找到的可执行文件。



Use where $PATH:find in cmd shell to list executable files found via the cmd shell's PATH variable.

在cmd shell中使用where $PATH:find列出通过cmd shell的PATH变量找到的可执行文件。



1.Check what your paths are to the find.exe file, You will get a path for both Windows and Cygwin, with Windows being the first :

1.检查find.exe文件的路径,您将获得Windows和Cygwin的路径,其中Windows是第一个路径:


C:\Users\User>where find
C:\Windows\System32\find.exe
C:\cygwin64\bin\find.exe

2.Now you will see what the default operating system is:

2.现在你将看到默认的操作系统是什么:


`which find
C:\Windows\System32\find.exe`

3use this command to set find from Cygwin befor Windows:

3对于Windows,使用以下命令设置从Cygwin查找:


set PATH=C:\cygwin64\bin;%PATH%

4.You will now see a long list of paths, and your path should be the first

4.现在您将看到一长串路径,您的路径应该是第一条


C:\Users\User\L>echo %PATH%

5.Now you can do a short test to check if it works by a simple find command like:


`find . -type f -name *.txt`

If the operation returns all the files that end in txt, or it returns nothing (because you don't have any files that end like that in the current location) You made it! If you encounter the error again, check the steps .

如果该操作返回所有以txt结尾的文件,或者不返回任何内容(因为您在当前位置没有任何以txt结尾的文件),那么您成功了!如果再次遇到错误,请检查步骤。



This is because find is a shell built-in in cmd, so it doesn't even try to go through the executable search path.

这是因为Find是cmd中内置的一个外壳,因此它甚至不会尝试遍历可执行文件搜索路径。



In general Cygwin symlinks will not be understood by Windows, but as explained https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks it is possible in modern Windows versions to create native Windows symlinks on NTFS file systems, as long as the link doesn't cross file systems.

通常情况下,Windows不会理解Cygwin符号链接,但正如https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks解释的那样,在现代Windows版本中,可以在NTFS文件系统上创建本地Windows符号链接,只要该链接不跨文件系统。



I would consider instead just wrapping it in, say, a batch script placed in your Cygwin /usr/local/bin with a name like cygfind.bat (or whatever you want to call it) that explicitly calls Cygwin's find by C:\path\to\find.exe.

比方说,我会考虑将其包装在Cygwin/usr/local/bin中的一个批处理脚本中,该脚本的名称类似于cygfind.bat(或者您想怎么称呼它),它显式地调用Cygwin的Find by C:\Path\to\find.exe。



The wrapper approach has the advantage that if you upgrade Cygwin and find is updated, the batch script wrapping it will still work transparently.

包装器方法的优点是,如果您升级了Cygwin并更新了Find,则包装它的批处理脚本仍将透明地工作。



I've never tried it myself but according to this answer you can also use the special @doskey variable to override cmd builtins.

我自己从来没有试过,但根据这个答案,您还可以使用特殊的@doskey变量来覆盖cmd内置。


更多回答

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com