LinuxCommandLibrary

unix2mac

Convert Unix line endings to Macintosh

TLDR

Change the line endings of a file

$ unix2mac [path/to/file]
copy

Create a copy with macOS-style line endings
$ unix2mac [[-n|--newfile]] [path/to/file] [path/to/new_file]
copy

Display file information
$ unix2mac [[-i|--info]] [path/to/file]
copy

Keep/add/remove Byte Order Mark
$ unix2mac --[keep-bom|add-bom|remove-bom] [path/to/file]
copy

SYNOPSIS

unix2mac [options] [file ...]
unix2mac [options] < input_file > output_file

PARAMETERS

-h, --help
    
Display help message and exit.

-v, --version
    
Display version information and exit.

-b, --backup
    
Create backup files with a `.bak` extension before converting.

-p, --preserve
    
Preserve the original file modification times and permissions.

-s, --skip-binary
    
Skip binary files. Files detected as binary will not be converted.

-L, --skip-symlink
    
Skip symbolic links. Symbolic links will not be followed or modified.

-o, --overwrite
    
Overwrite existing files without prompting (when creating backups).

DESCRIPTION

unix2mac is a command-line utility designed to convert text files from Unix-style line endings to classic Mac OS-style line endings. Unix systems use a single Line Feed (LF, ASCII 0x0A) character to denote the end of a line. In contrast, classic Mac OS used a single Carriage Return (CR, ASCII 0x0D).

It's crucial to note that modern macOS (formerly OS X) adopted the Unix-style LF for line endings, making unix2mac primarily useful for interoperability with older Mac OS systems or specific applications that still expect the classic CR format. This tool replaces every LF character with a CR character within the specified files, facilitating the exchange of text data between these different historical environments. It is often part of a broader package like tofrodos which also provides utilities for DOS (CRLF) conversions.

CAVEATS


Modern macOS Compatibility: Modern macOS uses Unix-style (LF) line endings. This command is primarily for compatibility with classic Mac OS (pre-OS X) or applications specifically requiring CR line endings. Applying it to files for modern macOS use is generally unnecessary and can lead to incorrect line display in some editors.

Binary Files: Applying unix2mac to binary files can corrupt them. Always use the -s option or ensure files are pure text.

Availability: unix2mac is not always a standalone command and may be part of packages like tofrodos, which might need to be installed separately.

<B>STANDARD INPUT/OUTPUT HANDLING</B>


When no input files are specified, unix2mac typically reads from standard input (stdin) and writes the converted content to standard output (stdout). This allows it to be used as part of a pipeline, for example: cat file.txt | unix2mac > converted_file.txt.

<B>IN-PLACE CONVERSION</B>


When one or more input files are provided as arguments, unix2mac usually modifies these files in-place, overwriting the original content with the converted version. The -b (backup) option is recommended to create a copy of the original file before modification, providing a safety net against unintended changes.

HISTORY


The need for unix2mac stems from the historical divergence in line ending conventions across different operating systems. Unix systems standardized on the Line Feed (LF) character, while classic Mac OS (up to version 9) used the Carriage Return (CR). This difference caused issues when exchanging text files between these environments, leading to misinterpretations of line breaks. Tools like unix2mac were developed to bridge this gap, ensuring proper rendering of text files.

With the advent of Mac OS X (now macOS), Apple adopted the Unix-standard LF line ending, significantly reducing the modern-day necessity for unix2mac for general file exchange with macOS. However, it remains relevant for legacy systems or specific applications that rely on the classic Mac OS CR convention. It is often provided as part of utility packages like tofrodos, which aim to standardize line ending conversions across all major platforms (Unix, DOS/Windows, Classic Mac).

SEE ALSO

mac2unix(1): Converts classic Mac line endings (CR) to Unix (LF)., dos2unix(1): Converts DOS/Windows line endings (CRLF) to Unix (LF)., unix2dos(1): Converts Unix line endings (LF) to DOS/Windows (CRLF)., tofrodos(1): A suite of tools for converting text files between various line ending formats., sed(1): A stream editor that can perform character substitutions., tr(1): Translates or deletes characters.

Copied to clipboard