Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
GetNetWise: You
e One Click Away

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents
Up to --> Basic Administration

· Terminals
· Terminal Capabilities
· Terminal Settings

Glossary
MoreInfo
Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
FAQ
Copyright Info
Terms of Use
Privacy Info
Disclaimer
WorkBoard
Thanks
Donations
Advertising
Masthead / Impressum
Your Account

Communication
Feedback
Forums
Private Messages
Recommend Us
Surveys

Features
HOWTOs
News
News Archive
Submit News
Topics
User Articles
Web Links

Google
Google


The Web
linux-tutorial.info

Who's Online
There are currently, 163 guest(s) and 4 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here

  
Linux Tutorial - Basic Administration - Terminals - Terminal Settings
  Terminal Capabilities  ---- Printers and Interfaces  


Terminal Settings

Whenever you work with an application, what you see is governed by a couple of mechanisms. If you have a serial terminal, the flow of data is controlled by the serial line characteristics, including the baud rate, the number of data bits, parity, and so on. One aspect that is often forgotten or even unknown to many users is the terminal characteristics, which are used to control the physical appearance on the screen. However, most of the characteristics still apply, even if you are not connected through a serial terminal.

The reason is that these conventions date back to the time of tele-typewriters. You had a keyboard on one end of the connection connected to a printer that printed out every single character you typed. At that time, it was essential that both ends knew what characteristics the connection had. Even as technology advanced there was still a need to ensure both sides communicated in the exact same way. Since you could not guarantee that the default settings were the same on both ends, you needed a way to change the characteristics so that both ends matched.

As I mentioned elsewhere, the serial line characteristics are initially determined by the gettydefs file. The characteristics are often changed within the users' startup scripts (.profile, .login, etc.). In addition, you can change them yourself by using the stty command. Rather than jumping to changing them, lets take a look at what our current settings are, which we also do with the stty command. With no arguments, stty might give us something like this:

speed 38400 baud; line = 0; -brkint ixoff -imaxbel -iexten -echoctl

This is pretty straightforward. Settings that are Boolean values (on or off) are listed by themselves if they are on (ixoff) or have a minus sign in front if they are turned off (-brkint). Settings that can take on different values (like the baud rate) appear in two formats: one in which the value simply follows the setting name (speed 38400 baud) and one in which an equal sign is between them (line=0).

In general, if a setting has discrete values, like the baud rate, there is no equal sign. There is only a discrete number of baud rates you could have (i.e., there is no 2678 baud). If the stty setting is for something that could take on "any" value (like the interrupt key), then there is an equal sign. Normally, the interrupt key is something like Ctrl-C or the Delete key. However, it could be the f key or the Down-Arrow or whatever.

This example shows the more "significant" terminal (stty) settings. The top line shows the input and output speed of this terminal, which is 38400. On the second line, we see that sending a break sends an interrupt signal (-brkint).

Setting these values is very straightforward. For Boolean settings (on or off), the syntax is simply

to turn it on or

(note the minus sign in front)

to turn it off.

For example, if I wished to turn on input stripping (in which the character is stripped to 7 bits), the command would look like this:

Settings that require a value have the following syntax:

So, to set the speed (baud rate) to 19200, the syntax would look like this:

To set the interrupt character to Ctrl-C, we would enter

Note that ^C is not two separate characters. Instead, when you type it, hold down the Ctrl key and press "c." In most documentation you will see that the letter appears as capital although you actually press the lowercase letter. Sometimes you want to assign the particular characteristic to just a single key. For example, it is often the case that you want to use the backspace key to send an "erase" character. What the erase character does is tell the system to erase the last character, which is exactly what the backspace is supposed to do. Just like the case where you press the control key and the character, stty settings for single keys are done the same way. For example, you would type "stty erase " and the press the backspace key (followed by the enter key, or course). What you would see might look like this:

The ^? is typically what the backspace key will send (at least that is the visual representation of what the backspace sends). You can get the same result by press CTRL-?.

If the default output does not show the particular characteristic you are looking for, you can use the -a option to show all the characteristics. You might end up with output like this:

speed 38400 baud; rows 25; columns 80; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon ixoff -iuclc -ixany -imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon -iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt -echoctl echoke

Here were see a number of well-known characteristics, such as the baud rate, the numbers of rows and columns, interrupt character, end of file character and so on. Some of which we talked about in the section on working with the system. For details on what the rest of these mean, please see the stty(1L) man-page.

In principle, you can set any key to any one of the terminal characteristics. For example, I could set the interrupt key to be the letter g:

Although this not does make too much sense, it is possible. What does make more sense is to set the characteristic to something fitting for your keyboard. For example, you might be using telnet to move between system. The key sequence that your backspace sends may not be ^? (often it is ^H) and you want to set it accordingly (or the case is reversed, as we discussed above.)

To save, change, and then restore the original values of your stty settings, use the -g option. This option outputs the stty settings as a strings of hexadecimal values. For example, I might get something like this:

500:5:d050d:3b:7f:1c:8:15:4:0:0:0:0:0:1a:11:13:0:0:0:0:0:0:0:0:0

We can run the stty command to get these values and make the changes, then run stty again and use these values as the argument. We don't have to type in everything manually; we simply take advantage of the fact that variables are expanded by the shell before being passed to the command. You could use this to add an additional password to your system:

echo "Enter your password: \c" oldstty=`stty -g` stty -echo intr ^- read password stty $oldstty

Assign the output of the stty command to the variable old, then change the stty settings so that the characters you input are not echoed to the screen and the interrupt key is disabled (this is done with

stty -echo intr ^-
). Then read a line from the keyboard and reset the stty settings to their old value.

 Previous Page
Terminal Capabilities
  Back to Top
Table of Contents
Next Page 
Printers and Interfaces


MoreInfo

Test Your Knowledge

User Comments:


You can only add comments if you are logged in.

Copyright 2002-2009 by James Mohr. Licensed under modified GNU Free Documentation License (Portions of this material originally published by Prentice Hall, Pearson Education, Inc). See here for details. All rights reserved.
  
Show your Support for the Linux Tutorial

Purchase one of the products from our new online shop. For each product you purchase, the Linux Tutorial gets a portion of the proceeds to help keep us going.


Login
Nickname

Password

Security Code
Security Code
Type Security Code


Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!


Amazon Wish List

Did You Know?
You can get all the latest Site and Linux news by checking out our news page.


Friends



Tell a Friend About Us

Bookmark and Share



Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.07 Seconds