Hot answers tagged

42

You can use tput reset. Besides reset and tput reset you can use following shell script. #!/bin/sh echo -e \\033c This sends control characters Esc-C to the console which resets the terminal. Google Keywords: Linux Console Control Sequences man console_codes says: The sequence ESC c causes a terminal reset, which is what you want if the screen ...


27

Find where your PS1 is set in your .bashrc and insert '\[\e[1m\]' at the beginning and \[\e[0m\] at the end. \[ and \] are necessary so the shell knows the mess inside takes up 0 space on the screen, which prevents some screwed up behavior when doing line-editing. You don't need to worry too much about it. \e[ is known as the CSI (control sequence ...


27

The ^D character (aka \04 or 0x4) is the default value for the eof special control character parameter of the terminal or pseudo-terminal driver in the kernel (more precisely of the tty line discipline attached to the serial or pseudo-tty device). That's the c_cc[VEOF] of the termios structure passed to the TCSETS/TCGETS ioctl one issues to the terminal ...


23

Many programs that generate colored output detect if they're writing to a TTY, and switch off colors if they aren't. This is because color codes are annoying when you only want to capture the text, so they try to "do the right thing" automatically. The simplest way to capture color output from a program like that is to tell it to write color even though ...


22

Those are sequences of characters sent by your terminal when you press a given key. Nothing to do with bash or readline per se, but you'll want to know what sequence of characters a given key or key combination sends if you want to configure readline to do something upon a given key press. When you press the A key, generally terminals send the a (0x61) ...


21

The following script should filter out all ANSI/VT100/xterm control sequences for (based on ctlseqs). Minimally tested, please report any under- or over-match. #!/usr/bin/env perl while (<>) { s/ \e[ #%()*+\-.\/]. | (?:\e\[|\x9b) [ -?]* [@-~] | # CSI ... Cmd (?:\e\]|\x9d) .*? (?:\e\\|[\a\x9c]) | # OSC ... (ST|BEL) ...


20

In your script, these assignments normal='\e[0m' yellow='\e[33m' put those characters literally into the variables, i.e., \e[0m, rather than the escape sequence. You can construct an escape character using printf (or some versions of echo), e.g., normal=$(printf '\033[0m') yellow=$(printf '\033[33m') but you would do much better to use tput, as this ...


19

No: there is no standard way to "disable it", and the details of breakage are actually terminal-specific, but there are some commonly-implemented features for which you can get misbehavior. For commonly-implemented features, look to the VT100-style alternate character set, which is activated by ^N and ^O (enable/disable). That may be suppressed in some ...


19

VT100 terminals (which all modern terminal emulators emulate to some extent) supported a number of problematic commands, but modern emulators or distributions disable the more problematic and less useful ones. Here's a non-exhaustive list of potentially risky escape sequences (not including the ones that merely make the display unreadable in some way): The ...


19

You can use the following string literal syntax: > echo $'\'single quote phrase\' "double quote phrase"' 'single quote phrase' "double quote phrase" From man bash Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash ...


17

Updating Gilles' answer to also remove carriage returns and do backspace-erasing of previous characters, which were both important to me for a typescript generated on Cygwin: #!/usr/bin/perl while (<>) { s/ \e[ #%()*+\-.\/]. | \r | # Remove extra carriage returns also (?:\e\[|\x9b) [ -?]* [@-~] | # CSI ... Cmd (?:\e\]|\x9d) ...


16

That's the way that the terminal represents the raw keycode of the Up key sent to it by the keyboard. Basically, your shell would normally intercept the keypress, but there's nothing to do that at the login prompt. So the character that you typed gets printed to the console just like any other letter (or number, or whatever).


15

Generally, you only have to escape one time to make special character considered literal. Sometime you have to do it twice, because your pattern is used by more than one program. Let disscuss your example: man gcc | grep \\. This command is interpreted by two programs, bash interpreter and grep. The first escape causes bash knows \ is literal, so the ...


14

Use -R flag: -r or --raw-control-chars Causes "raw" control characters to be displayed. The default is to display control characters using the caret notation; for example, a control-A (octal 001) is displayed as "^A". Warning: when the -r option is used, less cannot keep track of the actual appearance of the screen (since this depends on ...


14

There is escape char in ssh, by default this is tilde ~. It is recognized only at the beggining of a line. To suspend your ssh session type ~ then Ctrl+Z. Refer to the ssh(1) manual under ESCAPE CHARACTERS for more information.


13

You need to tell echo to honor escape sequences. echo -e "Hi\nabcd" >> ab.txt


13

Keyboards send events to the computer. An event says “scan code nnn down” or “scan code nnn up”. At the other end of the chain, applications running in a terminal expect input in the form of a sequence of characters. (Unless they've requested raw access, like the X server does.) When you press A, the keyboard sends the information “scan code 38 down”. The ...


13

These are ANSI escape codes. The ^[ represents an ESC (escape) character, the next [ is an actual left square bracket, and the letter indicates the function of the escape code. The Esc[ part is called the CSI (Control Sequence Introducer). So the sequence CSI A means arrow up, or CUU (CUrsor Up). Anyway, this scheme dates back to the time of the VT100 ...


13

To look for \\\" anywhere on a line: grep -F '\\\"' That is, use -F for a fixed string search as opposed to a regular expression match (where backslash is special). And use strong quotes ('...') inside which backslash is not special. Without -F, you'd need to double the backslashes: grep '\\\\\\"' Or use: grep '\\\{3\}"' grep -E '\\{3}"' grep -E ...


12

You could do this, x | grep --color=never hello To quickly test it, you can do, ls -l /etc/ --color=always | grep --color=never .


11

If you take a look at the ANSI ASCII standard, the lower part of the character set (the first 32) are reserved "control characters" (sometimes referred to as "escape sequences"). These are things like the NUL character, Life Feed, Carriage Return, Tab, Bell, etc. The vast majority can be emulated by pressing the Ctrl key in combination with another key. The ...


11

The behavior of echo varies from shell to shell¹; printf's behavior is more standard. printf "Hi\nabcd" >> ab.txt ¹ "It is not possible to use echo portably across all POSIX systems unless both -n (as the first argument) and escape sequences are omitted."


10

You could try URL-encoding your password. @ should be replaced by %40. Tackling Special Characters in Proxy Passwords on Linux indicates this should work, but looking around other people seem not to get that to work (and I have no way of testing this).


10

You should quote both the declaration and the usage PATH="/var/root/Documents/MyFile OG-v1.2.3.pkg" scp "$PATH" Me@10.1.10.33:/Users/Me/Desktop If you do not quote the first, $PATH will contain just the first part. If you do not quote the second, scp will treat each space-separated part as an argument.


10

This snippet is used to print out the hostname of the system with a blue background and a green font. To color your shell, you use special color escape sequences. \e[ starts the color scheme, 32; will set the foreground color to green, 44 will set the background color to blue and m will end it. $(command) creates a new shell, executes command and returns ...


10

You can use the reset command, that will reset the terminal settings.


10

Because you used sh, not bash, then echo command in sh doesn't have option -e. From sh manpage: echo [-n] args... Print the arguments on the standard output, separated by spaces. Unless the -n option is present, a newline is output following the arguments. And it doesn't have \e, too: If any of the following ...


10

^C aka Ctrl+C will abort what you're doing and get you back to a normal prompt.


10

Gnome-terminal (more properly VTE) imitates some version of xterm's escape sequences. How closely it does this, depends on the version of VTE. The relevant xterm documentation is in the PC-Style Function Keys section of XTerm Control Sequences. What you are looking for is a string like \e[1;5D (for control left-arrow), where the 5 denotes the control ...


10

The simplest way to find what are the codes of a key sequence is to use ctrl - v. So, you type ctrl V and ctrl → to get: ^[[1;5C Which is a way to write ESC[1;5C or \e[1;5C.



Only top voted, non community-wiki answers of a minimum length are eligible