Answers:
在Cygwin中安装了Cygwin和Dos2unix
find . -type f -exec dos2unix {} \;
-maxdepth 1使其不会通过子目录
您可以在Windows上安装git bash而不是cygwin32(或类似文件)。它配备了几个类unix命令(例如,find,dos2unix等)在bash仿真模式。安装后,将文件从Windows转换为Unix文件结尾应该很容易。
假设您将文件(后缀.java结束)放在名为src的文件夹树中,并且想要将其结尾从Windows转换为Unix。
find . -name "*.java" -exec dos2unix {} \;。就是这样!
使用dos2unix和unix2dos的答案非常好。
这是根据您的答案的另一种方法。
尽管可以很有趣地使用Gnuwin32,但是具有命令的Gnuwin32软件包是Cygutils http://gnuwin32.sourceforge.net/packages/cygutils.htm, 因此您将在C:\ Program Files文件中获得unix2dos.exe和dos2unix.exe。 .... \ GnuWin32 \ bin并包含在您的PATH中。
C:\somedir>dir<ENTER>
Volume in drive C has no label.
Volume Serial Number is DC46-3C68
Directory of C:\somedir
05/23/2014 01:10 AM <DIR> .
05/23/2014 01:10 AM <DIR> ..
05/23/2014 01:10 AM 4 file1
1 File(s) 4 bytes
3 Dir(s) 196,129,951,744 bytes free
Do this command to go from dos2unix
C:\somedir>for %f in (*) do dos2unix %f <ENTER>
C:\somedir>dos2unix file1 <-- This runs automatically from you doing the above command
file1: done.
And do this command to go from unix2dos
C:\somedir>for %f in (*) do unix2dos %f <ENTER>
C:\somedir>unix2dos file1 <-- This runs automatically from you doing the above command
file1: done.
C:\somedir>
并测试您的%f是否会执行您想要的操作,然后使用echo或@ECHO,例如
在(*)中使用%f做@ECHO unix2dos%f
您可以使用xxd创建文件并测试它们是否已转换。Windows的xxd随附VIM C:\ Program“” Files \ vim \ vim74 \ xxd.exe
so, i'll create a file, I like this style of command is it allows me to
create whateer file I want, a dos one or a unix one or anything.
61 is hex for 'a'
C:\somedir>echo 610d0a| xxd -r -p >testfile <ENTER>
check the file raw, in its hex
C:\somedir>cat testfile | xxd -p <ENTER>
610d0a
check the file in ascii or unicode
C:\somedir>cat testfile <ENTER>
a
and the following commands just prove that dos2unix and unix2dos work/are working fine.
C:\somedir>dos2unix testfile <ENTER>
testfile: done.
C:\somedir>cat testfile | xxd -p <ENTER>
610a
C:\somedir>unix2dos testfile <ENTER>
testfile: done.
C:\somedir>cat testfile | xxd -p <ENTER>
610d0a
C:\somedir>
注意-同样在使用* nix发行版的情况下,查看apt-get(apt-cache搜索dos2unix),该软件包确实是dos2unix(也许与apt-get install dos2unix一起安装),并且包括dos2unix可执行文件,unix2dos可执行文件。如果执行apt-cache搜索unix2dos,则会显示dos2unix软件包。