ult/Using_Linux_Tools.rst
changeset 73 d32a19958ad9
parent 55 6aa9568b5874
child 74 7dbeae0fac70
equal deleted inserted replaced
72:ab4d5ef645c3 73:d32a19958ad9
     1 Introduction to the Course
       
     2 ==========================
       
     3 
       
     4 Engineering students use computers for a large number of curricular
       
     5 tasks – mostly computation centred. However, they do not see this as coding or programming tasks and usually are not even aware of the tools and
       
     6 techniques that will help them to handle these tasks better. This results
       
     7 in less than optimal use of their time and resources. This also causes
       
     8 difficulties when it comes tocollaboration and building on other people’s
       
     9 work. This course is intended to train such students in good software
       
    10 practices and tools for producing code and documentation.
       
    11 
       
    12 After successfully completing the program, the participants will be able to:
       
    13 
       
    14 - understand how software tools work together and how they can be used in tandem to carry out tasks,        
       
    15                              
       
    16 - use unix command line tools to carry out common (mostly text processing tasks,
       
    17                                                             
       
    18 - to generate professional documents,                                
       
    19 
       
    20 - use version control effectively – for both code and documents,       
       
    21 
       
    22 - automate tasks by writing shell scripts and python scripts,        
       
    23 
       
    24 - realise the impact of coding style and readbility on quality,      
       
    25 
       
    26 - write mid-sized programs that carry out typical engineering / numerical computations such as those that involve (basic) manipulation of large arrays in an efficient manner,                                      
       
    27 
       
    28 - generate 2D and simple 3D plots,                                   
       
    29 
       
    30 - debug programs using a standardised approach,
       
    31 
       
    32 - understand the importance of tests and the philosophy of Test Driven Development,
       
    33 
       
    34 - write unit tests and improve the quality of code.
       
    35 
       
    36 Introducing Linux
     1 Introducing Linux
    37 =================
     2 =================
    38 
     3 
    39 (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
     4 (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
    40 
     5 
    41 Linux (usually pronounced ˈlɪnəks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU Global Public License (GPL) and other free software licences.
     6 Linux (usually pronounced ˈlɪnəks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.
    42 
     7 
    43 Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
     8 Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
    44 
     9 
    45 The name "Linux"  comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux".
    10 The name "Linux"  comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.
    46 
    11 
    47 Historical Background
    12 Historical Background
    48 ----------------------
    13 ----------------------
    49 
    14 
    50 Events leading to the creation
    15 Events leading to the creation
    51 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    52 - The Unix operating system was conceived and implemented in the 1960s and first released in 1970. Its availability and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems.
    17 - The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.
    53 
    18 
    54 - In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
    19 - In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
    55 
       
    56 - Another free operating system project in the 1980s was the Berkeley Software Distribution (BSD). This was developed by UC Berkeley from the 6th edition of Unix from AT&T. Since BSD contained Unix code that AT&T owned, AT&T filed a lawsuit (USL v. BSDi) in the early 1990s against the University of California. This strongly limited the development and adoption of BSD.
       
    57 
       
    58 - MINIX, a Unix-like system intended for academic use, was released by Andrew S. Tanenbaum in 1987. While source code for the system was available, modification and redistribution were restricted. In addition, MINIX's 16-bit design was not well adapted to the 32-bit features of the increasingly cheap and popular Intel 386 architecture for personal computers.
       
    59 
       
    60 - These factors of a lack of a widely-adopted, free kernel provided the impetus for Torvalds's starting his project. He has stated that if either the GNU or 386BSD kernels were available at the time, he likely would not have written his own.
       
    61 
    20 
    62 The Creation of Linux
    21 The Creation of Linux
    63 ~~~~~~~~~~~~~~~~~~~~~~
    22 ~~~~~~~~~~~~~~~~~~~~~~
    64 In 1991, in Helsinki, Linus Torvalds began a project that later became the Linux kernel. It was initially a terminal emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program specifically for the hardware he was using and independent of an operating system because he wanted to use the functions of his new PC with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
    23 In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
    65 
    24 
    66 Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components. These third-party components comprise a vast body of work and may include both kernel modules and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
    25 Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
    67 
    26 
    68 
    27 
    69 Design and Implications
    28 Design and Implications
    70 ------------------------
    29 ------------------------
    71 
    30 
    72 A Linux-based system is a modular Unix-like operating system. It derives much of its basic design from principles established in Unix during the 1970s and 1980s. Such a system uses a monolithic kernel, the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel.
    31 A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".
    73 
       
    74 Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the X Window System.
       
    75 
    32 
    76 User Interface
    33 User Interface
    77 ~~~~~~~~~~~~~~
    34 ~~~~~~~~~~~~~~
    78 Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually graphical user interface (or GUI).
    35 Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.
    79 
    36 
    80 On desktop machines, KDE, GNOME and Xfce are the most popular user interfaces,[36] though a variety of additional user interfaces exist. Most popular user interfaces run on top of the X Window System (or X), which provides network transparency, enabling a graphical application running on one machine to be displayed and controlled from another.
    37 A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A “headless system” (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
    81 
       
    82 Other GUIs include X window managers such as FVWM, Enlightenment and Window Maker. The window manager provides a means to control the placement and appearance of individual application windows, and interacts with the X window system. This is a more minimalist goal than KDE, GNOME et al., which are termed desktop environments.
       
    83 
       
    84 A Linux system typically provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A “headless system” run without even a monitor can be controlled by the command line via a remote-control protocol such as SSH or telnet.
       
    85 
       
    86 Most low-level Linux components, including the GNU Userland, use the CLI exclusively. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
       
    87 
    38 
    88 Development
    39 Development
    89 ~~~~~~~~~~~
    40 ~~~~~~~~~~~
    90 The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of copyleft, a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
    41 The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
    91 
    42 
    92 Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.
    43 Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
    93 
       
    94 Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
       
    95 
    44 
    96 A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
    45 A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
    97 
    46 
    98 Community
    47 Community
    99 ~~~~~~~~~
    48 ~~~~~~~~~
   100 A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis, Debian being a well-known example. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
    49 A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
   101 
    50 
   102 In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC chatrooms or newsgroups. Online forums are another means for support, with notable examples being LinuxQuestions.org and the Gentoo forums. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list.
    51 In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.
   103 
       
   104 There are several technology websites with a Linux focus. Print magazines on Linux often include cover disks including software or even complete Linux distributions.
       
   105 
    52 
   106 Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
    53 Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
   107 
    54 
   108 The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware.
    55 Can I make a profit out of running a business involving Linux?
       
    56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
    57 
       
    58 The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.
   109 
    59 
   110 Programming on Linux
    60 Programming on Linux
   111 ~~~~~~~~~~~~~~~~~~~~
    61 ~~~~~~~~~~~~~~~~~~~~
   112 Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
    62 Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
   113 
    63 
   114 Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
    64 Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
   115 
    65 
   116 The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated development environments available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
    66 The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
   117 
    67 
   118 Reasons for Using Linux
    68 Reasons for Using Linux
   119 -----------------------
    69 -----------------------
   120 - Linux is free:
    70 - Linux is free:
   121 
    71 
   122 As in free beer, they say. If you want to spend absolutely nothing, you don't even have to pay the price of a CD. Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
    72 As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
   123 Most of all, Linux is free as in free speech:
    73 Most of all, Linux is free as in "free speech":
   124 The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image, for instance to add support for teletransportation machines or time travel and sell your new code, as long as your customers 
    74 The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.
   125 can still have a copy of that code.
       
   126 
    75 
   127 - Linux is portable to any hardware platform:
    76 - Linux is portable to any hardware platform:
   128 
    77 
   129 A vendor who wants to sell a new type of computer and who doesn't know what kind of OS his new machine will run (say the CPU in your car or washing machine), can take a Linux kernel and make it work on his hardware, because documentation related to this activity is freely available.
    78 A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.
   130 
    79 
   131 - Linux was made to keep on running:
    80 - Linux was made to keep on running:
   132 
    81 
   133 As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other calm moments, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable also in environments where people don't have the time or the possibility to control their systems night and day.
    82 As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.
   134 
    83 
   135 - Linux is secure and versatile:
    84 - Linux is secure and versatile:
   136 
    85 
   137 The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only fit for use as a fort against enemy attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security. Your development machine or control station will be as secure as you firewall.
    86 The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.
   138 
    87 
   139 - Linux is scalable:
    88 - Linux is scalable:
   140 
    89 
   141 From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. You don't need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If you want to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
    90 From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
   142 
    91 
   143 - The Linux OS and Linux applications have very short debug−times:
    92 - The Linux OS and Linux applications have very short debug−times:
   144 
    93 
   145 Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
    94 Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
   146 
    95 
   147 Getting Started
    96 Getting Started
   148 ================
    97 ================
   149 
    98 
   150 Logging in, activating the user interface and logging out
    99 Logging in, activating the user interface and logging out
   151 ----------------------------------------------------------
   100 ----------------------------------------------------------
   152 In order to work on a Linux system directly, you will need to provide a user name and password. You always need to authenticate to the system. Most PC−based Linux systems have two basic modes for a system to run in: either quick and sober in text console mode, which looks like DOS with mouse, multitasking and multi−user features, or in graphical console mode, which
   101 In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PC−based Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multi−user features, or in graphical console mode, which looks better but eats more system resources.
   153 looks better but eats more system resources.
       
   154 
   102 
   155 Graphical Mode
   103 Graphical Mode
   156 ~~~~~~~~~~~~~~
   104 ~~~~~~~~~~~~~~
   157 This is the default nowadays on most desktop computers. You know you will connect to the system using graphical mode when you are first asked for your user name, and then, in a new window, to type your password.
   105 This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.
   158 
   106 
   159 To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click *OK* or press *Enter*.
   107 To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click *OK* or press *Enter*.
   160 It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
   108 It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
   161 
   109 
   162 After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
   110 After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
   163 
   111 
   164 To continue, you will need to open a *terminal window* or *xterm* for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the *Applications−>Utilities,
   112 To continue, you will need to open a *terminal window* or *xterm* for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the *Applications−>Utilities->System Tools* or *Internet menu*, depending on what window manager you are using. There might be icons that you can use as a shortcut to get an *xterm* window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
   165 System Tools* or *Internet menu*, depending on what window manager you are using. There might be icons that you can use as a shortcut to get an xterm window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
   113 
   166 
   114 While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old point−n−click method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
   167 While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old point−'n'−click method of dealing with the computer will do. But this
   115 
   168 guide is for future network and system administrators, who will need to meddle with the heart of the system.
   116 A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
   169 
       
   170 They need a stronger tool than a mouse to handle all the tasks they will face. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
       
   171 
       
   172 The terminal window is your control panel for the system. Almost everything that follows is done using this simple but powerful text tool. A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
       
   173 
   117 
   174 Another common form for a prompt is this one:
   118 Another common form for a prompt is this one:
   175 [user@host dir]
   119 [user@host dir]
   176 
   120 
   177 In the above example, *user* will be your login name, *hosts* the name of the machine you are working on, and *dir* an indication of your current location in the file system.Prompts can display all kinds of information, but that they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the logout icon or find Log Out in the menu. Closing everything is not really
   121 In the above example, *user* will be your login name, *hosts* the name of the machine you are working on, and *dir* an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the *logout* icon or find *Log Out* in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
   178 necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
       
   179 
   122 
   180 When you see the login screen again, asking to enter user name and password, logout was successful.
   123 When you see the login screen again, asking to enter user name and password, logout was successful.
   181 
   124 
   182 Text Mode
   125 Text Mode
   183 ~~~~~~~~~
   126 ~~~~~~~~~
   184 You know you're in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
   127 One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
   185 
   128 
   186 The login is different from a graphical login, in that you have to hit the *Enter* key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type
   129 The login is different from a graphical login, in that you have to hit the *Enter* key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another *Enter*. You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
   187 your password, followed by another *Enter*. You won't see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
       
   188 reasons.
   130 reasons.
   189 
   131 
   190 When the system has accepted you as a valid user, you may get some more information, called the *message of the day*, which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie,
   132 When the system has accepted you as a valid user, you may get some more information, called the *message of the day*, which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
   191 which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
       
   192 
   133 
   193 Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a non−privileged user.
   134 Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a non−privileged user.
   194 
   135 
   195 Logging out is done by entering the logout command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't power−off the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
   136 Logging out is done by entering the *logout* command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't power−off the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
   196 
   137 
   197 Basic Commands
   138 Basic Commands
   198 ===============
   139 ===============
   199 
   140 
   200 1.ls
   141 1.ls
   221 	$ ls -l
   162 	$ ls -l
   222 	drwxr--r--   1 plum  editors   4096  jeeves
   163 	drwxr--r--   1 plum  editors   4096  jeeves
   223 	-rw-r--r--   1 plum  editors  30405  psmith
   164 	-rw-r--r--   1 plum  editors  30405  psmith
   224 	-r-xr-xr-x   1 plum  plum      8460  blandings
   165 	-r-xr-xr-x   1 plum  plum      8460  blandings
   225 
   166 
       
   167 Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
   226 
   168 
   227 2.date
   169 2.date
   228 -------
   170 -------
   229 
   171 
   230 The Unix date command displays the time and date. The super-user can use it to set the system clock.
   172 The Unix date command displays the time and date. The super-user can use it to set the system clock.
   232 With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example::
   174 With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example::
   233 
   175 
   234 	$date
   176 	$date
   235 	Tue Sep  8 12:01:45 IST 2009
   177 	Tue Sep  8 12:01:45 IST 2009
   236 
   178 
   237 Options
   179 On some systems to set the current date and time to September 8, 2004 01:22 you type::
   238 ~~~~~~~~
       
   239 
       
   240 *-d, -de* : string display time described by string, not now.
       
   241 
       
   242 *-e* : datefile like de once for each line of datefile
       
   243 
       
   244 *-s, --set* : string set time described by string
       
   245 
       
   246 *-n* : don't synchronize the clocks on groups of machines using the utility timed(8). By default, if timed is running, date will set the time on all of the machines in the local group. *-n* inhibites that.
       
   247 
       
   248 *-u* : Display or set the date in UTC (universal) time.
       
   249 
       
   250 *date [-u|--utc|--universal] [mmddHHMM[[cc]yy].SS* : The only valid option for the this form specifies Coordinated Universal Time.
       
   251 
       
   252 *-u GMT* : example - Sat Feb 5 14:49:42 GMT 2005
       
   253 
       
   254 *--utc, --universal* : Coordinated Universal Time, example - Tue Sep  8 07:05:54 UTC 2009
       
   255 
       
   256 *-ITIMESPEC, --iso-8601* [=TIMESPEC] : output date/time in ISO 8601 format. TIMESPEC=date for date only, hours, minutes, or seconds for date and time to the indicated precision.
       
   257 
       
   258 *--iso-8601* without TIMESPEC defaults to 'date'.
       
   259 
       
   260 *-R*, *--rfc-822* outputs RFC-822 compliant date string,
       
   261 example - Sat Feb 5 09:50:23 EST 2005
       
   262 
       
   263 *--help*
       
   264 
       
   265 The Single Unix Specification (SUS) mandates only one option: *-u*, where the date and time is printed as if the timezone was UTC+0. Other Unix and Unix-like systems provide extra options.
       
   266 
       
   267 The XSI extension to the SUS specifies that the date command can also be used to set the date. The new date is specified as an option to date in the format MMddhhmm[[cc]yy], where MM specifies the two-digit numeric month, dd specifies the two-digit numeric day, hh specifies the two-digit numeric hour, mm specifies the two-digit numeric minutes. Optionally cc specifies the first two digits of the year, and yy specifies the last two digits of the year.
       
   268 
       
   269 Other Unix and Unix-like systems may set different options or date formats for date, for example, on some systems to set the current date and time to September 8, 2004 01:22 you type::
       
   270 
   180 
   271 	$date --set="20040908 01:22"
   181 	$date --set="20040908 01:22"
       
   182 
       
   183 In order to view the various options for the *date* command, type::
       
   184 
       
   185 	$man date
       
   186 
       
   187 This will take you to the "Manual" page comprising of all the details on the *date* command. You can return to the terminal from the "man" page by pressing the *Esc* key in the keyboard and typing ":q" in that order. 
   272 
   188 
   273 3.cd
   189 3.cd
   274 -----
   190 -----
   275 
   191 
   276 Change directory. Use “ cd ..” to go up one directory.
   192 This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered, “ cd ..” can be used.
   277 
   193 
   278 One dot '.' represents the current directory while two dots '..' represent the parent directory.
   194 One dot '.' represents the current directory while two dots '..' represent the parent directory.
   279 
   195 
   280 “ cd -” will return you to the previous directory (a bit like an “undo”).
   196 “ cd -” will return you to the previous directory (a bit like an “undo”).
   281 
   197 
   313 	beeblebrox pts/0        2009-09-08 11:25 (:0.0)
   229 	beeblebrox pts/0        2009-09-08 11:25 (:0.0)
   314 	dumbledore pts/1        2009-09-08 18:11 (potter.xyz.in)
   230 	dumbledore pts/1        2009-09-08 18:11 (potter.xyz.in)
   315 	beeblebrox pts/2        2009-09-08 18:53 (:0.0)
   231 	beeblebrox pts/2        2009-09-08 18:53 (:0.0)
   316 
   232 
   317 
   233 
   318 The command can be invoked with the arguments am i or am I (so it is invoked as who am i or am I), showing information about the current terminal only (see the -m option below, of which this invocation is equivalent).
   234 The command can be invoked with the arguments *am i* or *am I* (so it is invoked as *who am i* or * who am I*), showing information about the current terminal only (see the *-m* option below, of which this invocation is equivalent).
   319 
   235 
   320 The Single Unix Specification (SUS) without extensions only specifies the following -m, -T, and -u options, all other options are specified in the XSI extension.
   236 In order to find out the various options that can be appended to the *who* command, check the *man* page by typing out the following in the terminal::
   321 
   237 
   322     -a, process the system database used for user information with the -b, -d, -l, -p, -r, -t, -T and -u.
   238 	$man who
   323     -b, show time when system was last rebooted
   239 
   324     -d, show zombie processes and details
   240 This will take you to the "Manual" page containing details about the *who* command
   325     -H, show column headers
       
   326     -l, show terminals where a user can log in
       
   327     -m, show information about the current terminal only
       
   328     -p, show active processes
       
   329     -q, quick format, show only names and the number of all users logged on, disables all other options; equivalent to users command line utility
       
   330     -r, show runlevel of the init process.
       
   331     -s, (default) show only name, terminal, and time details
       
   332     -t, show when system clock was last changed
       
   333     -T, show details of each terminal in a standard format 
       
   334     -u, show idle time; XSI shows users logged in and displays information whether the terminal has been used recently or not 
       
   335 
   241 
   336 5.mkdir
   242 5.mkdir
   337 --------
   243 --------
   338 
   244 
   339 Normal usage is as straightforward as follows::
   245 This command is used to make a new directory. Normal usage is as straightforward as follows::
   340 
   246 
   341 	$mkdir name_of_directory
   247 	$mkdir name_of_directory
   342 
   248 
   343 Where *name_of_directory* is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and *mkdir* will try to create all of them.
   249 Where *name_of_directory* is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and *mkdir* will try to create all of them.
   344 
   250 
   380 ----------------------
   286 ----------------------
   381 
   287 
   382 This is a command to search the manual pages files in Unix and Unix-like operating systems. ::
   288 This is a command to search the manual pages files in Unix and Unix-like operating systems. ::
   383 
   289 
   384 	$ apropos grep
   290 	$ apropos grep
   385 	egrep       egrep (1)       Search a file for a pattern using full 		regular expressions
   291 	egrep       egrep (1)       Search a file for a pattern using full regular expressions
   386 	fgrep       fgrep (1)       Search a file for a fixed-character 	string
   292 	fgrep       fgrep (1)       Search a file for a fixed-character	string
   387 	fmlgrep     fmlgrep (1)     Search a file for a pattern
   293 	fmlgrep     fmlgrep (1)     Search a file for a pattern
   388 	grep        grep (1)        Search a file for a pattern
   294 	grep        grep (1)        Search a file for a pattern
   389 	gzgrep      gzgrep (1)      Search a possibly compressed file for a 		regular expression
   295 	gzgrep      gzgrep (1)      Search a possibly compressed file for a regular expression
   390 	nisgrep     nismatch (1)    Utilities for searching NIS+ tables
   296 	nisgrep     nismatch (1)    Utilities for searching NIS+ tables
   391 	pgrep       pgrep (1)       Find or signal a process by name or 	other attribute
   297 	pgrep       pgrep (1)       Find or signal a process by name or other attribute
   392 	zgrep       zgrep (1)       Search a possibly compressed file for a 		regular expression
   298 	zgrep       zgrep (1)       Search a possibly compressed file for a regular expression
       
   299 	...
   393 
   300 
   394 In this example, the user uses *apropos* to search for the string "grep", and apropos returns the indicated *man* pages that include the term "grep".
   301 In this example, the user uses *apropos* to search for the string "grep", and apropos returns the indicated *man* pages that include the term "grep".
   395 
   302 
   396 A short index of explanations for commands is available using the *whatis* command, like in the examples below::
   303 A short index of explanations for commands is available using the *whatis* command, like in the examples below::
   397 
   304 
   398 	[your_prompt] whatis ls
   305 	$whatis ls
   399 	ls                   (1)  - list directory contents
   306 	ls (1) 		 - list directory contents
   400 
   307 
   401 This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
   308 This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
   402 
   309 
   403 If you don't know where to get started and which man page to read, *apropos* gives more information. Say that you don't know how to start a browser, then you could enter the following command::
   310 If you don't know where to get started and which man page to read, *apropos* gives more information. Say that you do not know how to start a browser, then you could enter the following command::
   404 
   311 
   405 	another prompt> apropos browser
   312 	$apropos browser
   406 	gmusicbrowser (1)    - Jukebox for large collections of audio files
   313 	gmusicbrowser (1)    - Jukebox for large collections of audio files
   407 	infobrowser (1)      - read Info documents
   314 	infobrowser (1)      - read Info documents
   408 	libsmbclient (7)     - An extension library for browsers and that 		can be used...
   315 	libsmbclient (7)     - An extension library for browsers and that 		can be used...
   409 	opera (1)            - a standards-compliant graphical Web browser
   316 	opera (1)            - a standards-compliant graphical Web browser
   410 	sensible-browser (1) - sensible editing, paging, and web browsing
   317 	sensible-browser (1) - sensible editing, paging, and web browsing
   411 	smbtree (1)          - A text based smb network browser
   318 	smbtree (1)          - A text based smb network browser
   412 	tvtk_doc (1)         - A GUI based TVTK documentation search browser.
   319 	tvtk_doc (1)         - A GUI based TVTK documentation search browser.
   413 	viewres (1)          - graphical class browser for Xt
   320 	viewres (1)          - graphical class browser for Xt
   414 	w3m (1)              - a text based Web browser and pager
   321 	w3m (1)              - a text based Web browser and pager
   415 	www-browser (1)      - a text based Web browser and pager
   322 	www-browser (1)      - a text based Web browser and pager
   416 
   323 	...
   417 
   324 
   418 2. man
   325 2. man
   419 -------
   326 -------
   420 
   327 
   421 Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is *man*. Each page is a self-contained document.
   328 Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is *man*. Each page is a self-contained document.
   422 
   329 
   423 To read a manual page for a Unix command, one can use::
   330 To read a manual page for a Unix command, one can use::
   424 
   331 
   425 	$ man <command_name>
   332 	$ man <command_name>
   426 
   333 
   427 at a shell prompt; for example, "man ftp". In order to simplify navigation through the output, man generally uses the less terminal pager.
   334 at a shell prompt; for example, "man ftp". In order to simplify navigation through the output, *man* generally uses the less terminal pager.
   428 
   335 
   429 Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are *man(1)* and *man(7)*, or *exit(2)* and *exit(3)*. The syntax for accessing the non-default manual section varies between different man implementations. On Linux and *BSD, for example, the syntax for reading *printf(3)* is::
   336 Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are *man(1)* and *man(7)*, or *exit(2)* and *exit(3)*. The syntax for accessing the non-default manual section varies between different man implementations. On Linux and *BSD, for example, the syntax for reading *printf(3)* is::
   430 
   337 
   431 	$ man 3 printf
   338 	$man 3 printf
   432 
   339 
   433 Another example::
   340 Another example::
   434 
   341 
   435 	yourname@yourcomp ~> man man
   342 	$man man
   436 
   343 
       
   344 The previous example will take you to the "Manual" page entry about manual pages!
   437 
   345 
   438 Layout
   346 Layout
   439 ~~~~~~
   347 ~~~~~~
   440 
   348 
   441 All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
   349 All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
   451 SEE ALSO
   359 SEE ALSO
   452     A list of related commands or functions.
   360     A list of related commands or functions.
   453 
   361 
   454 Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
   362 Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
   455 
   363 
   456 History
   364 These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to *man* have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
   457 ~~~~~~~
   365 
   458 
   366 However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.
   459 The UNIX Programmer's Manual was first published on November 3, 1971. The first actual man pages were written by Dennis Ritchie and Ken Thompson at the insistence of Doug McIlroy in 1971. The *troff* macros used for man pages (-mm) were the general-purpose ones written by Ted Dolotta (later to be the first manager of USG and the principal author of the System III manual), with additions for the manuals. At the time, the availability of online documentation through the manual page system was regarded as a great advance. To this day, virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to man have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
       
   460 
       
   461 However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned info system.
       
   462 
   367 
   463 Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
   368 Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
   464 
   369 
   465 Usually the man pages are written in English. Translations into other languages can be also available on the system.
   370 Usually the man pages are written in English. Translations into other languages can be also available on the system.
   466 
   371 
   588 
   493 
   589     $ cp -R /home/hhgg/clients /home/hhgg/customers
   494     $ cp -R /home/hhgg/clients /home/hhgg/customers
   590 
   495 
   591 This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
   496 This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
   592 
   497 
   593 To copy a specific set of files to another directory, enter::
   498 To copy a specific set of files of any extension to another directory, enter::
   594 
   499 
   595     $ cp zaphod arthur ford /home/hhgg/clients
   500     $ cp zaphod arthur ford /home/hhgg/clients
   596 
   501 
   597 This copies the *zaphod*, *arthur*, and *ford* files in your current working directory to the /home/hhgg/clients directory.
   502 This copies the *zaphod*, *arthur*, and *ford* files in your current working directory to the /home/hhgg/clients directory.
   598 
   503 
   599 To use pattern-matching characters to copy files, enter::
   504 To use pattern-matching characters to copy files, enter::
   600 
   505 
   601     $ cp programs/*.py .
   506     $ cp programs/*.py .
   602 
   507 
   603 This copies the files in the programs directory that end with *.py* to the current directory, signified by the single . (dot). You must type a space between the *py* and the final dot.
   508 This copies the files in the programs directory that end with *.py* to the current directory, signified by the single "." (dot). You must type a space between the *py* and the final dot.
   604 
   509 
   605 2. mv
   510 2. mv
   606 -----
   511 -----
   607 
   512 
   608 *mv* (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system), *mv* will rename the file instead. Write permission is required on all directories being modified.
   513 *mv* (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system), *mv* will rename the file instead. Write permission is required on all directories being modified.
   636 Note that when the command is called with two arguments (as *mv name1 name2* or *mv name1 /dir/name2*), it can have three different effects, depending on whether *name2* does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory, */.* (or in some Unix versions */* is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
   541 Note that when the command is called with two arguments (as *mv name1 name2* or *mv name1 /dir/name2*), it can have three different effects, depending on whether *name2* does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory, */.* (or in some Unix versions */* is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
   637 
   542 
   638 3. rm
   543 3. rm
   639 ------
   544 ------
   640 
   545 
   641 *rm* (short for remove) is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
   546 *rm* (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
   642 
   547 
   643 Here's example to remove a file named "foo" from a directory, here shown with the -i option::
   548 Here's example to remove a file named "foo" from a directory, here shown with the -i option::
   644 
   549 
   645   	$ rm -i foo
   550   	$ rm -i foo
   646     	remove foo? y
   551     	remove foo? y
   686 
   591 
   687 "file.s" is a command line argument which tells the program rm to remove the file "file.s".
   592 "file.s" is a command line argument which tells the program rm to remove the file "file.s".
   688 
   593 
   689 Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
   594 Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
   690 
   595 
   691 A command line option or simply option (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
   596 A command line option or simply *option* (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
   692 
   597 
   693 Long options are introduced via --, and are typically whole words. For example, *ls --long --classify --all*. Arguments to long options are provided with =, as *ls --block-size=1024*. Some Unix programs use long options with single dashes, for example MPlayer as in *mplayer -nosound*.
   598 Long options are introduced via "--", and are typically whole words. For example, *ls --long --classify --all*. Arguments to long options are provided with "=", as *ls --block-size=1024*. Some Unix programs use long options with single dashes, for example MPlayer as in *mplayer -nosound*.
   694 
   599 
   695 Linux also uses -- to terminate option lists. For example, an attempt to delete a file called *-file1* by using *rm -file1* may produce an error, since rm may interpret *-file1* as a command line switch. Using *rm -- -file1* removes ambiguity.
   600 Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called *-file1* by using *rm -file1* may produce an error, since rm may interpret *-file1* as a command line switch. Using *rm -- -file1* removes ambiguity.
   696 
   601 
   697 Basic Text Processing
   602 Basic Text Processing
   698 ======================
   603 ======================
   699 
   604 
   700 1. head
   605 1. head
   814 If the files contain:
   719 If the files contain:
   815 
   720 
   816 +-----------+------------+------------+
   721 +-----------+------------+------------+
   817 |   who     |   where    |    when    |
   722 |   who     |   where    |    when    |
   818 +===========+============+============+
   723 +===========+============+============+
   819 |  Sam      |  Detroit   | January 3  |
   724 |  Batman   | GothamCity | January 3  |
   820 +-----------+------------+------------+	
   725 +-----------+------------+------------+	
   821 |  Dave     | Edgewood   | February 4 |
   726 | Trillian  | Andromeda  | February 4 |
   822 +-----------+------------+------------+
   727 +-----------+------------+------------+
   823 |  Sue      |  Tampa     |  March 19  |
   728 |  Jeeves   | London     |  March 19  |
   824 +-----------+------------+------------+	
   729 +-----------+------------+------------+	
   825 
   730 
   826 This creates the file named *www* containing::
   731 This creates the file named *www* containing::
   827 
   732 
   828 	Sam            Detroit         January 3
   733 	Batman            GothamCity       January 3
   829 	Dave           Edgewood        February 4
   734 	Trillian          Andromeda        February 4
   830 	Sue            Tampa           March 19
   735 	Jeeves            London           March 19
   831 
   736 
   832 Shell Meta Characters
   737 Shell Meta Characters
   833 ======================
   738 ======================
   834 
   739 
   835 Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
   740 Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
   877 The *cat* command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of *concatenate*.
   782 The *cat* command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of *concatenate*.
   878 
   783 
   879 The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
   784 The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
   880 
   785 
   881 If the filename is specified as -, then *cat* will read from standard input at that point in the sequence. If no files are specified, *cat* will read from standard input entered.
   786 If the filename is specified as -, then *cat* will read from standard input at that point in the sequence. If no files are specified, *cat* will read from standard input entered.
   882 
       
   883 Extensions
       
   884 ~~~~~~~~~~
       
   885 
       
   886 Both the BSD versions of *cat* (as per the OpenBSD manpage) and the GNU coreutils version of *cat* specify the following options:
       
   887 
       
   888     `*` -b (GNU only: --number-nonblank), number non-blank output lines
       
   889 
       
   890     `*` -n (GNU only: --number), number all output lines
       
   891 
       
   892     `*` -s (GNU only: --squeeze-blank), squeeze multiple adjacent blank lines
       
   893 
       
   894     `*` -v (GNU only: --show-nonprinting), displays nonprinting characters 		as if they were visible, except for tabs and the end of line 		character
       
   895 
       
   896     `*` -t on BSD, -T on GNU, implies -v but also display tabs as ^I
       
   897 
       
   898     `*` -e on BSD, -E on GNU, implies -v but also display end-of-line 		characters as $
       
   899 
   787 
   900 Jargon File Definition
   788 Jargon File Definition
   901 ~~~~~~~~~~~~~~~~~~~~~~
   789 ~~~~~~~~~~~~~~~~~~~~~~
   902 
   790 
   903 The Jargon File version 4.4.7 lists this as the definition of *cat*::
   791 The Jargon File version 4.4.7 lists this as the definition of *cat*::
   924 	Of such oppositions are holy wars made...
   812 	Of such oppositions are holy wars made...
   925 
   813 
   926 Useless Use of 'cat'
   814 Useless Use of 'cat'
   927 ~~~~~~~~~~~~~~~~~~~~
   815 ~~~~~~~~~~~~~~~~~~~~
   928 
   816 
   929 UUOC (from comp.unix.shell on Usenet) stands for “Useless Use of cat”. As received wisdom on *comp.unix.shell* observes, “The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.”
   817 UUOC (from comp.unix.shell on Usenet) stands for “Useless Use of cat”. As it is observed on *comp.unix.shell*, “The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.”
   930 
   818 
   931 Nevertheless one sees people doing::
   819 Nevertheless one sees people doing::
   932 
   820 
   933 	$ cat file | some_command and its args ...
   821 	$ cat file | some_command and its args ...
   934 
   822 
   938 
   826 
   939 or (equivalently and more classically)::
   827 or (equivalently and more classically)::
   940 
   828 
   941 	some_command and its args ... <file
   829 	some_command and its args ... <file
   942 
   830 
   943 Since 1995, occasional awards for UUOC have been given out, usually by Perl luminary Randal L. Schwartz. There is a web page devoted to this and other similar awards. In British hackerdom the activity of fixing instances of UUOC is sometimes called 'demoggification'.
   831 Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
   944 
   832 
   945 Amongst many, it is still considered safer to use *cat* for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.
   833 Amongst many, it is still considered safer to use *cat* for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.
   946 
   834 
   947 zcat
   835 zcat
   948 ~~~~~
   836 ~~~~~
   952 2. more
   840 2. more
   953 --------
   841 --------
   954 
   842 
   955 In computing, *more* is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
   843 In computing, *more* is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
   956 
   844 
   957 History
       
   958 ~~~~~~~
       
   959 
       
   960 The *more* command was originally written by Daniel Halbert, a graduate student at the University of California, Berkeley, in 1978. It was first included in 3.0 BSD, and has since become a standard program in all Unix systems. *less*, a similar command with the extended capability of allowing both forward and backward navigation through the file was written by Mark Nudelman during 1983-85 and is now included in most Unix and Unix-like systems.
       
   961 
       
   962 Usage
   845 Usage
   963 ~~~~~
   846 ~~~~~
   964 
   847 
   965 The command-syntax is::
   848 The command-syntax is::
   966 
   849 
   970 
   853 
   971 Once *more* has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause *more* to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that *more* has paged through. (This percentage includes the text displayed on the current screen.) When *more* reaches the end of a file (100%) it exits. The most common methods of navigating through a file are *Enter*, which advances the output by one line, and *Space*, which advances the output by one screen.
   854 Once *more* has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause *more* to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that *more* has paged through. (This percentage includes the text displayed on the current screen.) When *more* reaches the end of a file (100%) it exits. The most common methods of navigating through a file are *Enter*, which advances the output by one line, and *Space*, which advances the output by one screen.
   972 
   855 
   973 There are also other commands that can be used while navigating through the document; consult *more*'s *man* page for more details.
   856 There are also other commands that can be used while navigating through the document; consult *more*'s *man* page for more details.
   974 
   857 
   975 Options
   858 *Options* are typically entered before the file name, but can also be entered in the environment variable *$MORE*. Options entered in the actual command line will override those entered in the *$MORE* environment variable. Available options may vary between Unix systems.
   976 ~~~~~~~
       
   977 
       
   978 Options are typically entered before the file name, but can also be entered in the environment variable *$MORE*. Options entered in the actual command line will override those entered in the *$MORE* environment variable. Available options may vary between Unix systems, but a typical set of options is as follows:
       
   979 
       
   980     * -num: This option specifies an integer which is the screen size (in 	lines).
       
   981 
       
   982     * -d: more will prompt the user with the message "[Press space to 		  continue, 'q' to quit.]" and will display "[Press 'h' for 		  instructions.]" instead of ringing the bell when an illegal key is 		  pressed.
       
   983 
       
   984     * -l: more usually treats ^L (form feed) as a special character, and 	   will pause after any line that contains a form feed. The -l option 		  will prevent this behavior.
       
   985 
       
   986     * -f: Causes more to count logical, rather than screen lines (i.e., long 		  lines are not folded).
       
   987 
       
   988     * -p: Do not scroll. Instead, clear the whole screen and then display 		  the text.
       
   989 
       
   990     * -c: Do not scroll. Instead, paint each screen from the top, clearing 		  the remainder of each line as it is displayed.
       
   991 
       
   992     * -s: Squeeze multiple blank lines into one.
       
   993 
       
   994     * -u: Suppress underlining.
       
   995 
       
   996     * +/: The +/ option specifies a string that will be searched for before 		  each file is displayed. (Ex.: more +/Preamble gpl.txt)
       
   997 
       
   998     * +num: Start at line number num.
       
   999 
       
  1000 
   859 
  1001 3. less
   860 3. less
  1002 --------
   861 --------
  1003 
   862 
  1004 *less* is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to *more*, but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers, *less* does not need to read the entire file before starting, resulting in faster load times with large files.
   863 *less* is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to *more*, but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers, *less* does not need to read the entire file before starting, resulting in faster load times with large files.
  1005 
   864 
  1006 History
       
  1007 ~~~~~~~~
       
  1008 
       
  1009 *less* was initially written by Mark Nudelman during 1983-85, in the need of a version of more able to do backward scrolling of the displayed text. The name came from the joke of doing "backwards more." *less* is now part of the GNU project and it is included in most Unix systems.
       
  1010 
       
  1011 Usage
   865 Usage
  1012 ~~~~~~
   866 ~~~~~~
  1013 
   867 
  1014 *less* can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While *less* is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both *more* and *vi*. It is also possible to search for character patterns in the file.
   868 *less* can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While *less* is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both *more* and *vi*. It is also possible to search for character patterns in the file.
  1015 
   869 
  1028 
   882 
  1029     * -M: Shows more detailed prompt, including file position.
   883     * -M: Shows more detailed prompt, including file position.
  1030 
   884 
  1031     * -N: Shows line numbers (useful for source code viewing).
   885     * -N: Shows line numbers (useful for source code viewing).
  1032 
   886 
  1033     * -S: Disables line wrap ("chop long lines"). Long lines can be seen by 		  side scrolling.
   887     * -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
  1034 
   888 
  1035     * -?: Shows help.
   889     * -?: Shows help.
  1036 
   890 
  1037 Frequently Used Commands
   891 Frequently Used Commands
  1038 ~~~~~~~~~~~~~~~~~~~~~~~~
   892 ~~~~~~~~~~~~~~~~~~~~~~~~
  1047 
   901 
  1048     * nG: Jump to line number n. Default is the end of the file.
   902     * nG: Jump to line number n. Default is the end of the file.
  1049 
   903 
  1050     * /pattern: Search for pattern. Regular expressions can be used.
   904     * /pattern: Search for pattern. Regular expressions can be used.
  1051 
   905 
  1052     * n: Go to next match (after a successful search).
       
  1053 
       
  1054     * N: Go to previous match.
       
  1055 
       
  1056     * mletter: Mark the current position with letter.
       
  1057 
       
  1058     * 'letter: Return to position letter. [' = single quote]
       
  1059 
       
  1060     * '^ or g: Go to start of file.
   906     * '^ or g: Go to start of file.
  1061 
   907 
  1062     * '$ or G: Go to end of file.
   908     * '$ or G: Go to end of file.
  1063 
   909 
  1064     * s: Save current content (got from another program like grep) in a file.
   910     * s: Save current content (got from another program like grep) in a file.
  1065 
   911 
  1066     * =: File information.
   912     * =: File information.
  1067 
       
  1068     * F: continually read information from file and follow its end. Useful 	    for logs watching. Use Ctrl+C to exit this mode.
       
  1069 
       
  1070     * -option: Toggle command-line option -option.
       
  1071 
   913 
  1072     * h: Help.
   914     * h: Help.
  1073 
   915 
  1074     * q: Quit.
   916     * q: Quit.
  1075 
   917 
  1488 
  1330 
  1489 *pcregrep* is an implementation of *grep* that uses Perl regular expression syntax.
  1331 *pcregrep* is an implementation of *grep* that uses Perl regular expression syntax.
  1490 
  1332 
  1491 Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The *pgrep* utility, for instance, displays the processes whose names match a given regular expression.
  1333 Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The *pgrep* utility, for instance, displays the processes whose names match a given regular expression.
  1492 
  1334 
  1493 In Perl, *grep* is a built-in function that finds elements in a list. In functional programming languages, this higher-order function is typically named "filter" instead.
       
  1494 
       
  1495 The DOS, OS/2 and Microsoft Windows platforms provide the find command for simple string searches. Windows includes the "findstr" command which approximates much of the functionality of “grep”. Ports of grep (Cygwin and GnuWin32, for example) are also available for Windows.
       
  1496 
       
  1497 Adobe added support for grep in the CS4 version of InDesign. Their support allow for finding and changing the formatting of text or the text itself in a document using *grep*.
       
  1498 
       
  1499 2. tr
  1335 2. tr
  1500 ------
  1336 ------
  1501 
  1337 
  1502 *tr* (abbreviated from *translate* or *transliterate*) is a command in Unix-like operating systems.
  1338 *tr* (abbreviated from *translate* or *transliterate*) is a command in Unix-like operating systems.
  1503 
  1339 
  1543 
  1379 
  1544 In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
  1380 In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
  1545 
  1381 
  1546 Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributions—including the editor *ed* and the filter *grep* — were the first to popularize the concept of regular expressions.
  1382 Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributions—including the editor *ed* and the filter *grep* — were the first to popularize the concept of regular expressions.
  1547 
  1383 
  1548 Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX Basic Regular Expressions (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
  1384 Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX *Basic Regular Expressions* (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
  1549 
  1385 
  1550 In the BRE syntax, most characters are treated as literals — they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
  1386 In the BRE syntax, most characters are treated as literals — they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
  1551 
  1387 
  1552 +-------------+------------------------------------------------------------+
  1388 +-------------+------------------------------------------------------------+
  1553 |Metacharacter|                            Description                     |
  1389 |Metacharacter|                            Description                     |
  1609 
  1445 
  1610 	Another whale explosion occurred on <January 26>, <2004>.
  1446 	Another whale explosion occurred on <January 26>, <2004>.
  1611 
  1447 
  1612 ...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the `*` quantifier is greedy — it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26".
  1448 ...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the `*` quantifier is greedy — it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26".
  1613 
  1449 
  1614 Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as lazy (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
  1450 Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as *lazy* (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
  1615 
  1451 
  1616 One Liners
  1452 One Liners
  1617 ===========
  1453 ===========
  1618 
  1454 
  1619 A *one-liner* is textual input to the command-line of an operating system shell that performs some function in just one line of input.
  1455 A *one-liner* is textual input to the command-line of an operating system shell that performs some function in just one line of input.
  1620 
  1456 
  1621 The one liner can be
  1457 The one liner can be
  1622 
  1458 
  1623    1. An expression written in the language of the shell.
  1459    1. An expression written in the language of the shell.
  1624    2. The invocation of an interpreter together with program source for the  	   interpreter to run.
  1460    2. The invocation of an interpreter together with program source for the interpreter to run.
  1625    3. The invocation of a compiler together with source to compile and 	  
  1461    3. The invocation of a compiler together with source to compile and 	  
  1626       instructions for executing the compiled program.
  1462       instructions for executing the compiled program.
  1627 
  1463 
  1628 Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
  1464 Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
  1629 
  1465 
  1636 
  1472 
  1637 Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
  1473 Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
  1638 
  1474 
  1639 The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
  1475 The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
  1640 
  1476 
  1641 Here are the very first of them:
  1477 Here are the first few of them:
  1642 
  1478 
  1643    1. Print the total number of input lines:
  1479    1. Print the total number of input lines:
  1644 
  1480 
  1645       END { print NR }
  1481       END { print NR }
  1646 
  1482 
  1649       NR == 10
  1485       NR == 10
  1650 
  1486 
  1651    3. Print the last field of every input line:
  1487    3. Print the last field of every input line:
  1652 
  1488 
  1653       { print $NF }
  1489       { print $NF }
  1654 
       
  1655 Here are examples in J:
       
  1656 
       
  1657    1. A function avg to return the average of a list of numbers:
       
  1658 
       
  1659       avg=: +/ % #
       
  1660 
       
  1661    2. Quicksort:
       
  1662 
       
  1663       quicksort=: (($:@(<#[) , (=#[) , $:@(>#[)) ({~ ?@#)) ^: (1<#)
       
  1664 
       
  1665 
       
  1666 Many one-liners are practical. For example, the following Perl one-liner will reverse all the bytes in a file:
       
  1667 
       
  1668 	perl -0777e 'print scalar reverse <>' filename
       
  1669 
  1490 
  1670 One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
  1491 One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
  1671 
  1492 
  1672 The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).::
  1493 The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).::
  1673 	
  1494 	
  1674 	main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
  1495 	main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
  1675 	*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
  1496 	*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
  1676 
  1497 
  1677 This one-liner program is a glob pattern matcher. It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
  1498 This one-liner program is a *glob pattern matcher*. It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
  1678 
  1499 
  1679 Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples::
  1500 Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples::
  1680 
  1501 
  1681 	$ prog foo 'f??'; echo $?
  1502 	$ prog foo 'f??'; echo $?
  1682 
  1503 
  1687 ::
  1508 ::
  1688 
  1509 
  1689 	$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/' 
  1510 	$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/' 
  1690 
  1511 
  1691 
  1512 
  1692 One liners in functional programming
  1513 
  1693 -------------------------------------
       
  1694 
       
  1695 The following Haskell program is a one-liner: it sorts its input lines asciibetically.
       
  1696 ::
       
  1697 
       
  1698 	 main = (mapM_ putStrLn . List.sort . lines) =<< getContents 
       
  1699 
       
  1700 -- In ghci a qualified name like List.sort will work, although as a standalone executable you'd need to import List.
       
  1701 
       
  1702 An even shorter version.
       
  1703 ::
       
  1704  
       
  1705 	main = interact (unlines . List.sort . lines) -- Ditto.
       
  1706 
       
  1707 Python is well suited for writing one liners using lambda functions without yielding obfuscated code. Here is a one liner in Python that multiplies two matrices (represented as a list of lists)
       
  1708 ::
       
  1709 
       
  1710 	z = lambda x, y : [[ sum([x[i] [k]*y[k] [j] for k in 
       
  1711 	range(len(x[0]))]) for j in range(len(y[0]))] for i in range(len(x))]
       
  1712 
       
  1713 Another, that prints all primes within the specified range [2, n] :
       
  1714 ::
       
  1715 
       
  1716 	z = lambda n : [x for x in range(2, n + 1) if len([i for i in 
       
  1717 	range(2, x) if x%i == 0]) == 0]
       
  1718 
       
  1719 This performs a Discrete Time Convolution on two input lists and yields a new list
       
  1720 ::
       
  1721 
       
  1722 	z = lambda x, h : [sum((x[i - j] if i - j >= 0 and i - j < len(x) 	  else 0)*h[j]
       
  1723  	 for j in range(len(h)))
       
  1724  	 for i in range(len(x) + len(h) - 1)]
       
  1725 
       
  1726