Questions tagged [escape-characters]

Escape sequences such as encodings of terminal commands and function keys

Escape characters allow special functions to be represented in what would otherwise be an ordinary text. Use this tag, in particular, for escape sequences that begin with the ESC (\e, \033, \x1b, ␛) character to encode terminal commands and function keys.

For ways to prevent special characters from having a special meaning in regular expressions, shell scripts, etc., use the tag instead.

Further reading

449 questions
144
votes
5 answers

How to escape quotes in shell?

I'm having trouble with escaping characters in bash. I'd like to escape single and double quotes while running a command under a different user. For the purposes of this question let's say I want to echo the following on the screen: 'single quote…
m33lky
  • 2,505
  • 5
  • 22
  • 20
114
votes
2 answers

Is Vim immune to copy-paste attack?

You should never paste from web to your terminal. Instead, you should paste to your text editor, check the command and then paste to the terminal. That's OK, but what if Vim is my text editor? Could one forge a content that switches Vim to command…
Adam Trhon
  • 1,623
  • 3
  • 17
  • 20
110
votes
2 answers

Why does Ctrl-D (EOF) exit the shell?

Are you literally "ending a file" by inputting this escape sequence, i.e. is the interactive shell session is seen as a real file stream by the shell, like any other file stream? If so, which file? Or, is the Ctrl+D signal just a placeholder which…
Geeb
  • 2,061
  • 2
  • 16
  • 17
95
votes
15 answers

Removing control chars (including console codes / colours) from script output

I can use the "script" command to record an interactive session at the command line. However, this includes all control characters and colour codes. I can remove control characters (like backspace) with "col -b", but I can't find a simple way to…
67
votes
5 answers

Where do I find a list of terminal key codes to remap shortcuts in bash?

For example: "\e[1;5C" "\e[Z" "\e-1\C-i" I only know bits and pieces, like \e stands for escape and C- for Ctrl, but what are these numbers (1) and letters (Z)? What are the ;, [ and - signs for? Is there only trial and error, or is there a complete…
bug
  • 2,418
  • 6
  • 22
  • 23
60
votes
11 answers

How do I clear the Gnome terminal history?

When we use clear command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?
hpn
  • 1,431
  • 7
  • 18
  • 21
58
votes
7 answers

Is there any reason why I get ^[[A when I press up arrow at the console login screen?

Whenever I'm at the console login, I press up arrow intentionally to see the previously typed commands. But I see this ^[[A. But when I press Ctrl Alt Print Screen Scroll Lock Pause Break Page Up Page Down Win keys doesn't echo any characters. What…
Ruban Savvy
  • 8,409
  • 8
  • 29
  • 43
45
votes
3 answers

How do some tools (e.g. nano , less) manage to leave no content in terminals after exit?

Whenever I use a pager like less or an editor like nano in the shell (my shell is GNU bash), I see a behaviour I cannot explain completely and which differs to the behaviour I can observe with other tools like cat or ls. I would like to ask how this…
humanityANDpeace
  • 13,722
  • 13
  • 61
  • 107
44
votes
2 answers

Where do my ANSI escape codes go when I pipe to another process? Can I keep them?

I sometime want to pipe the color-coded output fror a process, eg. grep... but when I pipe it to another process, eg. sed, the color codes are lost... Is the some way to keep thes codes intact ? Here is an example which loses the colored…
Peter.O
  • 32,426
  • 28
  • 115
  • 163
37
votes
2 answers

How do I use grep while keeping the original text color?

For example, I have a output: Hello, this is the output. (let's say that for example hello is colored red, and the is colored green, and output is colored purple). Now, let's say that this is the output of a command named x. If I use this command,…
Z0q
  • 549
  • 1
  • 5
  • 6
35
votes
5 answers

How to make the terminal display user@machine in bold letters?

I have seen in some screen-shots (can't remember where on the web) that the terminal can display the [username@machine /]$ in bold letters. I'm looking forward to getting this too because I always find myself scrolling through long outputs to find…
neydroydrec
  • 3,777
  • 8
  • 32
  • 42
32
votes
3 answers

How to escape single quotes correctly creating an alias

I've been given this one-liner to know how much memory my processes consume. $ ps -u $USER -o pid,rss,command | \ awk '{print $0}{sum+=$2} END {print "Total", sum/1024, "MB"}' Now I'd like to create an alias for that command, but have an issue…
Paolo
  • 16,955
  • 11
  • 31
  • 40
32
votes
2 answers

How to avoid escape sequence attacks in terminals?

Reading the details of CVE-2009-4487 (which is about the danger of escape sequences in log files) I am a bit surprised. To quote CVE-2009-4487: nginx 0.7.64 writes data to a log file without sanitizing non-printable characters, which might allow…
31
votes
3 answers

Using `printf` to print variable containing `%` percent sign results in "bash: printf: `p': invalid format character"

I want to use printf to print a variable. It might be possible that this variable contains a % percent sign. Minimal example: $ TEST="contains % percent" $ echo "${TEST}" contains % percent $ printf "${TEST}\n" bash: printf: `p': invalid format…
finefoot
  • 2,940
  • 2
  • 21
  • 41
30
votes
4 answers

Make Less highlight search patterns instead of italicizing them

To my understanding man uses less as a pager, and when searching for keywords using less it "highlights" keywords with italics. I find that really inconvenient, so I'd like to change this to something like vim's set hlsearch where the found pattern …
sgp667
  • 445
  • 1
  • 4
  • 8
1
2 3
29 30