In the BASH shell, the history utility keeps a record of the most recent commands you have executed. The commands are numbered starting at 1, and a limit exists to the number of commands remembered—the default is 500. The history utility is a kind of short-term memory, keeping track of the most recent commands you have executed. To see the set of your most recent commands, type history on the command line and press ENTER. A list of your most recent commands is then displayed, preceded by a number.
$ history
1 cp mydata today
2 vi mydata
3 mv mydata reports
4 cd reports
5 ls
Each of these commands is technically referred to as an event. An event describes an action that has been taken—a command that has been executed. The events are numbered according to their sequence of execution. The most recent event has the largest number. Each of these events can be identified by its number or beginning characters in the command.
The history utility enables you to reference a former event, placing it on your command line and enabling you to execute it. The easiest way to do this is to use the UP ARROW and DOWN ARROW keys to place history events on your command line, one at a time. You needn’t display the list first with history. Pressing the UP ARROW key once places the last history event on your command line. Pressing it again places the next history event on your command. Pressing the DOWN ARROW key places the next event on the command line. You can use certain control and meta keys to perform other history operations like searching the history list. A meta key is the ALT key, or the ESC key on keyboards that have no ALT key. The ALT key is used here. ALT-< will move you to the beginning of the history list; ALT-N will search it. CTRL-S and CTRL-R will perform incremental searches, displaying matching commands as you type in a search string.
Custom Search
Introduction
A shell is a command line interpretor. It takes commands and executes them. As such, it implements a programming language. The Bourne shell is used to create shell scripts -- ie. programs that are interpreted/executed by the shell. You can write shell scripts with the C-shell; however, this is not covered here.
Necessity of Structured Shell Programming
Shell scripts remain a staple of the business world.With high development costs, it is not practical to develop everything in a high-level language. Many business processes are simply a matter of following a series of steps, after which the results are labeled and archived.This is the very type of activity scripts are made to handle. Over time, shells have collected new features, often by copying the capabilities of other shells. In his book, The Humane Interface, Apple Macintosh interface designer Jef Raskin once spoke with a pilot regarding the design of the plane’s autopilot.The device was designed with five ways to enter coordinates.The reason for this design was to reduce training costs by emulating other autopilots. However, a pilot pointed out that the operator of the aircraft is responsible for knowing how to operate every piece of equipment, and that meant he had to know how to adjust the autopilot in each of the five ways.
Many shells, including Bash, have developed a mixture of features with specialized or arcane applications. Like the autopilot, it is not always clear how these features should be
used nor which features are provided primarily for compatibility.Too often, poorly designed scripts are all-but illegible to another programmer, or even to the same programmer a few months after a script was hastily assembled.
This presents a problem for serious business scripts.The cost of developing a highlevel language solution is high, but a disorganized shell script can be expensive to maintain
over time. As the needs of the business change, and the shell script is modified by successive generations of programmers, the problem escalates.
As a rule of thumb, business programs never go away.At one place I recently worked,what started off as a simple shell script used to print reports gradually evolved into a Web-based reporting system complete with personal customizations and secure access.
The original programmer had no idea what his script would become. Because of the essential openness and complex syntax of Bash, it’s to the benefit of any serious project to adapt some kind of standard. Bash is very forgiving, but the costs are not. For example, there are many ways to add 2 + 2 in Bash. Like the autopilot anecdote, it’s not practical to expect the programmers who maintain the scripts to have to deal with this kind of redundancy. Likewise, shell word quoting is sometimes optional, sometimes required, depending on the context. A command that works with one form of quotation can suddenly stop working when different data appears in the quotes. Issues like shell word quoting, specialized capabilities, or portability features, when abused, can lead to increased maintenance and long-term development costs.
Many shells, including Bash, have developed a mixture of features with specialized or arcane applications. Like the autopilot, it is not always clear how these features should be
used nor which features are provided primarily for compatibility.Too often, poorly designed scripts are all-but illegible to another programmer, or even to the same programmer a few months after a script was hastily assembled.
This presents a problem for serious business scripts.The cost of developing a highlevel language solution is high, but a disorganized shell script can be expensive to maintain
over time. As the needs of the business change, and the shell script is modified by successive generations of programmers, the problem escalates.
As a rule of thumb, business programs never go away.At one place I recently worked,what started off as a simple shell script used to print reports gradually evolved into a Web-based reporting system complete with personal customizations and secure access.
The original programmer had no idea what his script would become. Because of the essential openness and complex syntax of Bash, it’s to the benefit of any serious project to adapt some kind of standard. Bash is very forgiving, but the costs are not. For example, there are many ways to add 2 + 2 in Bash. Like the autopilot anecdote, it’s not practical to expect the programmers who maintain the scripts to have to deal with this kind of redundancy. Likewise, shell word quoting is sometimes optional, sometimes required, depending on the context. A command that works with one form of quotation can suddenly stop working when different data appears in the quotes. Issues like shell word quoting, specialized capabilities, or portability features, when abused, can lead to increased maintenance and long-term development costs.
The Origin of Linux
The Linux operating system was created as a hobby by a young student, Linus Torvalds, at the University of Helsinki in Finland. Linus, interested in the Unix clone operating system Minix, wanted to create an expanded version of Minix with more capabilities. He began his work in 1991 when he released version 0.02 and invited programmers to participate in his project.Version 1.0 was released in 1994.
Linux uses GNU General Public License (GPL) and its source code is freely available to everyone. Linux distributions, CD-ROMs with the Linux kernel and other software ready for installation, do not have to be free, but the Linux source code must remain available. Making source code available is known as distributing open source. The word “Linux” is properly pronounced using a Swedish accent, making it difficult to say in North America. It is most often pronounced with a short “i” and with the firstsyllable stressed, as in LIH-nicks, but it is sometimes pronounced LYE-nicks (the anglicized “Linus’ Unix”) or LEE-nucks. Strictly speaking, Linux refers to the operating system kernel that starts and manages other programs and provides access to system resources.The various open source shells, compilers, standard libraries, and commands are a part of another project called GNU. The GNU project was started by the Free Software Foundation (FSF) as an attempt to create a free version of Unix.The main Linux C compiler, gcc, is a part of the GNU project. There is also a GNU kernel project, but the Linux kernel has largely superseded thiseffort.
X Windows is also not strictly a part of Linux. Xfree86, the open source version of X Windows, was adapted to the Linux operating system and was released under a different license.
Linux uses GNU General Public License (GPL) and its source code is freely available to everyone. Linux distributions, CD-ROMs with the Linux kernel and other software ready for installation, do not have to be free, but the Linux source code must remain available. Making source code available is known as distributing open source. The word “Linux” is properly pronounced using a Swedish accent, making it difficult to say in North America. It is most often pronounced with a short “i” and with the firstsyllable stressed, as in LIH-nicks, but it is sometimes pronounced LYE-nicks (the anglicized “Linus’ Unix”) or LEE-nucks. Strictly speaking, Linux refers to the operating system kernel that starts and manages other programs and provides access to system resources.The various open source shells, compilers, standard libraries, and commands are a part of another project called GNU. The GNU project was started by the Free Software Foundation (FSF) as an attempt to create a free version of Unix.The main Linux C compiler, gcc, is a part of the GNU project. There is also a GNU kernel project, but the Linux kernel has largely superseded thiseffort.
X Windows is also not strictly a part of Linux. Xfree86, the open source version of X Windows, was adapted to the Linux operating system and was released under a different license.
Command Line Editing
The BASH shell, which is your default shell, has special command line editing capabilities that you may find helpful as you learn Linux (see Table 3-2). You can easily modify commands you have entered before executing them, moving anywhere on the command line and inserting or deleting characters. This is particularly helpful for complex commands. You can use the CTRL-F or RIGHT ARROW key to move forward a character or the CTRL-B or LEFT ARROW key to move back a character. CTRL-D or DEL deletes the character the cursor is on, and CTRL-H or BACKSPACE deletes the character before the cursor. To add text, you use the arrow keys to move the cursor to where you want to insert text and type the new characters. You can even cut words with the CTRL-W or ALT-D key and then use the CTRL-Y key to paste them back in at a different position, effectively moving the words. As a rule, the CTRL version of the command operates on characters, and the ALT version works on words, such as CTRL-T to transpose characters and ALT-T to transpose words. At any time, you can press ENTER to execute the command. The actual associations of keys and their tasks, along with global settings, are specified in the /etc/inputrc file.
Movement Commands Operation
CTRL-F, RIGHT-ARROW Move forward a character.
CTRL-B, LEFT-ARROW Move backward a character.
CTRL-A or HOME Move to beginning of line.
CTRL-E or END Move to end of line.
ALT-F Move forward a word.
ALT-B Move backward a word.
CTRL-L Clear screen and place line at top.
Editing Commands Operation
CTRL-D or DEL Delete character cursor is on.
CTRL-H or BACKSPACE Delete character before the cursor.
CTRL-K Cut remainder of line from cursor position.
CTRL-U Cut from cursor position to beginning of line.
CTRL-W Cut previous word.
CTRL-C Cut entire line.
ALT-D Cut the remainder of a word.
ALT-DEL Cut from the cursor to the beginning of a word.
CTRL-Y Paste previous cut text.
ALT-Y Paste from set of previously cut text.
CTRL-Y Paste previous cut text.
CTRL-V Insert quoted text, used for inserting control or meta (ALT) keys
as text, such as CTRL-B for backspace or CTRL-T for tabs.
ALT-T Transpose current and previous word.
ALT-L Lowercase current word.
ALT-U Uppercase current word.
ALT-C Capitalize current word.
CTRL-SHIFT-_ Undo previous change.
TABLE 3-2 Command Line Editing Operations
Movement Commands Operation
CTRL-F, RIGHT-ARROW Move forward a character.
CTRL-B, LEFT-ARROW Move backward a character.
CTRL-A or HOME Move to beginning of line.
CTRL-E or END Move to end of line.
ALT-F Move forward a word.
ALT-B Move backward a word.
CTRL-L Clear screen and place line at top.
Editing Commands Operation
CTRL-D or DEL Delete character cursor is on.
CTRL-H or BACKSPACE Delete character before the cursor.
CTRL-K Cut remainder of line from cursor position.
CTRL-U Cut from cursor position to beginning of line.
CTRL-W Cut previous word.
CTRL-C Cut entire line.
ALT-D Cut the remainder of a word.
ALT-DEL Cut from the cursor to the beginning of a word.
CTRL-Y Paste previous cut text.
ALT-Y Paste from set of previously cut text.
CTRL-Y Paste previous cut text.
CTRL-V Insert quoted text, used for inserting control or meta (ALT) keys
as text, such as CTRL-B for backspace or CTRL-T for tabs.
ALT-T Transpose current and previous word.
ALT-L Lowercase current word.
ALT-U Uppercase current word.
ALT-C Capitalize current word.
CTRL-SHIFT-_ Undo previous change.
TABLE 3-2 Command Line Editing Operations
Running Windows Software on Linux: Wine
Wine is a Windows compatibility layer that will allow you to run many Windows applications natively on Linux. Though you could run the Windows operating system on it, the actual Windows operating system is not required. Windows applications will run as if they were Linux applications, able to access the entire Linux file system and use Linux-connected devices. Applications that are heavily driver dependent, such as graphic-intensive games, most likely will not run. Others, such as newsreaders, which do not rely on any specialized drivers, may run very well. For some applications, you may also need to copy over specific Windows DLLs from a working Windows system to your Wine Windows system32 or system directory. To install Wine on your system, search for wine on you distributions repositories. For some distributions you may have to download wine directly from winehq.org. Binaries for several distributions are provided.
Once installed, a Wine menu will appear in the Applications menu. The Wine menu holds entries for Wine configuration, the Wine software uninstaller, and the Wine file browser, as well as a regedit registry editor, a notepad, and a Wine help tool. To set up Wine, a user starts the Wine Configuration tool. This opens a window with panels for Applications, Libraries (DLL selection), Audio (sound drivers), Drives, Desktop Integration, and Graphics. On the Applications panel you can select which version of Windows an application is designed for. The Drives panel will list your detected partitions, as well as your Windows-emulated drives, such as drive C:. The C: drive is really just a directory, .wine/drive_c, not a partition of a fixed size. Your actual Linux file system will be listed as the Z: drive. Once configured, Wine will set up a .wine directory on the user’s home directory (the directory is hidden, so enable Show Hidden Files in the file browser View menu to display it). Within that directory will be the drive_c directory, which functions as the C: drive, holding your Windows system files and program files in the Windows and Program File subdirectories. The System and System32 directories are located in the Windows directory. Here is where you place any needed DLL files. The Program Files directory will hold your installed Windows programs, just as they would be installed on a Windows Program Files directory. To install a Windows application with Wine, you can either use the Wine configuration tool or open a Terminal window and run the wine command with the Windows application as an argument. The following example installs the popular newsbin program: $ wine newsbin.exe To install with the Windows Configuration tool, select the Applications panel and then click Add. Some applications, such as newsbin, will also require that you use certain DLL files from a working Windows operating system. The DLL files are normally copied to the user’s .wine/drive_c/Windows/system32 directory. Icons for installed Windows software will appear on your desktop. Just double-click an icon to start up the application. It will run normally within a Linux window, as would any Linux application. Installing Windows fonts on Wine is a simple matter of copying fonts from a Windows font directory to your Wine .wine/drive_c/Windows/fonts directory. You can just copy any Windows .ttf file to this directory to install a font. You can also use the Microsoft common web fonts available from fontconfig.org (this will require cabextract to extract them). Wine will use a stripped-down window style for features like buttons and the title bar. If you want to use the XP style, download and install the Royal theme from Microsoft. Keep in mind, however, that supporting this theme is very resource intensive and will likely slow down your system.
Once installed, a Wine menu will appear in the Applications menu. The Wine menu holds entries for Wine configuration, the Wine software uninstaller, and the Wine file browser, as well as a regedit registry editor, a notepad, and a Wine help tool. To set up Wine, a user starts the Wine Configuration tool. This opens a window with panels for Applications, Libraries (DLL selection), Audio (sound drivers), Drives, Desktop Integration, and Graphics. On the Applications panel you can select which version of Windows an application is designed for. The Drives panel will list your detected partitions, as well as your Windows-emulated drives, such as drive C:. The C: drive is really just a directory, .wine/drive_c, not a partition of a fixed size. Your actual Linux file system will be listed as the Z: drive. Once configured, Wine will set up a .wine directory on the user’s home directory (the directory is hidden, so enable Show Hidden Files in the file browser View menu to display it). Within that directory will be the drive_c directory, which functions as the C: drive, holding your Windows system files and program files in the Windows and Program File subdirectories. The System and System32 directories are located in the Windows directory. Here is where you place any needed DLL files. The Program Files directory will hold your installed Windows programs, just as they would be installed on a Windows Program Files directory. To install a Windows application with Wine, you can either use the Wine configuration tool or open a Terminal window and run the wine command with the Windows application as an argument. The following example installs the popular newsbin program: $ wine newsbin.exe To install with the Windows Configuration tool, select the Applications panel and then click Add. Some applications, such as newsbin, will also require that you use certain DLL files from a working Windows operating system. The DLL files are normally copied to the user’s .wine/drive_c/Windows/system32 directory. Icons for installed Windows software will appear on your desktop. Just double-click an icon to start up the application. It will run normally within a Linux window, as would any Linux application. Installing Windows fonts on Wine is a simple matter of copying fonts from a Windows font directory to your Wine .wine/drive_c/Windows/fonts directory. You can just copy any Windows .ttf file to this directory to install a font. You can also use the Microsoft common web fonts available from fontconfig.org (this will require cabextract to extract them). Wine will use a stripped-down window style for features like buttons and the title bar. If you want to use the XP style, download and install the Royal theme from Microsoft. Keep in mind, however, that supporting this theme is very resource intensive and will likely slow down your system.
Open Source Software
Linux was developed as a cooperative open source effort over the Internet, so no company or institution controls Linux. Software developed for Linux reflects this background. Development often takes place when Linux users decide to work on a project together. The software is posted at an Internet site, and any Linux user can then access the site and download the software. Linux software development has always operated in an Internet environment and is global in scope, enlisting programmers from around the world. The only thing you need to start a Linux-based software project is a website. Most Linux software is developed as open source software. This means that the source code for an application is freely distributed along with the application. Programmers over the Internet can make their own contributions to a software package’s development, modifying and correcting the source code. Linux is an open source operating system as well. Its source code is included in all its distributions and is freely available on the Internet. Many major software development efforts are also open source projects, as are the KDE and GNOME desktops, along with most of their applications. The Netscape Communicator web browser package has also become open source, with its source code freely available. The OpenOffice office suite supported by Sun is an open source project based on the StarOffice office suite (StarOffice is essentially Sun’s commercial version of OpenOffice). Many of the open source applications that run on Linux have located their websites at SourceForge (sourceforge.net), which is a hosting site designed specifically to support open source projects. You can find more information about the open source movement at opensource.org. Open source software is protected by public licenses. These prevent commercial companies from taking control of open source software by adding a few modifications of their own, copyrighting those changes, and selling the software as their own product. The most popular public license is the GNU GPL provided by the Free Software Foundation. This is the license that Linux is distributed under. The GNU GPL retains the copyright, freely licensing the software with the requirement that the software and any modifications made to it always be freely available. Other public licenses have also been created to support the demands of different kinds of open source projects. The GNU lesser general public license (LGPL) lets commercial applications use GNU licensed software libraries. The qt public license (QPL) lets open source developers use the Qt libraries essential to the KDE desktop. You can find a complete listing at opensource.org
Subscribe to:
Posts (Atom)