Kolam Ayer MakersLinux Foundations

File Encoding

Core Idea

Files contain bytes. Text files are bytes interpreted through an encoding. UTF-8 is the modern default for most Linux text because it can represent plain ASCII and many world writing systems without switching encodings.

Commands To Try

printf 'makers\n' > ~/playground/encoding.txt
file ~/playground/encoding.txt
xxd ~/playground/encoding.txt

file guesses the file type. xxd shows the bytes. The ASCII letters in makers appear as hexadecimal bytes 6d 61 6b 65 72 73.

Newlines Matter

Unix text files usually end lines with one byte: line feed, shown as 0a in hex. Windows text files often use carriage return plus line feed, shown as 0d 0a. Scripts copied from Windows can fail if the shebang line ends with 0d 0a.

Common Confusions

Binary Inspection

Use this first pass when a file is not obviously text:

file unknown
strings unknown | less
xxd unknown | head

strings extracts readable runs. xxd shows exact bytes. Neither replaces understanding the file format.

Proof Check

Run printf 'A\n' | xxd. Explain why 41 is A and 0a is the newline.

Docs Pointers