The tag has no wiki summary.

learn more… | top users | synonyms

15
votes
4answers
6k views

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) ...
13
votes
4answers
524 views

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 ...
11
votes
5answers
6k views

How to clear terminal completely?

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?
9
votes
2answers
2k views

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 ...
8
votes
4answers
5k views

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 ...
8
votes
2answers
1k views

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 ? ...
8
votes
2answers
1k views

How do I background an SSH session? [duplicate]

Possible Duplicate: How can I break away from an SSH session that has crashed? I have started an SSH session on the command line, but now I want to get back to my local command line. For ...
8
votes
2answers
4k views

inline double and single quote escaping

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 ...
5
votes
4answers
3k views

How can I create a file with multiple lines from the command-line?

How can I enter the following contents in a file: Hi abcd I tried using echo "Hi\nabcd" >> ab.txt, but in the file it's written as is (the \n is included, instead of a newline)
5
votes
1answer
3k views

export HTTP_PROXY and special characters in passwd

Suppose for the sake of argument my password below is abc123@ I need to authenticate my linux machine through a corporate proxy to get patches and updates... normally I'd use this: export ...
5
votes
2answers
2k views

Change colors in console/virtual terminal

Is there a way to alter all the available colors in console / virtual terminal? By console, I mean what you get after pressing CTRL + ALT + F1 and not anything like xterm or urxvt. So, I guess that ...
4
votes
3answers
616 views

Escape sequences with “echo -e” in different shells

I just noticed that it seems like the flag -e does not exist for the echo command in my shell on Linux. Is this just a messed up setting or is it "normal"? Some code as an example: #!/bin/sh echo -e ...
4
votes
5answers
213 views

How to use ' in alias?

I have one-line that I want to call using alias. while printf '%s ' "$(df -P / | awk 'NR==2 { print $(NF-1) }')"; do sleep 30; done I tried to escape ' like \' but it didn't work. What is the ...
4
votes
3answers
904 views

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? ...
4
votes
1answer
923 views

How can I match the page break character in a regular expression?

Nano calls it ^L, but of course, typing something like $ grep -v "^\^L" file doesn't work. Its unicode codepoint is 000C. How can I match it in a regular expression?
4
votes
1answer
518 views

Reverse control-code look up for terminals

My understanding is that terminals often use ANSI control-codes to represent non-alphanumeric character sequences. For example, when editing .inputrc for Bash in Linux, it's easy to find code ...
4
votes
2answers
140 views

The difference between \e and ^[

Gilles wrote: character 27 = 033 = 0x1b = ^[ = \e Demizey wrote: ^[ is just a representation of ESCAPE and \e is interpreted as an actual ESCAPE character Then I also found this line from ...
4
votes
2answers
572 views

is it possible to send a control sequence to a terminal emulator using the keyboard

If you type echo -e '\eZ' and hit return in a shell running in an xterm, you'll see that the terminal emulator prints an obscure code 1;2c. This seems to indicate that xterm interprets the VT100 ...
4
votes
1answer
85 views

how to escape “\”in ssh-copy-id?

I'm connected to Ubuntu server that is a member of a corporate Active Directory domain via likewise-open. The users are in the form mydomain\myuser. I can connect to it via ssh, escaping the \ with ...
4
votes
2answers
272 views

Is there a way to lock terminal's title?

Sometimes there're lots of different sessions opened in own terminal's tabs and it's rather desirable to have theirs initial titles (named by session name) locked since local title tweaks make those ...
4
votes
1answer
487 views

Re-escape brackets in PS1

As others have pointed out, color codes in PS1 should be bracketed by \[ and \] to avoid them taking up horizontal space. I've added the necessary code to .bashrc: highlight() { if [ -x ...
4
votes
2answers
313 views

DEC ANSI command sequence questions; cursor movement

So I'm writing a terminal emulation (I know, I should just compile putty, etc.) and am at the stage of plodding through vttest to make sure it's right. I'm basing it on the VT102 for now but will add ...
3
votes
5answers
259 views

What are the special characters to print from a script to move the cursor?

I found that by printing \r from a script the cursor moves to the beginning of the line. What character will move the cursor up one line? Where is a list of these special characters? EDIT: Working ...
3
votes
2answers
1k views

Passing a bash command-line argument containing a dot

How can a command-line argument containing a dot (.) be passed? Are there any escape sequences for capturing characters like dot? The following invocation of a bash-script from the shell does not ...
3
votes
2answers
354 views

Unix Shell and colours

Can any one please help me understand this code snippet that I found in .profile file echo -en "\e[32;44m $(hostname) \e[m";echo -e "\e[m"
3
votes
3answers
4k views

How can I pass strings with single quotes to grep?

My desired outcome is the following: to recursively search a directory looking for a given string in all found files. The following command is my usual port of call: find ./ | xargs grep -ns 'foobar' ...
3
votes
1answer
277 views

Could someone please explain some of these escape codes?

I'm seeing this in my .bashrc file: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\ [\033[01;34m\]\w\[\033[00m\]\$ ' and I have absolutely no idea what all those ...
3
votes
2answers
562 views

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? ...
3
votes
1answer
2k views

Trouble in script with spaces in filename

I've got a script that scp's a file from remote host back to local. Sometimes the file names contain spaces. scp does not like spaces in its file names. For some reason my attempts at handling the ...
3
votes
2answers
1k views

How to escape < or > in a parameter in shell?

I'd like to use grep with a PCRE expression that contains the < character. Bash thinks I want to redirect, but I don't want to. How can I escape <?
3
votes
1answer
1k views

In Bash, why is PROMPT_COMMAND set to something invisible?

On RHEL6 and CentOS 6, /etc/bashrc sets PROMPT_COMMAND here: case $TERM in xterm*) if [ -e /etc/sysconfig/bash-prompt-xterm ]; then PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm ...
3
votes
2answers
1k views

Trying to print up down arrow keys

I have this: I read down arrow key abc@abc-ubuntu:~/bashpratice$ read -n 3 key ^[[Babc@abc-ubuntu:~/bashpratice$ I am able to grep for it abc@abc-ubuntu:~/bashpratice$ echo $key | grep '\[' [B ...
3
votes
1answer
68 views

How to find out the escape sequence my keyboards sends to terminal?

Let's say we have a generic keyboard with some unknown keys which may send escape sequences to terminal. The keyboard is connected to an xterm terminal emulator running on a generic BSD/Linux. To ...
3
votes
2answers
113 views

Can I make grep treat escaped multiline as a single line?

How can I make tools like grep treat multilines escaped with a backslash as a long single line? Let's say I have some files that looks like this: testvar=test1 \ test2 \ test3 ...
3
votes
1answer
36 views

How do I generate the sequence “\e[Z” in a terminal?

It is bound to menu-complete in GNU readline. $ bind -p|grep menu "\e[Z": menu-complete # menu-complete-backward (not bound) # old-menu-complete (not bound) I think it's Meta-something.
3
votes
1answer
927 views

How to bypass GNOME Terminal when sending keyboard input?

When running an interactive shell application, how can I send it a key (or key combination) which would normally be intercepted by GNOME Terminal? In this particular instance it's the F10 key which is ...
3
votes
1answer
362 views

Printing colored text using script

When I type below command in the shell I get the OUTPUT in green color. Command echo "\033[32mCONNECTING TO abpwrk\033[m"; Output(in green color) CONNECTING TO abpwrk But if I use the same ...
3
votes
0answers
110 views

How to create a bash command which creates output that exactly mimics a source text file that can be pasted into bash shell where histexpand is on?

The goal is to create a bash one line command that can be copied and pasted - for instance published on a web forum - and then patches files. See it as a way to distribute a patch file by copy and ...
3
votes
1answer
445 views

Escape sequences in output of script called from ncurses application

I'm currently running mcabber as my Jabber client (which uses ncurses) in a tmux session on my homeserver. Locally i run iTerm2 as a terminal emulator, which supports the triggering of growl ...
2
votes
2answers
468 views

How to copy a piped list of files contained spaces and apostrophes?

I have a list of files generated using find that I want to feed (pipe) to cp. My problem is that the files have spaces and apostrophes in them, leading cp to repeatedly complain that it "cannot stat". ...
2
votes
2answers
113 views

Maximize xterm via bash script

I have found this answer providing how to manipulate the current xterm window's dimensions, ie: echo -ne "\e[8;30;30t" How can I modify this to maximize the window (xterm's alt + enter shortcut)? ...
2
votes
1answer
79 views

What characters TAR doesn't like?

I keep a list of photos burned to dvds for incremental backups but I got into a strange situation where a file was already burned into a dvd but tar keeps saying it's not. Here the steps to reproduce: ...
2
votes
1answer
229 views

How to capture text formatting in bash?

The following shell script works but removes colored formatting generated by rspec: #!/bin/bash OUTPUT=`rspec` echo "$OUTPUT" How to preserve the colors?
2
votes
1answer
195 views

highlighting text in shell

I have always been using below method to highlight background of text in shell . tput smso;printf " TEXT ";tput rmso; How can I achieve the same thing without using tput( I mean some way formatting ...
2
votes
1answer
97 views

How can a bash script detect support for window titling escape characters?

I have a debug trap that runs every time I enter a command in bash that sets the window title to indicate what command is running. I'm leaving out all the configuration details and boil it down to: ...
2
votes
1answer
133 views

Confused about when to escape metacharacters in pathnames

I'm pretty confused about under which circumstances do I need to escape metacharacters in pathnames. Consider the following example: I'm in the following working directory: $ echo $PWD ...
2
votes
2answers
82 views

Weird escape sequence

I need help identifying what this escape sequences represents. I see this sequence is autogenerating on my server's console, but I'm not sure what is the reason for that. Escape sequence: ^[[[D I've ...
2
votes
2answers
612 views

Calling bash from sh (dash) with commands read from args, and “Unterminated quoted string”/“unexpected EOF”

Just thought I'd document this: I'm trying something very simple - set env variable in bash, and print it out: $ bash -c "a=1; echo a$a;" a $ bash -c "a=1; echo a\$a;" a1 Now I'd want this same ...
2
votes
1answer
636 views

Shell escape characters for sh -c

I need to execute a command with escaped argument(s) using sh -c. I know the string looks pretty ugly but simple ones don't cause a problem. The output of the echo when passed to sh -c is different ...
2
votes
2answers
872 views

Is the `\` character escaping or becoming part of my ssh key password

If I do: ssh-keygen -N password123\$ -f bobskeys Is \ escaping the $ character or becoming part of the password? Or rather, will bash be doing any escaping before ssh-keygen gets the password ...