Key facts
- MIME type text/plain; there is no header, so the encoding (UTF-8, UTF-16, Windows-1252, ...) must be guessed or declared.
- Line endings differ by platform: CRLF on Windows, LF on Linux and macOS, CR on classic Mac OS.
- A UTF-8 file may start with an optional byte order mark (EF BB BF), which some tools display as stray characters.
- Size is simply the number of bytes of text; there is no formatting overhead.
How to open a .txt file
Double-click to open in Notepad, which handles UTF-8 and LF line endings on Windows 10/11. Notepad++ and VS Code show and change the encoding in the status bar.
Opens in TextEdit; use Format > Make Plain Text to keep it unformatted. BBEdit and VS Code give more control over encoding and line endings.
Read it with less file.txt or cat file.txt, edit with nano or vim, and detect the encoding with file -i file.txt.
Common problems and fixes
- Text shows garbled characters such as é or �
- The file is being read with the wrong encoding, typically UTF-8 shown as Windows-1252 or vice versa. Reopen it with the correct encoding and re-save as UTF-8, e.g. iconv -f WINDOWS-1252 -t UTF-8 in.txt > out.txt.
- Everything appears on one line or has ^M characters
- The line endings do not match the tool reading them. Convert them with dos2unix/unix2dos or your editor's line-ending setting.
- Strange characters () at the start of the file
- A UTF-8 BOM is being shown as text. Save the file as 'UTF-8 without BOM', which matters for scripts, CSVs and config files.
- Text has spaces between every letter or looks binary
- The file is UTF-16 (common for Windows exports) and the viewer expects UTF-8. Open it as UTF-16 and convert it to UTF-8.
Often converted to or from: DOCX, PDF, Markdown, CSV, HTML