summaryrefslogtreecommitdiff
path: root/man/man1/dos2unix.1
blob: a10ae8c7ec9aa061180ff03de29bc15e687f91c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
.    if \nF \{
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "dos2unix 1"
.TH dos2unix 1 "2017-10-10" "dos2unix" "2017-10-10"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
dos2unix \- DOS/Mac to Unix and vice versa text file format converter
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 2
\&    dos2unix [options] [FILE ...] [\-n INFILE OUTFILE ...]
\&    unix2dos [options] [FILE ...] [\-n INFILE OUTFILE ...]
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The Dos2unix package includes utilities \f(CW\*(C`dos2unix\*(C'\fR and \f(CW\*(C`unix2dos\*(C'\fR to convert
plain text files in \s-1DOS\s0 or Mac format to Unix format and vice versa.
.PP
In DOS/Windows text files a line break, also known as newline, is a combination
of two characters: a Carriage Return (\s-1CR\s0) followed by a Line Feed (\s-1LF\s0). In Unix
text files a line break is a single character: the Line Feed (\s-1LF\s0). In Mac text
files, prior to Mac \s-1OS X,\s0 a line break was single Carriage Return (\s-1CR\s0)
character. Nowadays Mac \s-1OS\s0 uses Unix style (\s-1LF\s0) line breaks.
.PP
Besides line breaks Dos2unix can also convert the encoding of files. A few
\&\s-1DOS\s0 code pages can be converted to Unix Latin\-1. And Windows Unicode (\s-1UTF\-16\s0)
files can be converted to Unix Unicode (\s-1UTF\-8\s0) files.
.PP
Binary files are automatically skipped, unless conversion is forced.
.PP
Non-regular files, such as directories and FIFOs, are automatically skipped.
.PP
Symbolic links and their targets are by default kept untouched.  Symbolic links
can optionally be replaced, or the output can be written to the symbolic link
target.  Writing to a symbolic link target is not supported on Windows.
.PP
Dos2unix was modelled after dos2unix under SunOS/Solaris.  There is one
important difference with the original SunOS/Solaris version. This version does
by default in-place conversion (old file mode), while the original
SunOS/Solaris version only supports paired conversion (new file mode). See also
options \f(CW\*(C`\-o\*(C'\fR and \f(CW\*(C`\-n\*(C'\fR. Another difference is that the SunOS/Solaris version
uses by default \fIiso\fR mode conversion while this version uses by default \fIascii\fR
mode conversion.
.SH "OPTIONS"
.IX Header "OPTIONS"
.IP "\fB\-\-\fR" 4
.IX Item "--"
Treat all following options as file names. Use this option if you want to
convert files whose names start with a dash. For instance to convert
a file named \*(L"\-foo\*(R", you can use this command:
.Sp
.Vb 1
\&    dos2unix \-\- \-foo
.Ve
.Sp
Or in new file mode:
.Sp
.Vb 1
\&    dos2unix \-n \-\- \-foo out.txt
.Ve
.IP "\fB\-\-allow\-chown\fR" 4
.IX Item "--allow-chown"
Allow file ownership change in old file mode.
.Sp
When this option is used, the conversion will not be aborted when the user
and/or group ownership of the original file can't be preserved in old file
mode. Conversion will continue and the converted file will get the same new
ownership as if it was converted in new file mode. See also options \f(CW\*(C`\-o\*(C'\fR and
\&\f(CW\*(C`\-n\*(C'\fR. This option is only available if dos2unix has support for preserving
the user and group ownership of files.
.IP "\fB\-ascii\fR" 4
.IX Item "-ascii"
Convert only line breaks. This is the default conversion mode.
.IP "\fB\-iso\fR" 4
.IX Item "-iso"
Conversion between \s-1DOS\s0 and \s-1ISO\-8859\-1\s0 character set. See also section
\&\s-1CONVERSION MODES.\s0
.IP "\fB\-1252\fR" 4
.IX Item "-1252"
Use Windows code page 1252 (Western European).
.IP "\fB\-437\fR" 4
.IX Item "-437"
Use \s-1DOS\s0 code page 437 (\s-1US\s0). This is the default code page used for \s-1ISO\s0 conversion.
.IP "\fB\-850\fR" 4
.IX Item "-850"
Use \s-1DOS\s0 code page 850 (Western European).
.IP "\fB\-860\fR" 4
.IX Item "-860"
Use \s-1DOS\s0 code page 860 (Portuguese).
.IP "\fB\-863\fR" 4
.IX Item "-863"
Use \s-1DOS\s0 code page 863 (French Canadian).
.IP "\fB\-865\fR" 4
.IX Item "-865"
Use \s-1DOS\s0 code page 865 (Nordic).
.IP "\fB\-7\fR" 4
.IX Item "-7"
Convert 8 bit characters to 7 bit space.
.IP "\fB\-b, \-\-keep\-bom\fR" 4
.IX Item "-b, --keep-bom"
Keep Byte Order Mark (\s-1BOM\s0). When the input file has a \s-1BOM,\s0 write a \s-1BOM\s0 in
the output file. This is the default behavior when converting to \s-1DOS\s0 line
breaks. See also option \f(CW\*(C`\-r\*(C'\fR.
.IP "\fB\-c, \-\-convmode \s-1CONVMODE\s0\fR" 4
.IX Item "-c, --convmode CONVMODE"
Set conversion mode. Where \s-1CONVMODE\s0 is one of:
\&\fIascii\fR, \fI7bit\fR, \fIiso\fR, \fImac\fR
with ascii being the default.
.IP "\fB\-D, \-\-display\-enc \s-1ENCODING\s0\fR" 4
.IX Item "-D, --display-enc ENCODING"
Set encoding of displayed text. Where \s-1ENCODING\s0 is one of:
\&\fIansi\fR, \fIunicode\fR, \fIunicodebom\fR, \fIutf8\fR, \fIutf8bom\fR
with ansi being the default.
.Sp
This option is only available in dos2unix for Windows with Unicode
file name support. This option has no effect on the actual file names
read and written, only on how they are displayed.
.Sp
There are several methods for displaying text in a Windows console based on the
encoding of the text. They all have their own advantages and disadvantages.
.RS 4
.IP "\fBansi\fR" 4
.IX Item "ansi"
Dos2unix's default method is to use \s-1ANSI\s0 encoded text. The advantage is that it
is backwards compatible. It works with raster and TrueType fonts. In some
regions you may need to change the active \s-1DOS OEM\s0 code page to the Windows
system \s-1ANSI\s0 code page using the \f(CW\*(C`chcp\*(C'\fR command, because dos2unix uses the
Windows system code page.
.Sp
The disadvantage of ansi is that international file names with characters not
inside the system default code page are not displayed properly. You will
see a question mark, or a wrong symbol instead. When you don't work with
foreign file names this method is \s-1OK.\s0
.IP "\fBunicode, unicodebom\fR" 4
.IX Item "unicode, unicodebom"
The advantage of unicode (the Windows name for \s-1UTF\-16\s0) encoding is that text is
usually properly displayed. There is no need to change the active code page.
You may need to set the console's font to a TrueType font to have international
characters displayed properly. When a character is not included in the TrueType
font you usually see a small square, sometimes with a question mark in it.
.Sp
When you use the ConEmu console all text is displayed properly, because ConEmu
automatically selects a good font.
.Sp
The disadvantage of unicode is that it is not compatible with \s-1ASCII.\s0 The output
is not easy to handle when you redirect it to another program.
.Sp
When method \f(CW\*(C`unicodebom\*(C'\fR is used the Unicode text will be preceded with a \s-1BOM
\&\s0(Byte Order Mark). A \s-1BOM\s0 is required for correct redirection or piping in
PowerShell.
.IP "\fButf8, utf8bom\fR" 4
.IX Item "utf8, utf8bom"
The advantage of utf8 is that it is compatible with \s-1ASCII.\s0 You need to set the
console's font to a TrueType font. With a TrueType font the text is displayed
similar as with the \f(CW\*(C`unicode\*(C'\fR encoding.
.Sp
The disadvantage is that when you use the default raster font all non-ASCII
characters are displayed wrong. Not only unicode file names, but also
translated messages become unreadable. On Windows configured for an East-Asian
region you may see a lot of flickering of the console when the messages are
displayed.
.Sp
In a ConEmu console the utf8 encoding method works well.
.Sp
When method \f(CW\*(C`utf8bom\*(C'\fR is used the \s-1UTF\-8\s0 text will be preceded with a \s-1BOM
\&\s0(Byte Order Mark). A \s-1BOM\s0 is required for correct redirection or piping in
PowerShell.
.RE
.RS 4
.Sp
The default encoding can be changed with environment variable \s-1DOS2UNIX_DISPLAY_ENC\s0
by setting it to \f(CW\*(C`unicode\*(C'\fR, \f(CW\*(C`unicodebom\*(C'\fR, \f(CW\*(C`utf8\*(C'\fR, or \f(CW\*(C`utf8bom\*(C'\fR.
.RE
.IP "\fB\-f, \-\-force\fR" 4
.IX Item "-f, --force"
Force conversion of binary files.
.IP "\fB\-gb, \-\-gb18030\fR" 4
.IX Item "-gb, --gb18030"
On Windows \s-1UTF\-16\s0 files are by default converted to \s-1UTF\-8,\s0 regardless of the
locale setting. Use this option to convert \s-1UTF\-16\s0 files to \s-1GB18030.\s0 This option
is only available on Windows. See also section \s-1GB18030.\s0
.IP "\fB\-h, \-\-help\fR" 4
.IX Item "-h, --help"
Display help and exit.
.IP "\fB\-i[\s-1FLAGS\s0], \-\-info[=FLAGS] \s-1FILE ...\s0\fR" 4
.IX Item "-i[FLAGS], --info[=FLAGS] FILE ..."
Display file information. No conversion is done.
.Sp
The following information is printed, in this order: number of \s-1DOS\s0 line breaks,
number of Unix line breaks, number of Mac line breaks, byte order mark, text
or binary, file name.
.Sp
Example output:
.Sp
.Vb 8
\&     6       0       0  no_bom    text    dos.txt
\&     0       6       0  no_bom    text    unix.txt
\&     0       0       6  no_bom    text    mac.txt
\&     6       6       6  no_bom    text    mixed.txt
\&    50       0       0  UTF\-16LE  text    utf16le.txt
\&     0      50       0  no_bom    text    utf8unix.txt
\&    50       0       0  UTF\-8     text    utf8dos.txt
\&     2     418     219  no_bom    binary  dos2unix.exe
.Ve
.Sp
Note that sometimes a binary file can be mistaken for a text file. See also option \f(CW\*(C`\-s\*(C'\fR.
.Sp
Optionally extra flags can be set to change the output. One or more flags
can be added.
.RS 4
.IP "\fB0\fR" 4
.IX Item "0"
Print the file information lines followed by a null character instead of a
newline character. This enables correct interpretation of file names with
spaces or quotes when flag c is used. Use this flag in combination with
\&\fIxargs\fR\|(1) option \f(CW\*(C`\-0\*(C'\fR or \f(CW\*(C`\-\-null\*(C'\fR.
.IP "\fBd\fR" 4
.IX Item "d"
Print number of \s-1DOS\s0 line breaks.
.IP "\fBu\fR" 4
.IX Item "u"
Print number of Unix line breaks.
.IP "\fBm\fR" 4
.IX Item "m"
Print number of Mac line breaks.
.IP "\fBb\fR" 4
.IX Item "b"
Print the byte order mark.
.IP "\fBt\fR" 4
.IX Item "t"
Print if file is text or binary.
.IP "\fBc\fR" 4
.IX Item "c"
Print only the files that would be converted.
.Sp
With the \f(CW\*(C`c\*(C'\fR flag dos2unix will print only the files that contain \s-1DOS\s0 line breaks,
unix2dos will print only file names that have Unix line breaks.
.IP "\fBh\fR" 4
.IX Item "h"
Print a header.
.IP "\fBp\fR" 4
.IX Item "p"
Show file names without path.
.RE
.RS 4
.Sp
Examples:
.Sp
Show information for all *.txt files:
.Sp
.Vb 1
\&    dos2unix \-i *.txt
.Ve
.Sp
Show only the number of \s-1DOS\s0 line breaks and Unix line breaks:
.Sp
.Vb 1
\&    dos2unix \-idu *.txt
.Ve
.Sp
Show only the byte order mark:
.Sp
.Vb 1
\&    dos2unix \-\-info=b *.txt
.Ve
.Sp
List the files that have \s-1DOS\s0 line breaks:
.Sp
.Vb 1
\&    dos2unix \-ic *.txt
.Ve
.Sp
List the files that have Unix line breaks:
.Sp
.Vb 1
\&    unix2dos \-ic *.txt
.Ve
.Sp
Convert only files that have \s-1DOS\s0 line breaks and leave the other files untouched:
.Sp
.Vb 1
\&    dos2unix \-ic0 *.txt | xargs \-0 dos2unix
.Ve
.Sp
Find text files that have \s-1DOS\s0 line breaks:
.Sp
.Vb 1
\&    find \-name \*(Aq*.txt\*(Aq \-print0 | xargs \-0 dos2unix \-ic
.Ve
.RE
.IP "\fB\-k, \-\-keepdate\fR" 4
.IX Item "-k, --keepdate"
Keep the date stamp of output file same as input file.
.IP "\fB\-L, \-\-license\fR" 4
.IX Item "-L, --license"
Display program's license.
.IP "\fB\-l, \-\-newline\fR" 4
.IX Item "-l, --newline"
Add additional newline.
.Sp
\&\fBdos2unix\fR: Only \s-1DOS\s0 line breaks are changed to two Unix line breaks.
In Mac mode only Mac line breaks are changed to two Unix
line breaks.
.Sp
\&\fBunix2dos\fR: Only Unix line breaks are changed to two \s-1DOS\s0 line breaks.
In Mac mode Unix line breaks are changed to two Mac line breaks.
.IP "\fB\-m, \-\-add\-bom\fR" 4
.IX Item "-m, --add-bom"
Write a Byte Order Mark (\s-1BOM\s0) in the output file. By default an \s-1UTF\-8 BOM\s0
is written.
.Sp
When the input file is \s-1UTF\-16,\s0 and the option \f(CW\*(C`\-u\*(C'\fR is used, an \s-1UTF\-16
BOM\s0 will be written.
.Sp
Never use this option when the output encoding is other than \s-1UTF\-8, UTF\-16,\s0 or
\&\s-1GB18030.\s0 See also section \s-1UNICODE.\s0
.IP "\fB\-n, \-\-newfile \s-1INFILE OUTFILE ...\s0\fR" 4
.IX Item "-n, --newfile INFILE OUTFILE ..."
New file mode. Convert file \s-1INFILE\s0 and write output to file \s-1OUTFILE.\s0
File names must be given in pairs and wildcard names should \fInot\fR be
used or you \fIwill\fR lose your files.
.Sp
The person who starts the conversion in new file (paired) mode will be the owner
of the converted file. The read/write permissions of the new file will be the
permissions of the original file minus the \fIumask\fR\|(1) of the person who runs the
conversion.
.IP "\fB\-\-no\-allow\-chown\fR" 4
.IX Item "--no-allow-chown"
Don't allow file ownership change in old file mode (default).
.Sp
Abort conversion when the user and/or group ownership of the original file
can't be preserved in old file mode. See also options \f(CW\*(C`\-o\*(C'\fR and \f(CW\*(C`\-n\*(C'\fR. This
option is only available if dos2unix has support for preserving the user
and group ownership of files.
.IP "\fB\-o, \-\-oldfile \s-1FILE ...\s0\fR" 4
.IX Item "-o, --oldfile FILE ..."
Old file mode. Convert file \s-1FILE\s0 and overwrite output to it. The program
defaults to run in this mode. Wildcard names may be used.
.Sp
In old file (in-place) mode the converted file gets the same owner, group, and
read/write permissions as the original file. Also when the file is converted by
another user who has write permissions on the file (e.g. user root).  The
conversion will be aborted when it is not possible to preserve the original
values.  Change of owner could mean that the original owner is not able to read
the file any more. Change of group could be a security risk, the file could be
made readable for persons for whom it is not intended.  Preservation of owner,
group, and read/write permissions is only supported on Unix.
.Sp
To check if dos2unix has support for preserving the user and group ownership of
files type \f(CW\*(C`dos2unix \-V\*(C'\fR.
.Sp
Conversion is always done via a temporary file. When an error occurs halfway
the conversion, the temporary file is deleted and the original file stays
intact. When the conversion is successful, the original file is replaced with
the temporary file. You may have write permission on the original file, but no
permission to put the same user and/or group ownership properties on the
temporary file as the original file has. This means you are not able to
preserve the user and/or group ownership of the original file. In this case you
can use option \f(CW\*(C`\-\-allow\-chown\*(C'\fR to continue with the conversion:
.Sp
.Vb 1
\&    dos2unix \-\-allow\-chown foo.txt
.Ve
.Sp
Another option is to use new file mode:
.Sp
.Vb 1
\&    dos2unix \-n foo.txt foo.txt
.Ve
.Sp
The advantage of the \f(CW\*(C`\-\-allow\-chown\*(C'\fR option is that you can use wildcards,
and the ownership properties will be preserved when possible.
.IP "\fB\-q, \-\-quiet\fR" 4
.IX Item "-q, --quiet"
Quiet mode. Suppress all warnings and messages. The return value is zero.
Except when wrong command-line options are used.
.IP "\fB\-r, \-\-remove\-bom\fR" 4
.IX Item "-r, --remove-bom"
Remove Byte Order Mark (\s-1BOM\s0). Do not write a \s-1BOM\s0 in the output file.
This is the default behavior when converting to Unix line breaks.
See also option \f(CW\*(C`\-b\*(C'\fR.
.IP "\fB\-s, \-\-safe\fR" 4
.IX Item "-s, --safe"
Skip binary files (default).
.Sp
The skipping of binary files is done to avoid accidental mistakes. Be aware
that the detection of binary files is not 100% foolproof. Input files are
scanned for binary symbols which are typically not found in text files. It is
possible that a binary file contains only normal text characters. Such a binary
file will mistakenly be seen as a text file.
.IP "\fB\-u, \-\-keep\-utf16\fR" 4
.IX Item "-u, --keep-utf16"
Keep the original \s-1UTF\-16\s0 encoding of the input file. The output file will be
written in the same \s-1UTF\-16\s0 encoding, little or big endian, as the input file.
This prevents transformation to \s-1UTF\-8.\s0 An \s-1UTF\-16 BOM\s0 will be written
accordingly. This option can be disabled with the \f(CW\*(C`\-ascii\*(C'\fR option.
.IP "\fB\-ul, \-\-assume\-utf16le\fR" 4
.IX Item "-ul, --assume-utf16le"
Assume that the input file format is \s-1UTF\-16LE.\s0
.Sp
When there is a Byte Order Mark in the input file the \s-1BOM\s0 has priority over
this option.
.Sp
When you made a wrong assumption (the input file was not in \s-1UTF\-16LE\s0 format) and
the conversion succeeded, you will get an \s-1UTF\-8\s0 output file with wrong text.
You can undo the wrong conversion with \fIiconv\fR\|(1) by converting the \s-1UTF\-8\s0 output
file back to \s-1UTF\-16LE.\s0 This will bring back the original file.
.Sp
The assumption of \s-1UTF\-16LE\s0 works as a \fIconversion mode\fR. By switching to the default
\&\fIascii\fR mode the \s-1UTF\-16LE\s0 assumption is turned off.
.IP "\fB\-ub, \-\-assume\-utf16be\fR" 4
.IX Item "-ub, --assume-utf16be"
Assume that the input file format is \s-1UTF\-16BE.\s0
.Sp
This option works the same as option \f(CW\*(C`\-ul\*(C'\fR.
.IP "\fB\-v, \-\-verbose\fR" 4
.IX Item "-v, --verbose"
Display verbose messages. Extra information is displayed about Byte Order Marks
and the amount of converted line breaks.
.IP "\fB\-F, \-\-follow\-symlink\fR" 4
.IX Item "-F, --follow-symlink"
Follow symbolic links and convert the targets.
.IP "\fB\-R, \-\-replace\-symlink\fR" 4
.IX Item "-R, --replace-symlink"
Replace symbolic links with converted files
(original target files remain unchanged).
.IP "\fB\-S, \-\-skip\-symlink\fR" 4
.IX Item "-S, --skip-symlink"
Keep symbolic links and targets unchanged (default).
.IP "\fB\-V, \-\-version\fR" 4
.IX Item "-V, --version"
Display version information and exit.
.SH "MAC MODE"
.IX Header "MAC MODE"
In normal mode line breaks are converted from \s-1DOS\s0 to Unix and vice versa.
Mac line breaks are not converted.
.PP
In Mac mode line breaks are converted from Mac to Unix and vice versa. \s-1DOS\s0
line breaks are not changed.
.PP
To run in Mac mode use the command-line option \f(CW\*(C`\-c mac\*(C'\fR or use the
commands \f(CW\*(C`mac2unix\*(C'\fR or \f(CW\*(C`unix2mac\*(C'\fR.
.SH "CONVERSION MODES"
.IX Header "CONVERSION MODES"
.IP "\fBascii\fR" 4
.IX Item "ascii"
In mode \f(CW\*(C`ascii\*(C'\fR only line breaks are converted. This is the default conversion
mode.
.Sp
Although the name of this mode is \s-1ASCII,\s0 which is a 7 bit standard, the
actual mode is 8 bit. Use always this mode when converting Unicode \s-1UTF\-8\s0
files.
.IP "\fB7bit\fR" 4
.IX Item "7bit"
In this mode all 8 bit non-ASCII characters (with values from 128 to 255)
are converted to a 7 bit space.
.IP "\fBiso\fR" 4
.IX Item "iso"
Characters are converted between a \s-1DOS\s0 character set (code page) and \s-1ISO\s0
character set \s-1ISO\-8859\-1 \s0(Latin\-1) on Unix. \s-1DOS\s0 characters without \s-1ISO\-8859\-1\s0
equivalent, for which conversion is not possible, are converted to a dot. The
same counts for \s-1ISO\-8859\-1\s0 characters without \s-1DOS\s0 counterpart.
.Sp
When only option \f(CW\*(C`\-iso\*(C'\fR is used dos2unix will try to determine the active code
page. When this is not possible dos2unix will use default code page \s-1CP437,\s0
which is mainly used in the \s-1USA. \s0 To force a specific code page use options
\&\f(CW\*(C`\-437\*(C'\fR (\s-1US\s0), \f(CW\*(C`\-850\*(C'\fR (Western European), \f(CW\*(C`\-860\*(C'\fR (Portuguese), \f(CW\*(C`\-863\*(C'\fR (French
Canadian), or \f(CW\*(C`\-865\*(C'\fR (Nordic).  Windows code page \s-1CP1252 \s0(Western European) is
also supported with option \f(CW\*(C`\-1252\*(C'\fR. For other code pages use dos2unix in
combination with \fIiconv\fR\|(1).  Iconv can convert between a long list of character
encodings.
.Sp
Never use \s-1ISO\s0 conversion on Unicode text files. It will corrupt \s-1UTF\-8\s0 encoded files.
.Sp
Some examples:
.Sp
Convert from \s-1DOS\s0 default code page to Unix Latin\-1:
.Sp
.Vb 1
\&    dos2unix \-iso \-n in.txt out.txt
.Ve
.Sp
Convert from \s-1DOS CP850\s0 to Unix Latin\-1:
.Sp
.Vb 1
\&    dos2unix \-850 \-n in.txt out.txt
.Ve
.Sp
Convert from Windows \s-1CP1252\s0 to Unix Latin\-1:
.Sp
.Vb 1
\&    dos2unix \-1252 \-n in.txt out.txt
.Ve
.Sp
Convert from Windows \s-1CP1252\s0 to Unix \s-1UTF\-8 \s0(Unicode):
.Sp
.Vb 1
\&    iconv \-f CP1252 \-t UTF\-8 in.txt | dos2unix > out.txt
.Ve
.Sp
Convert from Unix Latin\-1 to \s-1DOS\s0 default code page:
.Sp
.Vb 1
\&    unix2dos \-iso \-n in.txt out.txt
.Ve
.Sp
Convert from Unix Latin\-1 to \s-1DOS CP850:\s0
.Sp
.Vb 1
\&    unix2dos \-850 \-n in.txt out.txt
.Ve
.Sp
Convert from Unix Latin\-1 to Windows \s-1CP1252:\s0
.Sp
.Vb 1
\&    unix2dos \-1252 \-n in.txt out.txt
.Ve
.Sp
Convert from Unix \s-1UTF\-8 \s0(Unicode) to Windows \s-1CP1252:\s0
.Sp
.Vb 1
\&    unix2dos < in.txt | iconv \-f UTF\-8 \-t CP1252 > out.txt
.Ve
.Sp
See also <http://czyborra.com/charsets/codepages.html>
and <http://czyborra.com/charsets/iso8859.html>.
.SH "UNICODE"
.IX Header "UNICODE"
.SS "Encodings"
.IX Subsection "Encodings"
There exist different Unicode encodings. On Unix and Linux Unicode files are
typically encoded in \s-1UTF\-8\s0 encoding. On Windows Unicode text files can be
encoded in \s-1UTF\-8, UTF\-16,\s0 or \s-1UTF\-16\s0 big endian, but are mostly encoded in
\&\s-1UTF\-16\s0 format.
.SS "Conversion"
.IX Subsection "Conversion"
Unicode text files can have \s-1DOS,\s0 Unix or Mac line breaks, like regular text
files.
.PP
All versions of dos2unix and unix2dos can convert \s-1UTF\-8\s0 encoded files, because
\&\s-1UTF\-8\s0 was designed for backward compatibility with \s-1ASCII.\s0
.PP
Dos2unix and unix2dos with Unicode \s-1UTF\-16\s0 support, can read little and big
endian \s-1UTF\-16\s0 encoded text files. To see if dos2unix was built with \s-1UTF\-16\s0
support type \f(CW\*(C`dos2unix \-V\*(C'\fR.
.PP
On Unix/Linux \s-1UTF\-16\s0 encoded files are converted to the locale character
encoding. Use the \fIlocale\fR\|(1) command to find out what the locale character
encoding is. When conversion is not possible a conversion error will occur and
the file will be skipped.
.PP
On Windows \s-1UTF\-16\s0 files are by default converted to \s-1UTF\-8. UTF\-8\s0 formatted
text files are well supported on both Windows and Unix/Linux.
.PP
\&\s-1UTF\-16\s0 and \s-1UTF\-8\s0 encoding are fully compatible, there will no text be lost in
the conversion. When an \s-1UTF\-16\s0 to \s-1UTF\-8\s0 conversion error occurs, for instance
when the \s-1UTF\-16\s0 input file contains an error, the file will be skipped.
.PP
When option \f(CW\*(C`\-u\*(C'\fR is used, the output file will be written in the same \s-1UTF\-16\s0
encoding as the input file. Option \f(CW\*(C`\-u\*(C'\fR prevents conversion to \s-1UTF\-8.\s0
.PP
Dos2unix and unix2dos have no option to convert \s-1UTF\-8\s0 files to \s-1UTF\-16.\s0
.PP
\&\s-1ISO\s0 and 7\-bit mode conversion do not work on \s-1UTF\-16\s0 files.
.SS "Byte Order Mark"
.IX Subsection "Byte Order Mark"
On Windows Unicode text files typically have a Byte Order Mark (\s-1BOM\s0), because
many Windows programs (including Notepad) add BOMs by default. See also
<http://en.wikipedia.org/wiki/Byte_order_mark>.
.PP
On Unix Unicode files typically don't have a \s-1BOM.\s0 It is assumed that text files
are encoded in the locale character encoding.
.PP
Dos2unix can only detect if a file is in \s-1UTF\-16\s0 format if the file has a \s-1BOM.\s0
When an \s-1UTF\-16\s0 file doesn't have a \s-1BOM,\s0 dos2unix will see the file as a binary
file.
.PP
Use option \f(CW\*(C`\-ul\*(C'\fR or \f(CW\*(C`\-ub\*(C'\fR to convert an \s-1UTF\-16\s0 file without \s-1BOM.\s0
.PP
Dos2unix writes by default no \s-1BOM\s0 in the output file. With option \f(CW\*(C`\-b\*(C'\fR
Dos2unix writes a \s-1BOM\s0 when the input file has a \s-1BOM.\s0
.PP
Unix2dos writes by default a \s-1BOM\s0 in the output file when the input file has a
\&\s-1BOM.\s0 Use option \f(CW\*(C`\-r\*(C'\fR to remove the \s-1BOM.\s0
.PP
Dos2unix and unix2dos write always a \s-1BOM\s0 when option \f(CW\*(C`\-m\*(C'\fR is used.
.SS "Unicode file names on Windows"
.IX Subsection "Unicode file names on Windows"
Dos2unix has optional support for reading and writing Unicode file names in the
Windows Command Prompt. That means that dos2unix can open files that have
characters in the name that are not part of the default system \s-1ANSI\s0 code page.
To see if dos2unix for Windows was built with Unicode file name support type
\&\f(CW\*(C`dos2unix \-V\*(C'\fR.
.PP
There are some issues with displaying Unicode file names in a Windows console.
See option \f(CW\*(C`\-D\*(C'\fR, \f(CW\*(C`\-\-display\-enc\*(C'\fR. The file names may be displayed wrongly in
the console, but the files will be written with the correct name.
.SS "Unicode examples"
.IX Subsection "Unicode examples"
Convert from Windows \s-1UTF\-16 \s0(with \s-1BOM\s0) to Unix \s-1UTF\-8:\s0
.PP
.Vb 1
\&    dos2unix \-n in.txt out.txt
.Ve
.PP
Convert from Windows \s-1UTF\-16LE \s0(without \s-1BOM\s0) to Unix \s-1UTF\-8:\s0
.PP
.Vb 1
\&    dos2unix \-ul \-n in.txt out.txt
.Ve
.PP
Convert from Unix \s-1UTF\-8\s0 to Windows \s-1UTF\-8\s0 with \s-1BOM:\s0
.PP
.Vb 1
\&    unix2dos \-m \-n in.txt out.txt
.Ve
.PP
Convert from Unix \s-1UTF\-8\s0 to Windows \s-1UTF\-16:\s0
.PP
.Vb 1
\&    unix2dos < in.txt | iconv \-f UTF\-8 \-t UTF\-16 > out.txt
.Ve
.SH "GB18030"
.IX Header "GB18030"
\&\s-1GB18030\s0 is a Chinese government standard. A mandatory subset of the \s-1GB18030\s0
standard is officially required for all software products sold in China. See
also <http://en.wikipedia.org/wiki/GB_18030>.
.PP
\&\s-1GB18030\s0 is fully compatible with Unicode, and can be considered an unicode
transformation format. Like \s-1UTF\-8, GB18030\s0 is compatible with \s-1ASCII. GB18030\s0
is also compatible with Windows code page 936, also known as \s-1GBK.\s0
.PP
On Unix/Linux \s-1UTF\-16\s0 files are converted to \s-1GB18030\s0 when the locale encoding is
set to \s-1GB18030.\s0 Note that this will only work if the locale is supported by the
system. Use command \f(CW\*(C`locale \-a\*(C'\fR to get the list of supported locales.
.PP
On Windows you need to use option \f(CW\*(C`\-gb\*(C'\fR to convert \s-1UTF\-16\s0 files to \s-1GB18030.\s0
.PP
\&\s-1GB18030\s0 encoded files can have a Byte Order Mark, like Unicode files.
.SH "EXAMPLES"
.IX Header "EXAMPLES"
Read input from 'stdin' and write output to 'stdout':
.PP
.Vb 2
\&    dos2unix < a.txt
\&    cat a.txt | dos2unix
.Ve
.PP
Convert and replace a.txt. Convert and replace b.txt:
.PP
.Vb 2
\&    dos2unix a.txt b.txt
\&    dos2unix \-o a.txt b.txt
.Ve
.PP
Convert and replace a.txt in ascii conversion mode:
.PP
.Vb 1
\&    dos2unix a.txt
.Ve
.PP
Convert and replace a.txt in ascii conversion mode,
convert and replace b.txt in 7bit conversion mode:
.PP
.Vb 3
\&    dos2unix a.txt \-c 7bit b.txt
\&    dos2unix \-c ascii a.txt \-c 7bit b.txt
\&    dos2unix \-ascii a.txt \-7 b.txt
.Ve
.PP
Convert a.txt from Mac to Unix format:
.PP
.Vb 2
\&    dos2unix \-c mac a.txt
\&    mac2unix a.txt
.Ve
.PP
Convert a.txt from Unix to Mac format:
.PP
.Vb 2
\&    unix2dos \-c mac a.txt
\&    unix2mac a.txt
.Ve
.PP
Convert and replace a.txt while keeping original date stamp:
.PP
.Vb 2
\&    dos2unix \-k a.txt
\&    dos2unix \-k \-o a.txt
.Ve
.PP
Convert a.txt and write to e.txt:
.PP
.Vb 1
\&    dos2unix \-n a.txt e.txt
.Ve
.PP
Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt:
.PP
.Vb 1
\&    dos2unix \-k \-n a.txt e.txt
.Ve
.PP
Convert and replace a.txt, convert b.txt and write to e.txt:
.PP
.Vb 2
\&    dos2unix a.txt \-n b.txt e.txt
\&    dos2unix \-o a.txt \-n b.txt e.txt
.Ve
.PP
Convert c.txt and write to e.txt, convert and replace a.txt,
convert and replace b.txt, convert d.txt and write to f.txt:
.PP
.Vb 1
\&    dos2unix \-n c.txt e.txt \-o a.txt b.txt \-n d.txt f.txt
.Ve
.SH "RECURSIVE CONVERSION"
.IX Header "RECURSIVE CONVERSION"
In a Unix shell the \fIfind\fR\|(1) and \fIxargs\fR\|(1) commands can be used to run dos2unix
recursively over all text files in a directory tree. For instance to convert
all .txt files in the directory tree under the current directory type:
.PP
.Vb 1
\&    find . \-name \*(Aq*.txt\*(Aq \-print0 |xargs \-0 dos2unix
.Ve
.PP
The \fIfind\fR\|(1) option \f(CW\*(C`\-print0\*(C'\fR and corresponding \fIxargs\fR\|(1) option \f(CW\*(C`\-0\*(C'\fR are needed
when there are files with spaces or quotes in the name. Otherwise these options
can be omitted. Another option is to use \fIfind\fR\|(1) with the \f(CW\*(C`\-exec\*(C'\fR option:
.PP
.Vb 1
\&    find . \-name \*(Aq*.txt\*(Aq \-exec dos2unix {} \e;
.Ve
.PP
In a Windows Command Prompt the following command can be used:
.PP
.Vb 1
\&    for /R %G in (*.txt) do dos2unix "%G"
.Ve
.PP
PowerShell users can use the following command in Windows PowerShell:
.PP
.Vb 1
\&    get\-childitem \-path . \-filter \*(Aq*.txt\*(Aq \-recurse | foreach\-object {dos2unix $_.Fullname}
.Ve
.SH "LOCALIZATION"
.IX Header "LOCALIZATION"
.IP "\fB\s-1LANG\s0\fR" 4
.IX Item "LANG"
The primary language is selected with the environment variable \s-1LANG.\s0 The \s-1LANG\s0
variable consists out of several parts. The first part is in small letters the
language code. The second is optional and is the country code in capital
letters, preceded with an underscore. There is also an optional third part:
character encoding, preceded with a dot. A few examples for \s-1POSIX\s0 standard type
shells:
.Sp
.Vb 7
\&    export LANG=nl               Dutch
\&    export LANG=nl_NL            Dutch, The Netherlands
\&    export LANG=nl_BE            Dutch, Belgium
\&    export LANG=es_ES            Spanish, Spain
\&    export LANG=es_MX            Spanish, Mexico
\&    export LANG=en_US.iso88591   English, USA, Latin\-1 encoding
\&    export LANG=en_GB.UTF\-8      English, UK, UTF\-8 encoding
.Ve
.Sp
For a complete list of language and country codes see the gettext manual:
<http://www.gnu.org/software/gettext/manual/html_node/Usual\-Language\-Codes.html>
.Sp
On Unix systems you can use the command \fIlocale\fR\|(1) to get locale specific
information.
.IP "\fB\s-1LANGUAGE\s0\fR" 4
.IX Item "LANGUAGE"
With the \s-1LANGUAGE\s0 environment variable you can specify a priority list of
languages, separated by colons. Dos2unix gives preference to \s-1LANGUAGE\s0 over \s-1LANG.\s0
For instance, first Dutch and then German: \f(CW\*(C`LANGUAGE=nl:de\*(C'\fR. You have to first
enable localization, by setting \s-1LANG \s0(or \s-1LC_ALL\s0) to a value other than
\&\*(L"C\*(R", before you can use a language priority list through the \s-1LANGUAGE\s0
variable. See also the gettext manual:
<http://www.gnu.org/software/gettext/manual/html_node/The\-LANGUAGE\-variable.html>
.Sp
If you select a language which is not available you will get the
standard English messages.
.IP "\fB\s-1DOS2UNIX_LOCALEDIR\s0\fR" 4
.IX Item "DOS2UNIX_LOCALEDIR"
With the environment variable \s-1DOS2UNIX_LOCALEDIR\s0 the \s-1LOCALEDIR\s0 set
during compilation can be overruled. \s-1LOCALEDIR\s0 is used to find the
language files. The \s-1GNU\s0 default value is \f(CW\*(C`/usr/local/share/locale\*(C'\fR.
Option \fB\-\-version\fR will display the \s-1LOCALEDIR\s0 that is used.
.Sp
Example (\s-1POSIX\s0 shell):
.Sp
.Vb 1
\&    export DOS2UNIX_LOCALEDIR=$HOME/share/locale
.Ve
.SH "RETURN VALUE"
.IX Header "RETURN VALUE"
On success, zero is returned.  When a system error occurs the last system error will be
returned. For other errors 1 is returned.
.PP
The return value is always zero in quiet mode, except when wrong command-line options
are used.
.SH "STANDARDS"
.IX Header "STANDARDS"
<http://en.wikipedia.org/wiki/Text_file>
.PP
<http://en.wikipedia.org/wiki/Carriage_return>
.PP
<http://en.wikipedia.org/wiki/Newline>
.PP
<http://en.wikipedia.org/wiki/Unicode>
.SH "AUTHORS"
.IX Header "AUTHORS"
Benjamin Lin \- <blin@socs.uts.edu.au>,
Bernd Johannes Wuebben (mac2unix mode) \- <wuebben@kde.org>,
Christian Wurll (add extra newline) \- <wurll@ira.uka.de>,
Erwin Waterlander \- <waterlan@xs4all.nl> (maintainer)
.PP
Project page: <http://waterlan.home.xs4all.nl/dos2unix.html>
.PP
SourceForge page: <http://sourceforge.net/projects/dos2unix/>
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fIfile\fR\|(1)
\&\fIfind\fR\|(1)
\&\fIiconv\fR\|(1)
\&\fIlocale\fR\|(1)
\&\fIxargs\fR\|(1)