mac2unix
Convert Mac text files to Unix format
TLDR
Change the line endings of a file
Create a copy with Unix-style line endings
Display file information
Keep/add/remove Byte Order Mark
SYNOPSIS
mac2unix [options] [file ...]
mac2unix [options] -n infile [outfile ...]
PARAMETERS
-k, --keepdate
Keep the original modification date of the output file. By default, the output file's modification date is updated.
-q, --quiet
Suppress all warning and error messages. Only critical errors might be reported.
-n, --newfile infile [outfile ...]
Convert infile and write the output to outfile. The original infile is preserved. If outfile is not specified, a default output filename is used (e.g., appending '.unix'). This option can be used for multiple input/output file pairs.
-h, --help
Display a help message that outlines the command's usage and options, then exit.
-V, --version
Display version information for the mac2unix utility and then exit.
--
Signals the end of command options. Any arguments following -- are treated as filenames, even if they begin with a hyphen (-).
DESCRIPTION
mac2unix is a utility designed to convert text files from Macintosh line ending format to Unix line ending format. Traditionally, Macintosh systems use a single carriage return (CR, '\r') character to signify the end of a line, while Unix and Linux systems use a single newline (LF, '\n') character. This fundamental difference can lead to display anomalies or script execution failures when text files are moved between these operating environments.
The mac2unix command reads the input file, identifies each carriage return character, and replaces it with a newline character, ensuring compatibility with Unix-based tools and applications. It is often included as part of the dos2unix package, which provides a comprehensive suite of tools for various line ending conversions. The command can process one or more specified files, or it can read from standard input and write to standard output, making it versatile for use in shell pipelines.
CAVEATS
mac2unix is primarily designed for converting text files. Applying it to binary files without careful consideration (e.g., using -F for 'force') can lead to file corruption. It is typically a hardlink or symbolic link to the dos2unix command and implicitly operates in 'mac' conversion mode. Always back up important files before performing in-place conversions, especially when processing multiple files simultaneously.
IMPLICIT CONVERSION MODE
When invoked as mac2unix, the utility automatically sets its conversion mode to 'mac' (Macintosh to Unix). This means it expects input with Macintosh-style line endings (CR) and converts them to Unix-style (LF) without requiring an explicit -c mac option.
STANDARD INPUT/OUTPUT USAGE
If no input file arguments are provided, mac2unix will read from standard input (stdin) and write the converted content to standard output (stdout). This behavior allows it to be seamlessly integrated into shell pipelines, e.g., cat mac_file | mac2unix > unix_file.
IN-PLACE CONVERSION DEFAULT
By default, when you specify one or more file arguments, mac2unix performs an in-place conversion, meaning it overwrites the original file with the converted content. To preserve the original file, use the -n or --newfile option to specify a different output filename.
HISTORY
mac2unix is part of the widely used dos2unix package, which emerged to address line ending compatibility issues across different operating systems. Initially, dos2unix focused on converting between DOS/Windows (CRLF) and Unix (LF) line endings. As Macintosh systems also utilized a distinct line ending convention (CR), the mac2unix and unix2mac functionalities were introduced to provide a comprehensive solution for cross-platform text file portability. The dos2unix package, including its specialized commands like mac2unix, has since become a standard utility on most Unix-like operating systems, continually evolving to handle various conversion modes and options efficiently.