ult/Using_Linux_Tools.rst
author Puneeth Chaganti <puneeth@fossee.in>
Fri, 18 Sep 2009 14:46:54 +0530
changeset 59 8c15077f028d
parent 55 6aa9568b5874
child 73 d32a19958ad9
permissions -rw-r--r--
Added a section on functions in ULT; minor edits to SciTE section.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
     1
Introduction to the Course
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
     2
==========================
25
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
     3
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
     4
Engineering students use computers for a large number of curricular
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
     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
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
     6
techniques that will help them to handle these tasks better. This results
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
     7
in less than optimal use of their time and resources. This also causes
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
     8
difficulties when it comes tocollaboration and building on other people’s
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
     9
work. This course is intended to train such students in good software
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    10
practices and tools for producing code and documentation.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    11
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    12
After successfully completing the program, the participants will be able to:
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    13
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    14
- understand how software tools work together and how they can be used in tandem to carry out tasks,        
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    15
                             
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    16
- use unix command line tools to carry out common (mostly text processing tasks,
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    17
                                                            
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    18
- to generate professional documents,                                
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    19
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    20
- use version control effectively – for both code and documents,       
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    21
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    22
- automate tasks by writing shell scripts and python scripts,        
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    23
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    24
- realise the impact of coding style and readbility on quality,      
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    25
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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,                                      
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    27
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    28
- generate 2D and simple 3D plots,                                   
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    29
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    30
- debug programs using a standardised approach,
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    31
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    32
- understand the importance of tests and the philosophy of Test Driven Development,
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    33
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    34
- write unit tests and improve the quality of code.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    35
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
    36
Introducing Linux
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
    37
=================
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
    38
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
    39
(Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
25
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    40
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
    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.
25
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    42
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
    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.
25
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    44
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
    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".
25
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    46
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    47
Historical Background
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    48
----------------------
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    49
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    50
Events leading to the creation
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    51
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    53
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    55
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    57
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    59
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    61
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    62
The Creation of Linux
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    63
~~~~~~~~~~~~~~~~~~~~~~
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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).
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    65
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    67
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    68
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    69
Design and Implications
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    70
------------------------
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    71
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    73
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    75
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    76
User Interface
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    77
~~~~~~~~~~~~~~
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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).
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    79
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    81
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    83
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    85
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    87
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    88
Development
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    89
~~~~~~~~~~~
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    91
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    93
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    95
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    97
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    98
Community
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
    99
~~~~~~~~~
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   101
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   103
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   105
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   107
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   109
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   110
Programming on Linux
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   111
~~~~~~~~~~~~~~~~~~~~
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   113
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   115
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   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.
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   117
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   118
Reasons for Using Linux
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   119
-----------------------
27
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   120
- Linux is free:
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   121
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   123
Most of all, Linux is free as in free speech:
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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 
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   125
can still have a copy of that code.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   126
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   127
- Linux is portable to any hardware platform:
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   128
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   130
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   131
- Linux was made to keep on running:
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   132
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   134
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   135
- Linux is secure and versatile:
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   136
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
25
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   138
27
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   139
- Linux is scalable:
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   140
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   142
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   143
- The Linux OS and Linux applications have very short debug−times:
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   144
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   146
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   147
Getting Started
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   148
================
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   149
27
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   150
Logging in, activating the user interface and logging out
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   151
----------------------------------------------------------
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   153
looks better but eats more system resources.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   154
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   155
Graphical Mode
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   156
~~~~~~~~~~~~~~
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
25
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   158
27
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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*.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   161
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   163
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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,
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   166
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   168
guide is for future network and system administrators, who will need to meddle with the heart of the system.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   169
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   171
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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 (~)
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   173
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   174
Another common form for a prompt is this one:
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   175
[user@host dir]
25
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   176
27
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   179
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   180
When you see the login screen again, asking to enter user name and password, logout was successful.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   181
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   182
Text Mode
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   183
~~~~~~~~~
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   185
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   188
reasons.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   189
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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,
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   192
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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.
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   194
fe0672fd1be4 Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents: 25
diff changeset
   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!
25
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   196
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   197
Basic Commands
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   198
===============
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   199
55
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   200
1.ls
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   201
----
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   202
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   203
When invoked without any arguments, *ls* lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name *ls* is derived from *list segments* which was used in earlier systems.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   204
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   205
Files whose names start with "." are not listed, unless the *-a* flag is specified or the files are specified explicitly.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   206
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   207
Without options, *ls* displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   208
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   209
    * *-l* long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   210
    * *-F* appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   211
    * *-a* lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   212
    * *-R* recursively lists subdirectories. The command ls -R / would therefore list all files.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   213
    * *-d* shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   214
    * *-t* sort the list of files by modification time.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   215
    * *-h* print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   216
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   217
In some environments, providing the option *--color* (for GNU ls) or *-G* (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as *-F* would. To determine what color to use for a file, GNU *ls* checks the Unix file type, the file permissions, and the file extension, while FreeBSD *ls* checks only the Unix file type and file permissions.::
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   218
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   219
	$ ls
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   220
	jeeves.rst psmith.html blandings.html
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   221
	$ ls -l
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   222
	drwxr--r--   1 plum  editors   4096  jeeves
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   223
	-rw-r--r--   1 plum  editors  30405  psmith
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   224
	-r-xr-xr-x   1 plum  plum      8460  blandings
25
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   225
4df1ca9766b8 Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff changeset
   226
55
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   227
2.date
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   228
-------
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   229
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   230
The Unix date command displays the time and date. The super-user can use it to set the system clock.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   231
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   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::
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   233
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   234
	$date
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   235
	Tue Sep  8 12:01:45 IST 2009
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   236
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   237
Options
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   238
~~~~~~~~
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   239
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   240
*-d, -de* : string display time described by string, not now.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   241
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   242
*-e* : datefile like de once for each line of datefile
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   243
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   244
*-s, --set* : string set time described by string
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   245
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   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.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   247
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   248
*-u* : Display or set the date in UTC (universal) time.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   249
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   250
*date [-u|--utc|--universal] [mmddHHMM[[cc]yy].SS* : The only valid option for the this form specifies Coordinated Universal Time.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   251
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   252
*-u GMT* : example - Sat Feb 5 14:49:42 GMT 2005
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   253
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   254
*--utc, --universal* : Coordinated Universal Time, example - Tue Sep  8 07:05:54 UTC 2009
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   255
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   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.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   257
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   258
*--iso-8601* without TIMESPEC defaults to 'date'.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   259
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   260
*-R*, *--rfc-822* outputs RFC-822 compliant date string,
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   261
example - Sat Feb 5 09:50:23 EST 2005
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   262
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   263
*--help*
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   264
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   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.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   266
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   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.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   268
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   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::
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   270
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   271
	$date --set="20040908 01:22"
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   272
55
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   273
3.cd
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   274
-----
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   275
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   276
Change directory. Use “ cd ..” to go up one directory.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   277
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   278
One dot '.' represents the current directory while two dots '..' represent the parent directory.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   279
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   280
“ cd -” will return you to the previous directory (a bit like an “undo”).
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   281
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   282
You can also use cd absolute path or cd relative path (see below):
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   283
55
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   284
Absolute paths:
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   285
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   286
    An “ absolute path” is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   287
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   288
For example to get to /boot/grub you would type::
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   289
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   290
	$cd /boot/grub
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   291
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   292
This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   293
55
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   294
Relative paths:
44
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   295
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   296
    A “ relative path” doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   297
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   298
    For example if you are in root's home directory and want to get to /root/music, you type::
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   299
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   300
	$ cd music
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   301
6a9f6526b4f4 Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 27
diff changeset
   302
Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.
55
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   303
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   304
4.who
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   305
-----
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   306
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   307
The standard Unix command *who* displays a list of users who are currently logged into a computer.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   308
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   309
The *who* command is related to the command *w*, which provides the same information but also displays additional data and statistics.::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   310
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   311
	$who
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   312
	beeblebrox tty7         2009-09-08 10:50 (:0)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   313
	beeblebrox pts/0        2009-09-08 11:25 (:0.0)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   314
	dumbledore pts/1        2009-09-08 18:11 (potter.xyz.in)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   315
	beeblebrox pts/2        2009-09-08 18:53 (:0.0)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   316
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   317
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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).
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   319
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   321
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   322
    -a, process the system database used for user information with the -b, -d, -l, -p, -r, -t, -T and -u.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   323
    -b, show time when system was last rebooted
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   324
    -d, show zombie processes and details
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   325
    -H, show column headers
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   326
    -l, show terminals where a user can log in
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   327
    -m, show information about the current terminal only
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   328
    -p, show active processes
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   330
    -r, show runlevel of the init process.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   331
    -s, (default) show only name, terminal, and time details
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   332
    -t, show when system clock was last changed
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   333
    -T, show details of each terminal in a standard format 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   334
    -u, show idle time; XSI shows users logged in and displays information whether the terminal has been used recently or not 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   335
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   336
5.mkdir
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   337
--------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   338
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   339
Normal usage is as straightforward as follows::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   340
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   341
	$mkdir name_of_directory
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   342
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   344
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   345
Options
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   346
~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   347
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   348
On Unix-like operating systems, *mkdir* takes options. Three of the most common options are:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   349
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   350
    * *-p*: will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   351
    * *-v*: display each directory that mkdir creates. Most often used with -p.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   352
    * *-m*: specify the octal permissions of directories created by mkdir.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   353
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   354
*-p* is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   355
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   356
Examples
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   357
~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   358
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   359
An example of *-p* in action is::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   360
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   361
	$mkdir -p /tmp/a/b/c
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   362
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   363
If */tmp/a* exists but */tmp/a/b* does not, mkdir will create */tmp/a/b* before creating */tmp/a/b/c*.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   364
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   365
And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself)::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   366
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   367
	$mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   368
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   369
This will create:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   370
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   371
tmpdir 	- branches
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   372
	- tag
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   373
	- trunk	- sources - includes
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   374
			  - docs
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   375
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   376
Getting Help
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   377
============
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   378
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   379
1. apropos and whatis
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   380
----------------------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   381
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   382
This is a command to search the manual pages files in Unix and Unix-like operating systems. ::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   383
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   384
	$ apropos grep
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   385
	egrep       egrep (1)       Search a file for a pattern using full 		regular expressions
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   386
	fgrep       fgrep (1)       Search a file for a fixed-character 	string
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   387
	fmlgrep     fmlgrep (1)     Search a file for a pattern
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   388
	grep        grep (1)        Search a file for a pattern
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   389
	gzgrep      gzgrep (1)      Search a possibly compressed file for a 		regular expression
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   390
	nisgrep     nismatch (1)    Utilities for searching NIS+ tables
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   391
	pgrep       pgrep (1)       Find or signal a process by name or 	other attribute
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   392
	zgrep       zgrep (1)       Search a possibly compressed file for a 		regular expression
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   393
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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".
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   395
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   396
A short index of explanations for commands is available using the *whatis* command, like in the examples below::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   397
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   398
	[your_prompt] whatis ls
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   399
	ls                   (1)  - list directory contents
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   400
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   401
This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   402
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   404
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   405
	another prompt> apropos browser
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   406
	gmusicbrowser (1)    - Jukebox for large collections of audio files
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   407
	infobrowser (1)      - read Info documents
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   408
	libsmbclient (7)     - An extension library for browsers and that 		can be used...
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   409
	opera (1)            - a standards-compliant graphical Web browser
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   410
	sensible-browser (1) - sensible editing, paging, and web browsing
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   411
	smbtree (1)          - A text based smb network browser
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   412
	tvtk_doc (1)         - A GUI based TVTK documentation search browser.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   413
	viewres (1)          - graphical class browser for Xt
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   414
	w3m (1)              - a text based Web browser and pager
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   415
	www-browser (1)      - a text based Web browser and pager
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   416
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   417
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   418
2. man
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   419
-------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   420
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   422
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   423
To read a manual page for a Unix command, one can use::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   424
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   425
	$ man <command_name>
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   426
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   427
at a shell prompt; for example, "man ftp". In order to simplify navigation through the output, man generally uses the less terminal pager.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   428
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   430
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   431
	$ man 3 printf
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   432
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   433
Another example::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   434
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   435
	yourname@yourcomp ~> man man
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   436
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   437
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   438
Layout
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   439
~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   440
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   442
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   443
NAME
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   444
    The name of the command or function, followed by a one-line description of what it does.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   445
SYNOPSIS
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   446
    In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   447
DESCRIPTION
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   448
    A textual description of the functioning of the command or function.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   449
EXAMPLES
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   450
    Some examples of common usage.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   451
SEE ALSO
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   452
    A list of related commands or functions.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   453
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   455
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   456
History
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   457
~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   458
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   460
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   462
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   464
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   465
Usually the man pages are written in English. Translations into other languages can be also available on the system.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   466
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   467
The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   468
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   469
3. info
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   470
--------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   471
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   472
*info* is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   473
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   474
The syntax is ::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   475
	
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   476
	$ info <command_name>
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   477
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   478
*info* processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   479
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   480
    - *n* goes to the next page.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   481
    - *p* goes to the previous page.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   482
    - *u* goes to the upper page.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   483
    - *l* goes to the last(visited) node
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   484
    - To follow a cross reference, the cursor can be moved over a link (a word preceded by a `*`) and enter pressed.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   485
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   486
info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   487
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   488
4. --help
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   489
----------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   490
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   491
Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the *cat* command::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   492
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   493
	$ userprompt@host: cat --help
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   494
	Usage: cat [OPTION] [FILE]...
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   495
	Concatenate FILE(s), or standard input, to standard output.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   496
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   497
	  -A, --show-all           equivalent to -vET
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   498
	  -b, --number-nonblank    number nonempty output lines
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   499
	  -e                       equivalent to -vE
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   500
	  -E, --show-ends          display $ at end of each line
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   501
	  -n, --number             number all output lines
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   502
	  -s, --squeeze-blank      suppress repeated empty output lines
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   503
	  -t                       equivalent to -vT
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   504
	  -T, --show-tabs          display TAB characters as ^I
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   505
	  -u                       (ignored)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   506
	  -v, --show-nonprinting   use ^ and M- notation, except for LFD and 		  TAB
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   507
	  --help     display this help and exit
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   508
      	  --version  output version information and exit
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   509
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   510
	With no FILE, or when FILE is -, read standard input.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   511
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   512
	Examples:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   513
	  cat f - g  Output f's contents, then standard input, then g's 	  contents.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   514
	  cat        Copy standard input to standard output.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   515
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   516
	Report bugs to <bug-coreutils@gnu.org>.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   517
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   518
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   519
Basic file handling
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   520
===================
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   521
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   522
1. cp
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   523
------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   524
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   525
*cp* is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   526
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   527
Usage
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   528
~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   529
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   530
To copy a file to another file::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   531
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   532
	$ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   533
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   534
To copy a file to a directory::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   535
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   536
	$ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... 		TargetDirectory
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   537
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   538
To copy a directory to a directory::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   539
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   540
	$ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R } 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   541
	SourceDirectory ... TargetDirectory
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   542
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   543
Flags
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   544
~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   545
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   546
*-f* (force) – specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   547
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   548
*-P* – makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   549
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   550
*-i* (interactive) – prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   551
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   552
*-p* (preserve) – duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   553
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   554
    * The time of the last data modification and the time of the last access.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   555
    * The user ID and group ID (only if it has permissions to do this)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   556
    * The file permission bits and the SUID and SGID bits.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   557
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   558
*-R* (recursive) – copy directories (recursively copying all the contents)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   559
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   560
Examples
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   561
~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   562
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   563
To make a copy of a file in the current directory, enter::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   564
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   565
    $ cp prog.c prog.bak
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   566
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   567
This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   568
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   569
To copy a file in your current directory into another directory, enter::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   570
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   571
    $ cp zaphod /home/books/hhgg
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   572
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   573
This copies the jones file to /home/books/hhgg/zaphod.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   574
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   575
To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   576
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   577
    $ cp -p martin_luther_king martin_luther_king.jr
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   578
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   579
This copies the *martin_luther_king* file to the *martin_luther_king.jr* file. Instead of creating the file with the current date and time stamp, the system gives the *martin_luther_king.jr* file the same date and time as the *martin_luther_king* file. The *martin_luther_king.jr* file also inherits the *martin_luther_king* file's access control protection.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   580
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   581
To copy all the files in a directory to a new directory, enter::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   582
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   583
    $ cp /home/galactica/clients/* /home/hhgg/customers
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   584
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   585
This copies only the files in the clients directory to the customers directory.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   586
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   587
To copy a directory, including all its files and subdirectories, to another directory, enter:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   588
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   589
    $ cp -R /home/hhgg/clients /home/hhgg/customers
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   590
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   591
This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   592
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   593
To copy a specific set of files to another directory, enter::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   594
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   595
    $ cp zaphod arthur ford /home/hhgg/clients
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   596
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   597
This copies the *zaphod*, *arthur*, and *ford* files in your current working directory to the /home/hhgg/clients directory.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   598
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   599
To use pattern-matching characters to copy files, enter::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   600
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   601
    $ cp programs/*.py .
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   602
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   604
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   605
2. mv
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   606
-----
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   607
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   609
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   610
Conflicting existing file
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   611
~~~~~~~~~~~~~~~~~~~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   612
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   613
In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   614
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   615
Differences with copy and delete
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   616
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   617
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   618
Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   619
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   620
Examples
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   621
~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   622
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   623
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   624
	$ mv myfile mynewfilename    renames a file
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   625
	$ mv myfile otherfilename    renames a file and deletes the existing 		file "myfile"
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   626
	$ mv myfile /myfile          moves 'myfile' from the current 		directory to the root directory
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   627
	$ mv myfile dir/myfile       moves 'myfile' to 'dir/myfile' relative 		to the current directory
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   628
	$ mv myfile dir              same as the previous command (the 		filename is implied to be the same)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   629
	$ mv myfile dir/myfile2      moves 'myfile' to dir and renames it to 		'myfile2'
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   630
	$ mv foo bar baz dir         moves multiple files to directory dir
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   631
	$ mv --help                  shows a very concise help about the 		syntax of the command
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   632
	$ man mv                     prints an extensive user manual for 		'mv' in the terminal
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   633
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   634
In all cases, the file or files being moved or renamed can be a directory.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   635
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   637
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   638
3. rm
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   639
------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   640
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   642
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   643
Here's example to remove a file named "foo" from a directory, here shown with the -i option::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   644
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   645
  	$ rm -i foo
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   646
    	remove foo? y
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   647
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   648
Options
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   649
~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   650
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   651
Common options that rm accepts include:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   652
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   653
    * *-r*, which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   654
    * *-i*, which asks for every deletion to be confirmed ("interactive")
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   655
    * *-f*, which ignores non-existent files and overrides any confirmation prompts ("force")
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   656
    * *-v*, which shows what is being removed as it happens ("verbose")
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   657
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   658
*rm* is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   659
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   660
*rm -rf* (variously, rm -rf /, rm -rf `*`, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   661
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   662
*rm* is often used in conjunction with xargs to supply a list of files to delete::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   663
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   664
	xargs rm < filelist
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   665
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   666
When *rm* is used on a symbolic link, it deletes the link, but does not affect the target of the link.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   667
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   668
Permissions
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   669
~~~~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   670
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   671
Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   672
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   673
To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   674
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   675
If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   676
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   677
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   678
Command Line Arguments
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   679
=======================
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   680
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   681
In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   682
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   683
For example, in Unix and Unix-like environments, an example of a command-line argument is::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   684
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   685
	rm file.s
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   686
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   687
"file.s" is a command line argument which tells the program rm to remove the file "file.s".
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   688
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   690
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   692
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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*.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   694
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   696
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   697
Basic Text Processing
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   698
======================
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   699
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   700
1. head
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   701
--------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   702
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   703
*head* is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   704
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   705
	$ head [options] <file_name>
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   706
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   707
By default, *head* will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   708
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   709
	$ head -n 20 filename
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   710
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   711
This displays the first 5 lines of all files starting with *foo*::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   712
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   713
	$ head -n 5 foo*
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   714
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   715
Some versions omit the n and just let you say -5.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   716
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   717
Flags
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   718
~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   719
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   720
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   721
	-c <x number of bytes> Copy first x number of bytes.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   722
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   723
Other options: *sed*
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   724
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   725
Many early versions of Unix did not have this command, and so documentation and books had *sed* do this job::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   726
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   727
	sed 5q foo
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   728
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   729
This says to print every line (implicit), and quit after the fifth.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   730
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   731
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   732
2. tail
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   733
-------- 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   734
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   735
*tail* is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   736
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   737
The command-syntax is::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   738
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   739
	$ tail [options] <file_name>
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   740
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   741
By default, *tail* will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   742
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   743
	$ tail -n 20 filename
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   744
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   745
This example shows the last 15 bytes of all files starting with *foo*::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   746
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   747
	$ tail -c 15 foo*
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   748
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   749
This example shows all lines of filename from the second line onwards::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   750
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   751
	$ tail -n +2 filename
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   752
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   753
Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   754
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   755
	$ tail -20 filename
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   756
	$ tail -50c filename
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   757
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   758
However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   759
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   760
File monitoring
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   761
~~~~~~~~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   762
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   763
*tail* has a special command line option *-f* (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   764
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   765
	$ tail -f /var/adm/messages
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   766
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   767
To interrupt tail while it is monitoring, break-in with *Ctrl+C*. This command can be run "in the background" with &, see job control.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   768
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   769
If you have a command's result to monitor, you can use the *watch* command.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   770
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   771
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   772
3. cut
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   773
-------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   774
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   775
In computing, *cut* is a Unix command line utility which is used to extract sections from each line of input — usually from a file.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   776
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   777
Extraction of line segments can typically be done by *bytes (-b), characters (-c)*, or *fields (-f)* separated by a *delimiter (-d — the tab character by default)*. A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   778
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   779
Assuming a file named file containing the lines::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   780
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   781
	foo:bar:baz:qux:quux
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   782
	one:two:three:four:five:six:seven
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   783
	alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   784
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   785
To output the fourth through tenth characters of each line::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   786
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   787
	$ cut -c 4-10 file
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   788
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   789
This gives the output::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   790
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   791
	:bar:ba
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   792
	:two:th
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   793
	ha:beta
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   794
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   795
To output the fifth field through the end of the line of each line using the colon character as the field delimiter::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   796
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   797
	$ cut -d : -f 5- file
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   798
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   799
This gives the output::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   800
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   801
	quux
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   802
	five:six:seven
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   803
	epsilon:zeta:eta:teta:iota:kappa:lambda:mu
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   804
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   805
4. paste
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   806
---------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   807
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   808
*paste* is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility *cat* command which operates on the vertical plane of two or more files.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   809
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   810
To paste several columns of data together into the file *www* from files *who*, *where*, and *when*::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   811
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   812
	$ paste who where when > www
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   813
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   814
If the files contain:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   815
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   816
+-----------+------------+------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   817
|   who     |   where    |    when    |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   818
+===========+============+============+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   819
|  Sam      |  Detroit   | January 3  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   820
+-----------+------------+------------+	
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   821
|  Dave     | Edgewood   | February 4 |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   822
+-----------+------------+------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   823
|  Sue      |  Tampa     |  March 19  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   824
+-----------+------------+------------+	
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   825
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   826
This creates the file named *www* containing::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   827
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   828
	Sam            Detroit         January 3
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   829
	Dave           Edgewood        February 4
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   830
	Sue            Tampa           March 19
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   831
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   832
Shell Meta Characters
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   833
======================
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   834
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   836
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   837
The shell meta characters include:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   838
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   839
\ / < > ! $ % ^ & * | { } [ ] " ' ` ~ ; 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   840
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   841
Different shells may differ in the meta characters recognized.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   842
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   843
As an example,
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   844
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   845
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   846
	$ ls file.*
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   847
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   848
run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   849
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   850
	$ ls file.?
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   851
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   852
run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   853
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   854
	$ more c*
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   855
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   856
because the c* matches that long file name.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   857
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   858
Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the \  to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named `"``*`|more`"` can be accomplished with::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   859
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   860
	$ rm ??more
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   861
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   862
or::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   863
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   864
	$ rm $\backslash$*$\backslash$|more
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   865
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   866
or::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   867
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   868
	$ rm ''*|more'' 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   869
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   870
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   871
Looking At Files
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   872
================
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   873
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   874
1. cat
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   875
-------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   876
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   877
The *cat* command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of *concatenate*.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   878
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   880
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   882
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   883
Extensions
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   884
~~~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   885
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   886
Both the BSD versions of *cat* (as per the OpenBSD manpage) and the GNU coreutils version of *cat* specify the following options:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   887
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   888
    `*` -b (GNU only: --number-nonblank), number non-blank output lines
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   889
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   890
    `*` -n (GNU only: --number), number all output lines
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   891
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   892
    `*` -s (GNU only: --squeeze-blank), squeeze multiple adjacent blank lines
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   893
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   894
    `*` -v (GNU only: --show-nonprinting), displays nonprinting characters 		as if they were visible, except for tabs and the end of line 		character
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   895
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   896
    `*` -t on BSD, -T on GNU, implies -v but also display tabs as ^I
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   897
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   898
    `*` -e on BSD, -E on GNU, implies -v but also display end-of-line 		characters as $
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   899
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   900
Jargon File Definition
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   901
~~~~~~~~~~~~~~~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   902
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   903
The Jargon File version 4.4.7 lists this as the definition of *cat*::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   904
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   905
   1. To spew an entire file to the screen or some other output sink without
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   906
 	pause (syn. blast).
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   907
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   908
   2. By extension, to dump large amounts of data at an unprepared target or
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   909
 	with no intention of browsing it carefully. Usage: considered silly.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   910
 	Rare outside Unix sites. See also dd, BLT.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   911
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   912
	Among Unix fans, *cat(1)* is considered an excellent example of
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   913
 	user-interface design, because it delivers the file contents without 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   914
	such verbosity as spacing or headers between the files, and because 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   915
	it does not require the files to consist of lines of text, but works 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   916
	with any sort of data.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   917
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   918
	Among Unix critics, *cat(1)* is considered the canonical example of 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   919
	bad user-interface design, because of its woefully unobvious name. 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   920
	It is far more often used to blast a single file to standard output 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   921
	than to concatenate two or more files. The name cat for the former 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   922
	operation is just as unintuitive as, say, LISP's cdr.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   923
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   924
	Of such oppositions are holy wars made...
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   925
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   926
Useless Use of 'cat'
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   927
~~~~~~~~~~~~~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   928
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.”
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   930
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   931
Nevertheless one sees people doing::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   932
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   933
	$ cat file | some_command and its args ...
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   934
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   935
instead of the equivalent and cheaper::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   936
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   937
	<file some_command and its args ...
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   938
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   939
or (equivalently and more classically)::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   940
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   941
	some_command and its args ... <file
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   942
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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'.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   944
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   946
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   947
zcat
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   948
~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   949
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   950
*zcat* is a Unix program similar to *cat*, that decompresses individual files and concatenates them to standard output. Traditionally *zcat* operated on files compressed by compress but today it is usually able to operate on *gzip* or even *bzip2* archives. On such systems, it is equivalent to *gunzip -c*
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   951
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   952
2. more
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   953
--------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   954
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   956
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   957
History
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   958
~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   959
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   961
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   962
Usage
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   963
~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   964
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   965
The command-syntax is::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   966
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   967
	$ more [options] [file_name]
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   968
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   969
If no file name is provided, *more* looks for input from stdin.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   970
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   972
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   973
There are also other commands that can be used while navigating through the document; consult *more*'s *man* page for more details.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   974
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   975
Options
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   976
~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   977
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   979
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   980
    * -num: This option specifies an integer which is the screen size (in 	lines).
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   981
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   983
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   985
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   986
    * -f: Causes more to count logical, rather than screen lines (i.e., long 		  lines are not folded).
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   987
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   988
    * -p: Do not scroll. Instead, clear the whole screen and then display 		  the text.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   989
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   990
    * -c: Do not scroll. Instead, paint each screen from the top, clearing 		  the remainder of each line as it is displayed.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   991
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   992
    * -s: Squeeze multiple blank lines into one.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   993
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   994
    * -u: Suppress underlining.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   995
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   996
    * +/: The +/ option specifies a string that will be searched for before 		  each file is displayed. (Ex.: more +/Preamble gpl.txt)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   997
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   998
    * +num: Start at line number num.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
   999
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1000
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1001
3. less
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1002
--------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1003
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1005
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1006
History
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1007
~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1008
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1010
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1011
Usage
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1012
~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1013
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1015
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1016
By default, *less* displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1017
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1018
The command-syntax is::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1019
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1020
	$ less [options] file_name
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1021
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1022
Frequently Used Options
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1023
~~~~~~~~~~~~~~~~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1024
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1025
    * -g: Highlights just the current match of any searched string.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1026
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1027
    * -I: Case-insensitive searches.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1028
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1029
    * -M: Shows more detailed prompt, including file position.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1030
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1031
    * -N: Shows line numbers (useful for source code viewing).
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1032
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1033
    * -S: Disables line wrap ("chop long lines"). Long lines can be seen by 		  side scrolling.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1034
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1035
    * -?: Shows help.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1036
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1037
Frequently Used Commands
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1038
~~~~~~~~~~~~~~~~~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1039
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1040
    * [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1041
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1042
    * [Space bar]: Next page.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1043
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1044
    * b: Previous page.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1045
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1046
    * ng: Jump to line number n. Default is the start of the file.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1047
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1048
    * nG: Jump to line number n. Default is the end of the file.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1049
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1050
    * /pattern: Search for pattern. Regular expressions can be used.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1051
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1052
    * n: Go to next match (after a successful search).
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1053
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1054
    * N: Go to previous match.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1055
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1056
    * mletter: Mark the current position with letter.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1057
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1058
    * 'letter: Return to position letter. [' = single quote]
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1059
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1060
    * '^ or g: Go to start of file.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1061
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1062
    * '$ or G: Go to end of file.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1063
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1064
    * s: Save current content (got from another program like grep) in a file.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1065
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1066
    * =: File information.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1067
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1068
    * F: continually read information from file and follow its end. Useful 	    for logs watching. Use Ctrl+C to exit this mode.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1069
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1070
    * -option: Toggle command-line option -option.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1071
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1072
    * h: Help.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1073
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1074
    * q: Quit.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1075
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1076
Examples 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1077
~~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1078
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1079
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1080
	$ less -M readme.txt                     #Read "readme.txt."
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1081
	$ less +F /var/log/mail.log              #Follow mode for log
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1082
	$ file * | less                          #Easier file analysis.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1083
	$ grep -i void *.c | less -I -p void     #Case insensitive search 		                                          for "void" in all .c files
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1084
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1085
Directory Structure
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1086
====================
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1087
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1088
In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1089
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1090
The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1091
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1092
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1093
|   Directory   |             Description                        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1094
+===============+================================================+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1095
| /             | Primary hierarchy root and root directory of   |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1096
|               | the entire file system hierarchy.              |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1097
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1098
| /bin/         | Essential command binaries that need to be     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1099
|               | available in single user mode; for all users,  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1100
|               | e.g., *cat*, *ls*, *cp*.                       |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1101
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1102
| /boot/        | Boot loader files, e.g., *kernels*, *initrd*;  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1103
|               | often a separate partition.                    |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1104
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1105
| /dev/         | Essential devices, e.g., /dev/null             |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1106
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1107
| /etc/         | Host-specific system-wide configuration files  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1108
|               | (the name comes from *et cetera*)              |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1109
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1110
| /home/        | User's home directories, containing saved      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1111
|               | files, personal settings, etc.; often a        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1112
|               | separate partition.                            |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1113
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1114
| /lib/         | Libraries essential for the binaries in        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1115
|               | */bin/* and */sbin/*                           |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1116
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1117
| /media/       | Mount points for removable media such as       |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1118
|               | CD-ROMs, external hard disks, USB sticks, etc. |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1119
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1120
| /mnt/         | Temporarily mounted file systems               |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1121
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1122
| /opt/         | Optional application software packages         |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1123
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1124
| /proc/        | Virtual filesystem documenting kernel and      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1125
|               | process status as text files; e.g., uptime,    |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1126
|               | network. In Linux, corresponds to a *Procfs*   |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1127
|               | mount.                                         |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1128
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1129
| /root/        | Home directory for the root user               |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1130
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1131
| /sbin/        | Essential system binaries; e.g., *init*,       |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1132
|               | *route*, *mount*.                              |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1133
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1134
| /srv/         | Site-specific data which is served by the      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1135
|               | system.                                        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1136
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1137
| /tmp/         | Temporary files. Often not preserved between   |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1138
|               | system reboots.                                |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1139
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1140
| /usr/         | Secondary hierarchy for read-only user data;   |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1141
|               | contains the majority of (multi-)user          |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1142
|               | utilities and applications.                    |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1143
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1144
| /var/         | Variable files - files whose content is        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1145
|               | expected to continually change during normal   |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1146
|               | operation of the system - such as logs, spool  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1147
|               | files, and temporary e-mail files.             |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1148
|               | Sometimes a separate partition.                |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1149
+---------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1150
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1151
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1152
1. man hier
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1153
------------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1154
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1155
This is the manual page on the UNIX filesystem. The syntax for this is::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1156
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1157
	$ man hier
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1158
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1159
2. ls -l
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1160
---------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1161
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1162
Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is ::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1163
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1164
	$ ls -l
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1165
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1166
This can be done after entering the required directory. 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1167
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1168
Permissions and Ownership
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1169
=========================
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1170
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1171
1. chmod
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1172
---------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1173
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1174
The *chmod* command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&T Unix version 1, and is still used today on Unix-like machines.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1175
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1176
Usage
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1177
~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1178
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1179
The *chmod* command options are specified like this:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1180
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1181
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1182
	$ chmod [options] mode[,mode] file1 [file2 ...]
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1183
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1184
To view what the permissions currently are, type:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1185
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1186
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1187
	$ ls -l file
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1188
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1189
Command line options
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1190
~~~~~~~~~~~~~~~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1191
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1192
The *chmod* command has a number of command line options that affect its behavior. The most common options are:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1193
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1194
    * -R: Changes the modes of directories and files recursively
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1195
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1196
    * -v: Verbose mode; lists all files as they are being processed
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1197
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1198
Symbolic modes
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1199
+++++++++++++++
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1200
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1201
To the *chmod* utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1202
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1203
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1204
	$ chmod [references][operator][modes] file1 ...
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1205
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1206
The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to “all” but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1207
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1208
+--------------+--------+---------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1209
| Reference    | Class  |                Description                  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1210
+==============+========+=============================================+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1211
|      u       | user   | the owner of the file                       |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1212
+--------------+--------+---------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1213
|      g       | group  | users who are members of the file's group   |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1214
+--------------+--------+---------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1215
|      o       | others | users who are not hte owner of the file or  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1216
|              |        | members of the group                        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1217
+--------------+--------+---------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1218
|      a       | all    | all three of the above; is the same as *ugo*|
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1219
+--------------+--------+---------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1220
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1221
The *chmod* program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1222
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1223
+--------------+------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1224
| Operator     |                      Description                     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1225
+==============+======================================================+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1226
| +            | adds the specified modes to the specified classes    |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1227
+--------------+------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1228
| -            | removes the specified modes from the specified       |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1229
|              | classes                                              |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1230
+--------------+------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1231
| =            | the modes specified are to be made the exact modes   |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1232
|              | for the specified classes                            |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1233
+--------------+------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1234
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1235
The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1236
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1237
+-----+--------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1238
|Mode |    Name      |                 Description                    |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1239
+=====+==============+================================================+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1240
| r   | read         | read a file or list a directory's contents     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1241
+-----+--------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1242
| w   | write        | write to a file or directory                   |   
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1243
+-----+--------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1244
| x   | execute      | execute a file or recurse a directory tree     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1245
+-----+--------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1246
| X   | special      | which is not a permission in itself but rather |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1247
|     | execute      | can be used instead of 'x'. It applies execute |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1248
|     |              | permissions to directories regardless of their |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1249
|     |              | current permissions and applies execute        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1250
|     |              | permissions to a file which already has at     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1251
|     |              | least 1 execute permission bit already set     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1252
|     |              | (either user, group or other). It is only      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1253
|     |              | really useful when used with '+' and usually   |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1254
|     |              | in combination with the *-R* option for giving |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1255
|     |              | group or other access to a big directory tree  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1256
|     |              | without setting execute permission on normal   |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1257
|     |              | files (such as text files), which would        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1258
|     |              | normally happen if one just used 'chmod -R     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1259
|     |              | a+rx .', whereas with 'X' one can do 'chmod -R |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1260
|     |              | a+rX .' instead.                               |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1261
+-----+--------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1262
| s   | setuid/gid   | are Unix access rights flags that allow users  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1263
|     |              | to run an executable with the permissions of   |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1264
|     |              | the executable's owner or group.They are often |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1265
|     |              | used to allow users on a computer system to run| 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1266
|     |              | programs with temporarily elevated privileges  | 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1267
|     |              | in order to perform a specific task. While the |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1268
|     |              | assumed user id or group id privileges provided|
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1269
|     |              | are not always elevated, at a minimum they are | 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1270
|     |              | specific.They are needed for tasks that require|
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1271
|     |              | higher privileges than those which a common    |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1272
|     |              | user has, such as changing his or her login    |  
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1273
|     |              | password.                                      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1274
+-----+--------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1275
| t   | sticky       | The most common use of the sticky bit today is |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1276
|     |              | on directories, where, when set, items inside  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1277
|     |              | the directory can be renamed or deleted only by|
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1278
|     |              | the item's owner, the directory's owner, or the| 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1279
|     |              | superuser; without the sticky bit set, any user|
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1280
|     |              | with write and execute permissions for the     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1281
|     |              | directory can rename or delete contained files,| 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1282
|     |              | regardless of owner.                           |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1283
+-----+--------------+------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1284
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1285
The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1286
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1287
Symbolic examples
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1288
+++++++++++++++++
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1289
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1290
Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1291
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1292
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1293
	$ chmod ug+rw mydir
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1294
	$ ls -ld mydir
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1295
	drw-rw----   2 starwars  yoda  96 Dec 8 12:53 mydir
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1296
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1297
For a file, remove *write* permissions for all classes:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1298
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1299
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1300
	$ chmod a-w myfile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1301
	$ ls -l myfile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1302
	-r-xr-xr-x   2 starwars  yoda 96 Dec 8 12:53 myfile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1303
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1304
Set the permissions for the *u*ser and the *g*roup to read and execute only (no write permission) on *mydir*.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1305
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1306
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1307
	$ chmod ug=rx mydir
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1308
	$ ls -ld mydir
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1309
	dr-xr-x---   2 starwars  yoda 96 Dec 8 12:53 mydir
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1310
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1311
Octal numbers
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1312
+++++++++++++
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1313
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1314
The *chmod* command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1315
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1316
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1317
	$ chmod 664 myfile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1318
	$ ls -l myfile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1319
	-rw-rw-r--  1   57 Jul  3 10:13  myfile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1320
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1321
Since the *setuid*, *setgid* and *sticky* bits are not set, this is equivalent to:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1322
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1323
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1324
	$ chmod 0664 myfile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1325
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1326
Special modes
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1327
+++++++++++++
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1328
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1329
The *chmod* command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use **s** to represent the *setuid* and *setgid* modes, and **t** to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1330
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1331
Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1332
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1333
Redirection and Piping
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1334
=======================
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1335
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1336
In computing, *redirection* is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1337
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1338
Programs do redirection with the *dup2(2)* system call, or its less-flexible but higher-level stdio analogues, *freopen(3)* and *popen(3)*.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1339
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1340
Redirecting standard input and standard output
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1341
-----------------------------------------------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1342
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1343
Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1344
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1345
	$ command1 > file1
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1346
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1347
executes *command1*, placing the output in file1. Note that this will truncate any existing data in *file1*. To append output to the end of the file, use the >> operator.::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1348
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1349
	$ command1 < file1
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1350
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1351
executes *command1*, using *file1* as the source of input (as opposed to the keyboard).::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1352
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1353
	$ command1 < infile > outfile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1354
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1355
combines the two capabilities: *command1* reads from *infile* and writes to *outfile*
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1356
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1357
Piping
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1358
-------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1359
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1360
Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1361
A pipeline of three programs run on a text terminal::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1362
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1363
	$ command1 | command2
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1364
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1365
executes *command1*, using its output as the input for *command2* (commonly called piping, since the "|" character is known as a "pipe").
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1366
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1367
This is equivalent to using two redirects and a temporary file::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1368
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1369
	$ command1 > tempfile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1370
	$ command2 < tempfile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1371
	$ rm tempfile
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1372
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1373
A good example for command piping is combining *echo* with another command to achieve something interactive in a non-interactive shell, e.g.::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1374
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1375
	$ echo -e "user\npass" | ftp localhost
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1376
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1377
This runs the ftp client with input user, press return, then pass.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1378
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1379
Redirecting to and from the standard file handles
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1380
--------------------------------------------------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1381
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1382
In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1383
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1384
+------------+-------------+------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1385
|   Handle   |    Name     |      Description       |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1386
+============+=============+========================+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1387
| 0          |   stdin     |    Standard input      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1388
+------------+-------------+------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1389
| 1          |   stdout    |    Standard output     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1390
+------------+-------------+------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1391
| 2          |   stderr    |    Standard error      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1392
+------------+-------------+------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1393
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1394
For example:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1395
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1396
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1397
	$ command1 2> file1
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1398
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1399
executes *command1*, directing the standard error stream to *file1*.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1400
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1401
In shells derived from *csh* (the C shell), the syntax instead appends the & character to the redirect characters, thus achieving a similar result.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1402
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1403
Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1404
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1405
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1406
	$ find / -name .profile > results 2>&1
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1407
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1408
will try to find all files named *.profile*. Executed without redirection, it will output hits to *stdout* and errors (e.g. for lack of privilege to traverse protected directories) to *stderr*. If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge *stderr* (handle 2) into *stdout* (handle 1) using 2>&1 .
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1409
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1410
It's possible use 2>&1 before ">" but it doesn't work. In fact, when the interpreter reads 2>&1, it doesn't know yet where standard output is redirected and then standard error isn't merged.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1411
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1412
If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1413
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1414
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1415
	$ find / -name .profile 2>&1 | less
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1416
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1417
A simplified form of the command:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1418
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1419
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1420
	$ command > file 2>&1
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1421
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1422
is:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1423
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1424
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1425
	$ command &>file
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1426
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1427
or:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1428
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1429
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1430
	$command >&file
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1431
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1432
Chained pipelines
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1433
------------------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1434
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1435
The redirection and piping tokens can be chained together to create complex commands. For example:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1436
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1437
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1438
	$ ls | grep '\.sh' | sort > shlist
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1439
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1440
lists the contents of the current directory, where this output is filtered to only contain lines which contain *.sh*, sort this resultant output lexicographically, and place the final output in *shlist*. This type of construction is used very commonly in shell scripts and batch files.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1441
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1442
Redirect to multiple outputs
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1443
-----------------------------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1444
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1445
The standard command *tee* can redirect output from a command to several destinations.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1446
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1447
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1448
	$ ls -lrt | tee xyz
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1449
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1450
This directs the file list output to both standard output as well as to the file *xyz*.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1451
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1452
More Text Processing
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1453
====================
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1454
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1455
1. grep
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1456
--------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1457
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1458
*grep* is a command line text search utility originally written for Unix. The name is taken from the first letters in *global / regular expression / print*, a series of instructions for the *ed* text editor. The *grep* command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1459
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1460
Usage
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1461
~~~~~~
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1462
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1463
This is an example of a common *grep* usage:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1464
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1465
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1466
	$ grep apple fruitlist.txt
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1467
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1468
In this case, *grep* prints all lines containing 'apple' from the file *fruitlist.txt*, regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The *grep* command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1469
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1470
Like most Unix commands, *grep* accepts command line arguments to change this and many other behaviors. For example:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1471
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1472
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1473
	$ grep -i apple fruitlist.txt
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1474
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1475
This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells *grep* to be case insensitive, or to ignore case.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1476
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1477
To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1478
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1479
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1480
	$ grep -w apple fruitlist.txt
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1481
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1482
Regular expressions can be used to match more complicated queries.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1483
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1484
Variations
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1485
+++++++++++
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1486
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1487
There are countless implementations and derivatives of *grep* available for many operating systems. Early variants of *grep* included *egrep* and *fgrep*. The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern *grep* implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations, *grep* may also behave differently depending on the name by which it is invoked, allowing *fgrep*, *egrep*, and *grep* to be links to the same program.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1488
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1489
*pcregrep* is an implementation of *grep* that uses Perl regular expression syntax.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1490
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1492
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1494
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1496
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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*.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1498
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1499
2. tr
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1500
------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1501
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1502
*tr* (abbreviated from *translate* or *transliterate*) is a command in Unix-like operating systems.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1503
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1504
When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1505
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1506
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1507
	$ tr 'abcd' 'jkmn' 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1508
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1509
maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1510
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1511
Sets of characters may be abbreviated by using character ranges. The previous example could be written:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1512
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1513
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1514
	$ tr 'a-d' 'jkmn'
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1515
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1516
In POSIX compliant versions of *tr* the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1517
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1518
The *-c* flag complements the first set of characters.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1519
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1520
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1521
	$ tr -cd '[:alnum:]' 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1522
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1523
therefore removes all non-alphanumeric characters.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1524
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1525
The *-s* flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1526
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1527
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1528
	$ tr -s '\n' '\n'
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1529
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1530
replaces sequences of one or more newline characters with a single newline.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1531
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1532
The *-d* flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1533
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1534
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1535
	$ tr -d '\r'
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1536
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1537
Most versions of *tr*, including GNU *tr* and classic Unix *tr*, operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1538
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1539
Ruby and Perl also have an internal *tr* operator, which operates analogously. Tcl's *string map* command is more general in that it maps strings to strings while *tr* maps characters to characters.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1540
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1541
Elementary Regex
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1542
=================
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1543
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1545
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1547
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1549
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1551
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1552
+-------------+------------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1553
|Metacharacter|                            Description                     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1554
+=============+============================================================+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1555
| .           | Matches any single character (many applications exclude    | 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1556
|             | newlines, and exactly which characters are considered      | 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1557
|             | newlines is flavor, character encoding, and platform       |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1558
|             | specific, but it is safe to assume that the line feed      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1559
|             | character is included). Within POSIX bracket expressions,  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1560
|             | the dot character matches a literal dot. For example, a.c  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1561
|             | matches abc, etc., but [a.c] matches only a, ., or         |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1562
|             | c.                                                         |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1563
+-------------+------------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1564
| [ ]         | A bracket expression. Matches a single character that is   | 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1565
|             | contained within the brackets. For example, [abc] matches  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1566
|             | a, b, or c. [a-z] specifies a range which matches any      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1567
|             | lowercase letter from a to z. These forms can be mixed:    |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1568
|             | [abcx-z] matches a, b, c, x, y, or z, as does              |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1569
|             | [a-cx-z]. The - character is treated as a literal character|
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1570
|             | if it is the last or the first character within the        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1571
|             | brackets, or if it is escaped with a backslash: [abc-],    |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1572
|             | [-abc], or [a\-bc].                                        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1573
+-------------+------------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1574
| [^ ]        | Matches a single character that is not contained within the|
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1575
|             | brackets. For example, [^abc] matches any character other  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1576
|             | than a, b, or c. [^a-z] matches any single character       |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1577
|             | that is not a lowercase letter from a to z. As above,      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1578
|             | literal characters and ranges can be mixed.                |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1579
+-------------+------------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1580
| ^           | Matches the starting position within the string. In        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1581
|             | line-based tools, it matches the starting position of any  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1582
|             | line.                                                      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1583
+-------------+------------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1584
| $           | Matches the ending position of the string or the position  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1585
|             | just before a string-ending newline. In line-based tools,  |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1586
|             | it matches the ending position of any line.                |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1587
+-------------+------------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1588
| `*`         | Matches the preceding element zero or more times. For      |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1589
|             | example, ab*c matches "ac", "abc", "abbbc", etc. [xyz]*    |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1590
|             | matches "", "x", "y", "z", "zx", "zyx", "xyzzy", and so on.|
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1591
|             | \(ab\)* matches "", "ab", "abab", "ababab", and so on.     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1592
+-------------+------------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1593
| ?           | Matches the preceding element zero or one time. For        |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1594
|             | example, ba? matches "b" or "ba".                          |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1595
+-------------+------------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1596
| `+`         | Matches the preceding element one or more times. For       |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1597
|             | example, ba+ matches "ba", "baa", "baaa", and so on.       |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1598
+-------------+------------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1599
| `|`         | The choice (aka alternation or set union) operator matches |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1600
|             | either the expression before or the expression after the   |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1601
|             | operator. For example, abc|def matches "abc" or "def".     |
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1602
+-------------+------------------------------------------------------------+
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1603
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1604
Lazy quantification
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1605
--------------------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1606
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1607
The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between < and > symbols in this example:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1608
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1609
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1610
	Another whale explosion occurred on <January 26>, <2004>.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1611
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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".
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1613
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1615
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1616
One Liners
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1617
===========
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1618
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1620
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1621
The one liner can be
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1622
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1623
   1. An expression written in the language of the shell.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1624
   2. The invocation of an interpreter together with program source for the  	   interpreter to run.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1625
   3. The invocation of a compiler together with source to compile and 	  
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1626
      instructions for executing the compiled program.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1627
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1629
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1630
The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1631
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1632
The word *One-liner* has two references in the index of the book *The AWK Programming Language* (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1633
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1634
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1635
    “The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.”
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1636
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1638
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1640
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1641
Here are the very first of them:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1642
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1643
   1. Print the total number of input lines:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1644
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1645
      END { print NR }
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1646
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1647
   2. Print the tenth input line:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1648
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1649
      NR == 10
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1650
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1651
   3. Print the last field of every input line:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1652
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1653
      { print $NF }
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1654
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1655
Here are examples in J:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1656
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1657
   1. A function avg to return the average of a list of numbers:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1658
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1659
      avg=: +/ % #
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1660
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1661
   2. Quicksort:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1662
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1663
      quicksort=: (($:@(<#[) , (=#[) , $:@(>#[)) ({~ ?@#)) ^: (1<#)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1664
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1665
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1666
Many one-liners are practical. For example, the following Perl one-liner will reverse all the bytes in a file:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1667
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1668
	perl -0777e 'print scalar reverse <>' filename
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1669
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1671
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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).::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1673
	
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1674
	main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1675
	*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1676
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1678
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1680
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1681
	$ prog foo 'f??'; echo $?
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1682
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1683
	$ prog 'best short program' '??st*o**p?*'; echo $?
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1684
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1685
Here is a one line shell script to show directories:
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1686
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1687
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1688
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1689
	$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/' 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1690
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1691
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1692
One liners in functional programming
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1693
-------------------------------------
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1694
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1695
The following Haskell program is a one-liner: it sorts its input lines asciibetically.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1696
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1697
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1698
	 main = (mapM_ putStrLn . List.sort . lines) =<< getContents 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1699
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1700
-- In ghci a qualified name like List.sort will work, although as a standalone executable you'd need to import List.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1701
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1702
An even shorter version.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1703
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1704
 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1705
	main = interact (unlines . List.sort . lines) -- Ditto.
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1706
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  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)
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1708
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1709
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1710
	z = lambda x, y : [[ sum([x[i] [k]*y[k] [j] for k in 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1711
	range(len(x[0]))]) for j in range(len(y[0]))] for i in range(len(x))]
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1712
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1713
Another, that prints all primes within the specified range [2, n] :
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1714
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1715
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1716
	z = lambda n : [x for x in range(2, n + 1) if len([i for i in 
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1717
	range(2, x) if x%i == 0]) == 0]
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1718
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1719
This performs a Discrete Time Convolution on two input lists and yields a new list
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1720
::
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1721
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1722
	z = lambda x, h : [sum((x[i - j] if i - j >= 0 and i - j < len(x) 	  else 0)*h[j]
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1723
 	 for j in range(len(h)))
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1724
 	 for i in range(len(x) + len(h) - 1)]
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1725
6aa9568b5874 Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents: 44
diff changeset
  1726