• Skip to main content
  • Skip to after header navigation
  • Skip to site footer

Free-Mail

  • Events
  • Images
    • Instagram Goodness
  • Music
  • News
  • Software

5 escape sequences for your Linux shell

5 escape sequences for your Linux shell: 5 escape sequences for your Linux shell sethkenlon Thu, 02/16/2023 – 03:00

I recently read an article about shell metacharacters by Opensource.com correspondent Don Watkins. His article made me think about all the weird things you could do with shell input. While I probably have yet to discover the extremes, I do often find shell escape sequences, like \b and \t and \f strangely useful.

Escape sequences are a special type of terminal input. They’re designed to make it possible for you to enter characters or events that you may not have on your physical keyboard. Here are my favorite escape sequences for the Bash shell.

1. Backspace

You can enter a backspace character as part of a command, more or less loading it to trigger once the command executes. For instance, looking casually at this command, you might expect its output to be ab, but take a look at the actual output:

 $   echo a$  '\b'b b

Technically, the shell did output ab (you can confirm that by appending | wc -m to the command) but part of the total output was the \b backspace event. The backspace removed a before outputting b, and so the viewable output is just b.

2. Newline

A newline character is a signal for your shell to go to column 0 of the next line. This is essential when using a command like printf, which doesn’t assume that you want a newline added to the end of your output, the way echo does. Look at the difference between a printf statement without the \n newline character and one with it:

 $   printf "%03d.txt" 1 001.txt$   $   printf "%03d.txt\n" 1 001.txt $  

3. Form feed

A \f form feed signal is like a newline character, but without the imperative to return to column 0. Here’s a printf command using a form feed instead of a newline:

 $   printf "%s\f" hello hello      $  

Your shell prompt is on the next line, but not at the start of the line.

4. Tab

There are two tab escape sequences: the \t horizontal tab and the \v vertical tab. The horizontal tab is exactly what you’d expect.

 $   echo a$  '\t'b a     b

The vertical tab is, in theory, the same principle but in vertical space. On most consoles, though, the vertical spacing of a line isn’t variable, so it usually ends up looking a lot like a form feed:

 $   echo a$  '\t'b a  b

More Linux resources
Linux commands cheat sheet
Advanced Linux commands cheat sheet
Free online course: RHEL technical overview
Linux networking cheat sheet
SELinux cheat sheet
Linux common commands cheat sheet
What are Linux containers?
Our latest Linux articles

5. Unicode

There are a lot of characters available in the Unicode standard, and your keyboard only has about 100 keys. There are a few ways to enter special characters on Linux, but one way to enter them into the terminal is to use the Unicode escape sequence. You start this escape sequence with \u followed by a hexadecimal value. You can find many Unicode values in the file /usr/share/X11/locale/en_US.UTF-8/Compose, or you can look at the Unicode specification at https://www.unicode.org/charts/.

This can be a useful trick for entering common symbols like Pi (the ratio of a circle’s circumference to its diameter):

 $   echo $  '\u03C0' ?

There are lots of other symbols and characters, too.

 $   echo $  '\u270B' ? $   echo $  '\u2658' ? $   echo $  '\u2B67' ?

There’s Braille notation, musical notation, alphabets, electrical symbols, mathematical symbols, emoji, game symbols, and much more. In fact, there are so many available symbols that sometimes you need the \U (note the capital letter) Unicode escape sequence to access Unicode in the high ranges. For instance, this 5-of-Hearts playing card only appears with the \U escape sequence:

 $   echo $  '\U1F0B5' ?

Have a look around on the Unicode specification to find your niche, and use \u and \U to access all the special symbols you need.

Escape the shell

There are 18 escape sequences listed in the man page for the Bash shell, and some I find more useful than others. I’ve covered my favorites in this article, and Don Watkins talked about the metacharacters he uses most often in his article, yet there’s still more to be discovered. There are ways to encode ranges of letters and numbers, subshells, mathematical equations, and more. For a good overview of metacharacters available for the shell, download our metacharacter cheat sheet and keep it handy as you get better at using the most powerful application on your computer: the Linux terminal.

Use these secret codes for your Bash terminal. Download our new Linux metacharacters cheat sheet.

bash logo on green background
Image by:

Opensource.com

Linux

What to read next
Linux metacharacters cheat sheet

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.
Register or Login to post a comment.

: Opensource.com sethkenlon

Supporting Open Source.

Have you tried: Diving with Sharks?

Share this:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Pinterest (Opens in new window) Pinterest
  • Email a link to a friend (Opens in new window) Email
  • More
  • Share on Tumblr (Opens in new window) Tumblr
  • Print (Opens in new window) Print
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit
Published on 16 February 2023 by Alan Category: SoftwareTag: Escape, Linux, sequences, Shell

Suid-Afrikaanse Testamente Word Gereeld Deur Howe Verwerp

JOHANNESBURG – Testamente word dikwels deur Suid-Afrikaanse howe as ongeldig verklaar weens …

Read moreSuid-Afrikaanse Testamente Word Gereeld Deur Howe Verwerp

Monaco’s Princess Charlene stable after collapsing in South Africa

South Africa in the news: Monaco’s Princess Charlene stable after collapsing in South Africa: …

Read moreMonaco’s Princess Charlene stable after collapsing in South Africa

Lions squad 2021 in full: The 37-man British & Irish Lions team selected to tour South Africa

South Africa in the news: Lions squad 2021 in full: The 37-man British & Irish Lions team …

Read moreLions squad 2021 in full: The 37-man British & Irish Lions team selected to tour South Africa

About Alan

Previous Post:At-home fertility tests: here’s what they can actually tell you
Next Post:How running can help you cope with stress at work

Reach Trust

Reach Trust is a holding trust for a number of companies within the Stratlec Group.

Copyright © 2026 · Free-Mail · All Rights Reserved · Powered by Straton Electrical

Back to top