Plain Text
- A plain text file is created by a Linux editor,
or the echo command.
- It contains lines of text.
- Each line (even the last one) ends with a newline character.
- Newlines do not separate lines, they end lines, like a period ends a sentence.
$ echo "abcd" >foo
$ echo "fg" >>foo
$ ls -l foo
-rw------- 1 ct320 class 8 Jan 21 03:50 foo
$ cat foo
abcd
fg
$ od -t x1 foo
0000000 61 62 63 64 0a 66 67 0a
0000010
Windows Text Files—not what we want
- On Windows, a data file line ends with a two-character sequence
(CR/LF), as opposed to a Linux’s one-character (newline, alias LF).
- If you work at it, you can create Linux plain text files on Windows.
- Avoid that until you know what you’re doing.
What Plain Text is Not
- It is not:
- a .pdf file
- a .doc file
- a .pdf or a .doc file renamed to be .txt
- created with Microsoft Word.
- It is not created on Windows.
- It is not created via
notepad
or notepad++
,
because those are Windows programs (even if run on Linux).
- If the file command reports “CRLF line terminators”,
then it has Windows-style line endings, so it’s not plain text.
- If the file command reports “no line terminators”,
it contains no line endings at all, so it’s not plain text.
Examples
$ date >good
$ cat good
Tue Jan 21 03:50:34 MST 2025
$ ls -l good
-rw------- 1 ct320 class 29 Jan 21 03:50 good
$ file good
good: ASCII text
$ file /usr/share/cups/data/default.pdf
/usr/share/cups/data/default.pdf: PDF document, version 1.5
$ echo -n "hi" >bad
$ cat bad
hi$ ls -l bad
-rw------- 1 ct320 class 2 Jan 21 03:50 bad
$ file bad
bad: ASCII text, with no line terminators
$ sed 's/$/\r/' <good >bad
$ cat bad
Tue Jan 21 03:50:34 MST 2025
$ ls -l bad good
-rw------- 1 ct320 class 30 Jan 21 03:50 bad
-rw------- 1 ct320 class 29 Jan 21 03:50 good
$ od -t x1 bad
0000000 54 75 65 20 4a 61 6e 20 32 31 20 30 33 3a 35 30
0000020 3a 33 34 20 4d 53 54 20 32 30 32 35 0d 0a
0000036
$ od -t x1 good
0000000 54 75 65 20 4a 61 6e 20 32 31 20 30 33 3a 35 30
0000020 3a 33 34 20 4d 53 54 20 32 30 32 35 0a
0000035
$ file bad
bad: ASCII text, with CRLF line terminators
Linux Text Editors
There are many text editors on Linux:
- gedit
- simple, like notepad on Windows
- graphics-based, so it doesn’t work over a text-only ssh connection
such as putty
pico
/nano
- like gedit, but text-based
- vim: my favorite
- emacs: good luck
Where’s the GUI?
- There isn’t one.
- Or, the editor is the gui.