Linux

Bash Line Drawing Characters

Here are a few cool escape sequences:

 

echo -e "\033(0" # Set line drawing mode
echo -e "\033(B" # Set Text mode

 

Colorizing 'cat' with source-highlight, dump code in color

I always wanted to colorize a 'cat' of a file (lord knows why?!), but tonight, I figured out how to do it!

What you need

You need to install the packages

  • highlight
  • source-highlight

In Fedora, its as easy as

yum install -y highlight source-highlight

After this is complete, generate the script called 'scat' in /usr/bin:

#!/bin/bash
INFILE="$1"

if [ -n "$2" ]; then
        OPTS="-S $2"
fi

highlight $INFILE -A $OPTS

 

 

Drupal 6.3 and phpBB 3.0.4 CAN be integrated together

This is my personal reference just in case I have to make another installation that integrates Drupal 6.3 and phpBB 3.0.3. A Drupal 6.3 web site must already be existing. PhpBB 3.0.2 and Drupal phpBBforum module must be installed in that order. Here then are the steps I did in sequence:

Installing phpBB 3.0.2

I downloaded phpBB 3.0.2 (zip)
I extracted this file to my local hard drive. A phpBB3 directory is created.
Using Filezilla client, I uploaded the entire phpBB3 directory to the root directory Public_HTML/) of my Drupal installation.
I changed the permissions on config.php to be writable by all users (numeric value 666 in Fizezilla client)
I changed the permissions on the following directories to be writable by all users (numeric value 777 in Fizezilla client):
store/,
cache/,
files/ and
images/avatars/upload/

To start the installation process, I typed the Drupal site url + install/index.php to start phpBB installation. My Drupal 6.3 site is http://voxbikol.net63.net/, so I typed http://voxbikol.net63.net/install/index.php. (Typing http://voxbikol.net63.net/install will do).

In the installation dialog, I clicked the INSTALL tab and fill out all the requested information:
host name
database name
database username and password

As instructed, I removed the entire install/ and docs/ directory in my remote site before opening the newly installed phpBB. I also changed the permissions on config.php to be writable only by myself (numeric value 644 in Fizezilla client)

With the above mentioned directories deleted, I typed http://voxbikol.net63.net/phpBB3 in my browser and the stand alone phpBB version 3.0.2 opened. I was automatically led to the Administator panel, where I must enter my phpBB admin user name and password. The same user name and password of the Drupal web site administrator should be entered.

Keep logged on to phpBB as we proceed to the next steps.

Installing and Configuring Drupal phpBBforum Moodule

1) Download the phpBBforum module from http://drupal.org/project/phpbbforum or
from http://vgb.org.ru.
Unpack the archive.

2) Install phpbb mod phpbbdrupal.
Go to the directory .../phpbbforum/contrib/phpbbdrupal/
You must at least patch file functions_user.php to avoid name conflict
in function user_delete.

Copy the file “function_user.php” located here:
[phpbbforum > contrib > phpbbdrupal > root > includes] ... to ...
[phpbb3 > includes] ... replacing the existing “function_user.php” file there.

Then, if you are using subsilver2 theme, copy the four icons named:
“icon_home.gif,” “icon_members.gif,” “icon_pages.gif,” “icon_ucp.gif” ... from ...
[phpbbforum > contrib > phpbbdrupal > root > styles > subsilver2 > theme > images] ... into ...
[phpBB3 > styles > subsilver2 > theme > images]

Then, if you are using prosilver theme
and would like to hide the vertical scrollbar in Firefox in iframe,
you may copy file “common.css” located here:
[phpbbforum > contrib > phpbbdrupal > root > styles > prosilver > theme] ... to ...
[phpBB3 > styles > prosilver > theme] ... replacing the existing
“common.css” file there.

or

You may simple to copy content of directory contrib/phpbbdrupal/root/ to your phpbb
root directory

3) Copy phpbbforum directory to your modules directory
sites/all/modules/phpbbforum/
Do not copy .../phpbbforum/contrib/ subdirectory or you may delete it.

phpbbforum install paths

Module -------------------------> Your site paths
+/phpbbforum -------------------> +/sites/all/modules/phpbbforum
(Path to phpBB api file: sites/all/modules/phpbbforum/includes/)
+/includes -------------------> +/sites/all/modules/phpbbforum/includes/
phpbb_api.php ----------------> phpbb_api.php (phpBB api file name:)
phpbb_api_subs.php -----------> phpbb_api_subs.php
phpbb_api_recent.php ---------> phpbb_api_recent.php
+/contrib
+/phpbbdrupal (phpBB forum root path: /home/vb/www/example.com/public_html/phpBB3/)
+/root ---------------------> +/phpBB3/
+/includes -----------------> +/includes
functions_user.php ----------> functions_user.php (replace or patch)
+/styles -------------------> +/styles

4) To test how you will be authenticated, login to your phpBB forum as admin.
It is assumed that you have both usernames with the same name ('admin' or your name) and the same password.
If you do not have so, change.

5) Open new window in browser with your Drupal site, login as admin,
navigate to Administer » modules and enable the phpBBforum and profile module.

6) Navigate to phpBBforum settings and enter the path to
phpBB root (path to forum's config.php file).
Save settings and ensure that phpBBforum successfully connected
to the phpBB database and you are authenticated.

Your path settings should look like this

phpBB forum root path:
/home/vb/www/example.com/public_html/phpbb/
Path to forum directory. Enter the full directory path where phpBB is installed.

Path to phpBB api file:
sites/all/modules/phpbbforum/includes/
Enter the full directory path where phpBB api file is located.

phpBB api file name:
phpbb_api.php
Enter phpBB api file name.

You should see in phpBBforum settings

Successfully locating phpBB installation.
Successfully locating sites/all/modules/phpbbforum/includes/phpbb_api.php.
Successfully connected to the phpBB database.
Successfully authenticated phpBB user: admin.

If you see Anonymous beenig logged in phpBB and Drupal as admin,
it is probably mean your settings are wrong.

You should go to phpBB settings and revise Server and qookie settings or do something else
in your environment, site and forum layout and settings.

7) Ensure that phpBB profile fields map with corresponding
drupal profile.module fields.

8) Ensure that corresponding profile.module fields exist.
If necessary create profile.module fields that match with
phpBB profile fields.

9) Navigate to Blocks.
Enable phpBBforum: Hidden authentication block.
Do not disable it in the future if you want advanced synchronyzation.
In configure add at least
(*) Show on every page except the listed pages.
user/reset/*
user/password
Enable the phpBBforum blocks you want to use (optional).

10) How to make phpBB work in frame

1. Go to Administer › Site configuration › phpBBforum settings

phpBB display way:
In the window
X In frame inside Drupal page

Save configuration

2. Go to Administer › Site configuration > Performance
Clear cached data

3. Go to Administer › Site building > Menus > Navigation
See Menu item with blank title in state (Disabled)
You may enable it if you do not want phpbbforum in Primary links

If you enable it your forum page will be with title.
Reset will help to remove the page title if you disable it back.

4. Go to Administer › Site building › Menus › Primary links
Enter Menu item phpbbforum.

Main page and link to phpBB in frame is

phpbbforum

To change this name you may add URL aliases (core module Path must be enabled).

Add next URL aliases (System path -> URL Alias)

For the path 'forums'

phpbbforum -> forums
phpbbforum/viewtopic.php -> forums/viewtopic.php
phpbbforum/viewforum.php -> forums/viewforum.php
phpbbforum/viewonline.php -> forums/viewonline.php
phpbbforum/memberlist.php -> forums/memberlist.php
phpbbforum/posting.php -> forums/posting.php
phpbbforum/search.php -> forums/search.php
phpbbforum/ucp.php -> forums/ucp.php
phpbbforum/mcp.php -> forums/mcp.php
phpbbforum/faq.php -> forums/faq.php
phpbbforum/report.php -> forums/report.php
phpbbforum/adm/index.php -> forums/adm/index.php

Administer › Site building › URL aliases › Add alias

Existing system path: http://example.com/phpbbforum

Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1+2.

http://example.com/forums

Specify an alternative path by which this data can be accessed.
For example, type "about" when writing an about page.
Use a relative path and don't add a trailing slash or the URL alias won't work.

All links from blocks will have that path 'forums' instead of system phpbbforum.

It works with or without Clean URLs enabled.

11. Pay attention to Drupal User settings

(*) Visitors can create accounts and no administrator approval is required.

Clear checkbox
[ ] Require e-mail verification when a visitor creates an account
If this box is checked, new users will be required to validate their e-mail address prior to logging into the site, and will be assigned a system-generated password. With it unchecked, users will be logged in immediately upon registering, and may select their own passwords during registration.

Go to User settings

(*) Visitors can create accounts and no administrator approval is required.

Clear checkbox
[ ] Require e-mail verification when a visitor creates an account
If this box is checked, new users will be required to validate their e-mail address prior to logging into the site, and will be assigned a system-generated password. With it unchecked, users will be logged in immediately upon registering, and may select their own passwords during registration.

12. Pay attention to phpBB Settings

User registration settings

Account activation: () Disable (*) None () By User () By Admin
This determines whether users have immediate access to the board or if confirmation is required. You can also completely disable new registrations.

If you set By User, user must to login first to phpBB and after that you will see that he is registered.
Set to None for test purposes.

Username length:
Minimum and maximum number of characters in usernames. [1] [30]

Password length:
Minimum and maximum number of characters in passwords. [5] [30]

Security settings

Check IP against DNS Blackhole List: () Yes (*) No

You may switch off
Check e-mail domain for valid MX record: () Yes (*) No
If enabled, the e-mail domain provided on registration and profile changes is checked for a valid MX record.

Cookie settings
These details define the data used to send cookies to your users browsers. In most cases the default values for the cookie settings should be sufficient. If you do need to change any do so with care, incorrect settings can prevent users logging in.

Cookie settings
Cookie domain:
Cookie path:

Server settings

Server URL settings

Domain name:
The domain name this board runs from (for example: www.example.com).

Script path:
The path where phpBB is located relative to the domain name, e.g. /phpBB3.

You should revise all settings that may affect the behavior of the module.

Install first locally and ensure that with your settings it works as you expect.

Upgrade
------------------------------------------------------------------------------

1) Replace old files in your modules directory .../modules/phpbbforum/
2) Login to your phpBB forum as admin.
3) Login to your Drupal site (www.example.com/user/login will help you).
4) Navigate to phpBBforum settings and ensure that phpBBforum
successfully connected to the phpBB database and you are authenticated.
5) Navigate to Blocks.
Enable the phpBBforum blocks you want to use.

 

 

Cross Compiling with distcc

 

Introduction

This page describes a novel technique that eliminates some of the complexity of normal cross-compiling. A classic problem with cross-compiling software for Unix-like systems is that many of the build systems (particularly the GNU auto tools) run small test programs as part of the build system to check for specific features or bugs. Traditional cross-compilation environments do not allow these programs to run and the builds therefore fail.

 

Setup

After installing distcc and distccd. edit /etc/sysconfig/distccd. In my case, I set the following

DISTCCPATH="/opt/toolchain/bin"
OPTIONS="--nice 5 --jobs 5 --allow 192.168.0.0/24 --port 3632"

Masquerading the compilers

On the client side, I masqueraded the compilers so that distcc would be called. My compilers are located in /opt/toolchain/bin. So I did the following:

cd /opt/toolchain/bin
mkdir distcc
cd distcc
ln -s /usr/bin/distcc arm-linux-gcc
ln -s /usr/bin/distcc arm-linux-g++
ln -s /usr/bin/distcc arm-linux-c++

the PATH variable has to reflect this new change, and you need to create a pointer to the distcc path BEFORE the path of the original, as in

PATH="/opt/toolchain/bin/distcc:/opt/toolchain/bin"

On the client (Building) machine, you need to put DISTCC_HOSTS in /etc/profile. By default, the limit of 4 compiles on each machine is the default but can be changed with '/x' where x is the number of processes on the other hosts

 

export DISTCC_HOSTS="machine1/2 machine2/2 localhost/4"

 

 

 

Colorized Console man Viewer

Here is a little trick to colorize man pages. Place these lines in your .bashrc file (~/.bashrc):

 

export LESS_TERMCAP_mb=$'\E[01;31m'       # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m'  # begin bold
export LESS_TERMCAP_me=$'\E[0m'           # end mode
export LESS_TERMCAP_se=$'\E[0m'           # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m'    # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m'           # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline

Then the output of man looks like this:

Bash Prompt Tricks

Here is a trick I use in ~/.bashrc to make a nice fancy prompt

 

#!/bin/bash
DATESTR=$(date +%m/%d/%y)
TIMESTR=$(date +%H:%m)
LIGHTRED="\[\033[01;31m\]"
RED="\[\033[02;31m\]"
LIGHTGREEN="\[\033[01;32m\]"
GREEN="\[\033[02;32m\]"
LIGHTCYAN="\[\033[01;36m\]"
CYAN="\[\033[02;36m\]"
NORM="\[\033[00m\]"
BLUE="\[\033[02;34m\]"
LIGHTBLUE="\[\033[01;34m\]"
MAGENTA="\[\033[02;35m\]"
LIGHTMAGENTA="\[\033[01;35m\]"
YELLOW="\[\033[02;33m\]"
LIGHTYELLOW="\[\033[01;33m\]"
PS1="${LIGHTRED}[${LIGHTGREEN}u${LIGHTBLUE}@${LIGHTGREEN}h${LIGHTRED}] ${LIGHTCYAN} \ 
{${LIGHTRED}${DATESTR} ${LIGHTMAGENTA}${TIMESTR}${LIGHTCYAN}} ${NORM}${CYAN} \
(${LIGHTCYAN}w${NORM}${CYAN})n${LIGHTYELLOW}> ${NORM}"
 

The result of the above is this: 


[root@jim] {04/09/09 16:04} (~)
> ls -la

 


 

 

Malloc Tracing

Malloc Tracing

I recently had to use this feature to find a memory leak in some code I was debugging.

Including in your code

You need to add the following into your #include section of your code:

#include <mtrace.h>

 This includes the malloc tracing headers. in your main() function, add the following near the top of the function:

 

int main(int argc, char *argv[])
{
    ...
    mtrace();
    ...
    ...
}

 

 Setting up the Environment for Tracing

After your program is compiled, you need to specify where the tracing file is located. Export the following variable before launching your program:

export MALLOC_TRACE="/tmp/mtrace.txt"

 

 Using mtrace.pl

I had to dig around to find this, but this perl script will go through and extrapolate which malloc calls are not freed and print a list of them.

Here is a sample of the output of mtrace

 


 Mtrace Source Code

 

#! /usr/bin/perl
#eval "exec /usr/bin/perl -S $0 $*"
#    if 0;
# Copyright (C) 1997-2002, 2003, 2004 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Ulrich Drepper <drepper@gnu.org>, 1997.
# Based on the mtrace.awk script.
 
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
 
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
 
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
 
$VERSION = "2.3.6";
$PACKAGE = "libc";
$progname = $0;
 
sub usage {
    print "Usage: mtrace [OPTION]... [Binary] MtraceDatan";
    print "  --help       print this help, then exitn";
    print "  --version    print version number, then exitn";
    print "n";
    print "For bug reporting instructions, please see:n";
    print "<http://www.gnu.org/software/libc/bugs.html>.n";
    exit 0;
}
 
# We expect two arguments:
#   #1: the complete path to the binary
#   #2: the mtrace data filename
# The usual options are also recognized.
 
arglist: while (@ARGV) {
    if ($ARGV[0] eq "--v" || $ARGV[0] eq "--ve" || $ARGV[0] eq "--ver" ||
	$ARGV[0] eq "--vers" || $ARGV[0] eq "--versi" ||
	$ARGV[0] eq "--versio" || $ARGV[0] eq "--version") {
	print "mtrace (GNU $PACKAGE) $VERSIONn";
	print "Copyright (C) 2005 Free Software Foundation, Inc.n";
	print "This is free software; see the source for copying conditions.  There is NOn";
	print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.n";
	print "Written by Ulrich Drepper <drepper@gnu.org>n";
 
	exit 0;
    } elsif ($ARGV[0] eq "--h" || $ARGV[0] eq "--he" || $ARGV[0] eq "--hel" ||
	     $ARGV[0] eq "--help") {
	&usage;
    } elsif ($ARGV[0] =~ /^-/) {
	print "$progname: unrecognized option `$ARGV[0]'n";
	print "Try `$progname --help' for more information.n";
	exit 1;
    } else {
	last arglist;
    }
}
 
if ($#ARGV == 0) {
    $binary="";
    $data=$ARGV[0];
} elsif ($#ARGV == 1) {
    $binary=$ARGV[0];
    $data=$ARGV[1];
 
    if ($binary =~ /^.*[/].*$/) {
	$prog = $binary;
    } else {
	$prog = "./$binary";
    }
    if (open (LOCS, "env LD_TRACE_LOADED_OBJECTS=1 $prog |")) {
	while (<LOCS>) {
	    chop;
	    if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) {
		$locs{$1} = $2;
	    }
	}
	close (LOCS);
    }
} else {
    die "Wrong number of arguments, run $progname --help for help.";
}
 
sub location {
    my $str = pop(@_);
    return $str if ($str eq "");
    if ($str =~ /.*[[](0x[^]]*)]:(.)*/) {
	my $addr = $1;
	my $fct = $2;
	return $cache{$addr} if (exists $cache{$addr});
	if ($binary ne "" && open (ADDR, "arm-linux-addr2line -e $binary $addr|")) {
	    my $line = <ADDR>;
	    chomp $line;
	    close (ADDR);
	    if ($line ne '??:0') {
		$cache{$addr} = $line;
		return $cache{$addr};
	    }
	}
	$cache{$addr} = $str = "$fct @ $addr";
    } elsif ($str =~ /^(.*):.*[[](0x[^]]*)]$/) {
	my $prog = $1;
	my $addr = $2;
	my $searchaddr;
	return $cache{$addr} if (exists $cache{$addr});
	if ($locs{$prog} ne "") {
	    $searchaddr = sprintf "%#x", $addr - $locs{$prog};
	} else {
	    $searchaddr = $addr;
	    $prog = $binary;
	}
	if ($binary ne "" && open (ADDR, "arm-linux-addr2line -e $prog $searchaddr|")) {
	    my $line = <ADDR>;
	    chomp $line;
	    close (ADDR);
	    if ($line ne '??:0') {
		$cache{$addr} = $line;
		return $cache{$addr};
	    }
	}
	$cache{$addr} = $str = $addr;
    } elsif ($str =~ /^.*[[](0x[^]]*)]$/) {
	my $addr = $1;
	return $cache{$addr} if (exists $cache{$addr});
	if ($binary ne "" && open (ADDR, "addr2line -e $binary $addr|")) {
	    my $line = <ADDR>;
	    chomp $line;
	    close (ADDR);
	    if ($line ne '??:0') {
		$cache{$addr} = $line;
		return $cache{$addr};
	    }
	}
	$cache{$addr} = $str = $addr;
    }
    return $str;
}
 
$nr=0;
open(DATA, "<$data") || die "Cannot open mtrace data file";
while (<DATA>) {
    my @cols = split (' ');
    my $n, $where;
    if ($cols[0] eq "@") {
	# We have address and/or function name.
	$where=$cols[1];
	$n=2;
    } else {
	$where="";
	$n=0;
    }
 
    $allocaddr=$cols[$n + 1];
    $howmuch=hex($cols[$n + 2]);
 
    ++$nr;
    SWITCH: {
	if ($cols[$n] eq "+") {
	    if (defined $allocated{$allocaddr}) {
		printf ("+ %#010x Alloc %d duplicate: %s %sn",
			hex($allocaddr), $nr, &location($addrwas{$allocaddr}),
			$where);
	    } else {
		$allocated{$allocaddr}=$howmuch;
		$addrwas{$allocaddr}=$where;
	    }
	    last SWITCH;
	}
	if ($cols[$n] eq "-") {
	    if (defined $allocated{$allocaddr}) {
		undef $allocated{$allocaddr};
		undef $addrwas{$allocaddr};
	    } else {
		printf ("- %#010x Free %d was never alloc'd %sn",
			hex($allocaddr), $nr, &location($where));
	    }
	    last SWITCH;
	}
	if ($cols[$n] eq "<") {
	    if (defined $allocated{$allocaddr}) {
		undef $allocated{$allocaddr};
		undef $addrwas{$allocaddr};
	    } else {
		printf ("- %#010x Realloc %d was never alloc'd %sn",
			hex($allocaddr), $nr, &location($where));
	    }
	    last SWITCH;
	}
	if ($cols[$n] eq ">") {
	    if (defined $allocated{$allocaddr}) {
		printf ("+ %#010x Realloc %d duplicate: %#010x %s %sn",
			hex($allocaddr), $nr, $allocated{$allocaddr},
			&location($addrwas{$allocaddr}), &location($where));
	    } else {
		$allocated{$allocaddr}=$howmuch;
		$addrwas{$allocaddr}=$where;
	    }
	    last SWITCH;
	}
	if ($cols[$n] eq "=") {
	    # Ignore "= Start".
	    last SWITCH;
	}
	if ($cols[$n] eq "!") {
	    # Ignore failed realloc for now.
	    last SWITCH;
	}
    }
}
close (DATA);
 
# Now print all remaining entries.
@addrs= keys %allocated;
$anything=0;
if ($#addrs >= 0) {
    foreach $addr (sort @addrs) {
	if (defined $allocated{$addr}) {
	    if ($anything == 0) {
		print "nMemory not freed:n-----------------n";
		print ' ' x (10 - 7), "Address     Size     Callern";
		$anything=1;
	    }
	    printf ("%#010x %#8x  at %sn", hex($addr), $allocated{$addr},
		    &location($addrwas{$addr}));
	}
    }
}
print "No memory leaks.n" if ($anything == 0);
 
exit $anything != 0;
 

 

 

 

 

Bash Control Key Reference

 
About the listkayboard

An average terminal session accepts a range of control keys. This is a list for a system running Bash, the (by far) most common scenario for a linux user. The list assumes no one has changed the default behavior.

The key is the key to press, ^A meaning C-a or Ctrl+A. A key followed by a '!' means the key is very important to know, one followed by '+' means it's not important as such, but lifechangingly useful. One should try out the various other commands to see if they are worth knowing or not. (Editors: please do not add !/+ to your own pet favorite, it cheapens the system)

The function is what the key does. Multiple uses are separated by slashes (/).

The User is the part of the system that is responsible for handling the key. The terminal and the shell have a symbiotic relationship, often both will be required to complete an action. The User is in any case the part one can modify to remap the key. If the key has multiple functions, users will be separated by slashes as well.

Different terminals can have different settings for certain keys, Backspace especially (some uses ^? for example).

The list

Key (and importance) Function User
^A GNU Screen multifunction key/Go to the beginning of the line Screen / Bash
^B One char backwards (like left-arrow) Bash
^C ! Interrupt a running program (SIGINT) Terminal
^D ! Ends input for interactive programs. The program will act as if you piped a file to it that now has reached the end, and will usually terminate itself. For this reason it's also a simple way of logging out (an alternative to exit). Terminal (though the current program will do what it please when it encounters the event)
^E Go to the end of the line Bash
^F One char forward (like right-arrow) Bash
^G Abort the current editing command (for composite command such as M-5 Up-Arrow (M-5 meaning Meta-5 or Alt+5) which would repeat the Up-Arrow action five times. Pressing ^G after M-5 would abort it, meaning a subsequent Up-Arrow key would just function as normal and just act once) Bash
^H Erase the last character Terminal (this is the Backspace key)
^I Move the cursor to the next column divisible by eight (for alignment)/autocomplete commands and file names (typing Terminal / Bash (This is the Tab key)
^J Move the cursor to the next line*/ Execute the current command line Terminal / Bash (this is the Return key)
^K Remove the parts of the command line after the cursor Bash
^L + Redraw the screen Bash (and most curses applications or textmode programs and games that draw graphics using characters and symbols)
^M Move the cursor to the next line* / Execute the current command line Terminal / Bash (this is the Enter key)
^N Move to next (more recent) history entry (same as down-arrow) Bash
^O Execute the current command and start editing the next history entry (for redoing multiple commands that need small edits) Bash
^P Move to previous (earlier) history entry (same as up-arrow) Bash
^Q Allow a terminal to continue display after being paused with ^S Terminal
^R + Search history backwards, allows one to search the history by keyword rather than hit ^P or Up-arrow to locate an old command. Bash
^S Temporarily stop the terminal from displaying more information. It will continue by pressing ^Q Terminal
^T Swap positions of the current and previous chars, and advance one char forward on the command line Bash
^U Delete from the current point backwards, complement to ^K Bash
^V Insert the next character literally, one can use ^V^S to type a ^S character rather than stop the terminal. Terminal
^W Delete one word backwards Terminal
^X Bash multifunction key. One command is ^X^E which will invoke the users editor on the current command and execute it when they exit the editor (very useful for long command lines) Bash
^Y Copy previously killed text (^W, ^K, ^U, ...) onto the current command line (functioning in effect as cut&paste) Bash
^Z ! Suspend the current job and get back to the shell Terminal
^[ Mostly a composing character meaning Meta/Alt. ^[5 will repeat the next action five times. Bash (this is the Escape key)
^/ Abort a running program (SIGQUIT) Terminal
^] Search char forward, pressing ^] V will place the cursor on the next V on the current command line Bash
^_ Undo, restore the command line to what it was before the last edit (since _ is shift-minus on US layouts, this command is actually Ctrl-Shift-Minus) Bash

 * Strictly, and under certain terminal modes (stty -onlcr), ^J (newline) will move the the next line at the same position, while ^M (carriage return) will move to the beginning of the same line.

Changing shortcuts

 

When to change keys

It is possible to change most of the shortcuts to suit one's need. Changing terminal keys such as ^C, ^D and ^Z is not recommend however, this will cause much confusion and grief when one uses other terminals or let others use one's own (imagine not finding ^C in an emergency!). It is in fact used as a prank on those who leave their terminals unattended.

Bash keys such as ^K/^U can be customized, since advanced editing commands are a mere convenience, not vital to the operation of the system. There are many, many other bash commands, some which do not even have key combinations bound do them by default. The manual mentions them all.

How to change keys

Bash keys are changed by editing ~/.inputrc or using bind (not to be confused with the name server). Terminal keys can be changed with stty. The manual for bash and stty will give directions and possible input.

 

Syndicate content