How does `cat -A` show hidden characters?

QuestionsQuestions8 SkillsProDec, 18 2025
0223

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, cat sees \n and simply moves the cursor to the start of the next line.
  • With -A, cat puts 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 -A shows a Tab as ^I.
  • If you see 8 spaces in a file but cat -A shows 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 \n is 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 ^ and M- 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:

  1. echo -e "Hello\tWorld" > /tmp/test_tab
  2. cat -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?

0 Comments

no data
Be the first to share your comment!