When you run cat -A, you are telling the computer: "Don't just show me the text; show me the structure of the file."
It does this by substituting "invisible" control characters with visible symbols. Here is the breakdown of how it works:
1. The Line Ending ($)
In Linux, lines don't just "end"; they are terminated by a Newline character (\n).
- Normally,
catsees\nand simply moves the cursor to the start of the next line. - With
-A,catputs a$symbol exactly where that hidden newline character exists.
Example:
If your file contains:
Hi
Labby
cat -A will show:
Hi$
Labby$
2. The Tab Character (^I)
Tabs are often invisible—they just look like empty space. This is a common source of bugs in coding (especially in languages like Python or Makefiles).
cat -Ashows a Tab as^I.- If you see 8 spaces in a file but
cat -Ashows nothing special, you know someone used the Spacebar. If you see^I, you know they hit the Tab key.
3. Windows Style Endings (^M)
As we discussed earlier, Windows files use \r\n.
- Since
\nis shown as$, the\r(Carriage Return) is shown as^M. - If you see
^M$at the end of your lines, you know the file was saved on a Windows system!
4. What does the -A actually stand for?
The -A flag is actually a shortcut for three other flags combined:
-v: Display non-printing characters (using^andM-notation).-E: Show$at the end of lines.-T: Show tabs as^I.
Try it yourself!
In your terminal, try creating a file with a tab and then viewing it:
echo -e "Hello\tWorld" > /tmp/test_tabcat -A /tmp/test_tab
You will see Hello^IWorld$.
It’s a fantastic "quick check" tool to see if there are trailing spaces or weird formatting characters messing up your work. Ready to move back to the tail commands in the lab?