Linux Notes Latest 2020
Linux Notes Latest 2020
Table of Contents
• The History of Unix
◦ Origins
◦ Key Success Factors
◦ Advantages of Unix
◦ Unix Turns Commercial
◦ MINIX
◦ The Genesis of the Free Software Movement
◦ Linux is Born
◦ It’s All About Freedom and Choice
• Free v/s Commercial Software
◦ Commercial Software Model
◦ Free Software Model
◦ Different Types of Free Software
◦ The Free Software Revenue Model
◦ Proprietary software v/s open source software
◦ Why commercial organizations take part in free software development
◦ Different categories of free software
◦ Different types of licenses and IPR (Intellectual Property Rights) issues
• Comparison of Popular Operating Systems for Personal Computers
◦ Microsoft Windows
◦ Apple OS X
◦ Linux
• Introduction to Ubuntu Linux
◦ Ubuntu Versions
◦ Strengths and Weaknesses of Ubuntu
• The Present Landscape of Unix / Linux Derivatives
• Pros and Cons of using Linux
◦ Pros and cons of using Linux
• The File System
◦ The Unix/Linux File System
◦ Accessing Multiple File Systems
◦ User Accounts and Home Directories
◦ The Standard File System Layout
• The Shells
◦ The Graphical Shell (GNOME Shell / Unity)
◦ The Bourne Shell
◦ The Command Line
• File System Manipulation Commands
◦ Shell Globbing Patterns
• Plain Text Editors
• Brief Overview of Working with the Vim Editor
• The Shell Scripting Language of the bash Shell
◦ Shell Variables
◦ The test Command and the [ Builtin
◦ The Control Structures
◦ Comments
◦ The Shebang Line
◦ Output
◦ Input
◦ Integer Arithmetic
◦ String Operations
• Standard I/O Streams and I/O Redirection
◦ Default Assignment of Standard I/O Streams
◦ Standard Output Redirection
◦ Standard Input Redirection
◦ Standard Input and Standard Output Redirection
◦ Standard Error Redirection
◦ Supplying the standard input from the command line
◦ Command Substitution
◦ Pipes
◦ Redirecting One File Descriptor to Another File Descriptor
• Filters
• Regular Expressions
◦ Basic Regular Expressions
◦ Extended Regular Expressions
• The grep Family of Commands
• Combining Multiple Commands using Logical Operators
• Vim Editor in More Detail
• Commands List
The History of Unix
The success of the UNIX system stems from its tasteful selection of a few key ideas and their elegant implem
Unix system has led a generation of software designers to new ways of thinking about programming. The ge
framework, which enables programmers to stand on the work of others. (the Turing Award selection committ
Origins
The Unix operating system is a watershed operating system developed at the then AT&T Bell Laboratories by a
Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy and Joe Ossanna starting in 1969. In the pa
system has had tremendous influence on the way we think about and develop operating systems and compute
well as various Unix-like and Unix-derived operating systems continue to dominate the computer world even tod
Information Technology, few computer programs have survived for such a long time while still retaining their ess
The people who developed Unix were originally working on a joint project of AT&T Bell Laboratories, General E
Institute of Technology (MIT) to develop a large ambitious multi-user operating system called Multics (Multiplexe
Service). Though the project had many innovations to its credit, it was a large and unwieldy project that was no
AT&T decided to pull out of the project, Thomson, Ritchie and others decided to develop a smaller operating sy
ideas of Multics. Ken Thomson had developed a game called Space Travel while still on the Multics projects, bu
game on a large machine in active use. He found a little used machine at Bell Labs and redeveloped Space Tra
gradually added the operating system ideas they had in mind and finally came out with a simple operating syste
because it supported a single user; as opposed to Multics. When it was developed further and started supportin
the name was changed to Unix.
Also, as a part of a court settlement with the US Government, AT&T was not allowed to sell computer software
Unix developers giving out copies of the Unix operating system with source code and online manuals to others
government agencies and private companies started using Unix. Because, the source code was available, it wa
of changes needed to run Unix on a new platform. It also allowed the universities and organizations to study the
with new features. Unix became phenomenally successful in the subsequent years. Denis Ritchie and Ken Tho
Award, considered to be the Nobel Prize of computing, in 1983.
The success of Unix can be largely attributed to the revolutionary concepts it pioneered or popularized for the fi
below.
• Unix was the first successful operating system to have been developed in a high level language
• Unix popularized the multi-level hierarchical file system. With some modifications, it is still in use by all maj
• Unix simplified device access by abstracting I/O to devices also as file I/O
• Unix provided a very powerful command line environment that supported combining the power of existing c
a new job done (I/O redirection). This major innovation dramatically changed the way people worked, impro
continues to be a major strength of the platform
• Unix stored all configuration information in plain text files, making them easily accessible and modifiable
• Unix started a new trend by providing an online manual with the system itself, so there was no need to wal
manual if one forgot some command or option.
• The communication and networking technologies that are so ubiquitous today, were largely developed first
• Unix provides powerful pattern matching capabilities in many of the tools that are part of the environment
Advantages of Unix
• Multi-user
• Multitasking
• The Unix Philosophy (do one thing well)
• Hierarchical file system
• Emphasis on the use of plain text files for configuration and data storage
• Devices as files
• Pattern matching
• Shell programming language
• Portability
• Online documentation
• Communication
• Security
• Reliability
• Performance
• Scalability
• Abstracted I/O & I/O redirection
From the beginning, Unix has been a system designed by programmers, for the programmers. Unlike other
try to protect the user from committing mistakes unintentionally, Unix generally assumes you know what you ar
command issued by the user without bothering him/her with prompts to confirm the action. Unix commands wo
extraneous output when a commands does its job successfully. Thus applies especially to the command line en
the GUI interfaces are quite user-friendly.
MINIX
The famous academician and author Andrew S Tanenbaum had developed a Unix-like operating system called
operating systems. Its source code was published as a part of his textbook Operating Systems: Design and Imp
publisher had restricted its use to those who purchase the book and to academic use only. Thus, it was not free
Andrew S Tanenbaum
Linux is Born
I’m doing a (free) operating system (just a hobby, won’t be big and professional like gnu)… – Linus Torvalds
In 1991, Linus Torvalds, a student from Finland, developed an experimental operating system kernel for the PC
Linux kernel (Linux stood for Linux is Not Unix, again a reference to Unix’s now commercial status). After he op
programmers on the Internet, the project grew rapidly. With the help of these volunteers, finally the Linux kerne
combined to form the first completely free working Unix-like system (BSD’s case was still going on in the courts
be known as GNU/Linux, or simply Linux and became widely popular after Linus granted all the freedoms to ev
so) and a large community of volunteers, individuals, organizations and even commercial corporations, started
Linus Torvalds
Usually, the software companies do not provide the original source code developed by their programmers in a h
efforts to their customers. They only provide the binary machine code or executable version of the programs to
enough to run on a computer, it is extremely difficult to understand and modify such binary versions of software
software and sells it without any changes as one’s own development, the bluff will get caught. If the original dev
copyright on one’s original work of creation, the copyright laws prevent others from making copies of the work w
copyright holder.
Further, the companies never “sell” the software, they merely license it. Even when you “purchase” legal softwa
the software; you merely purchase a license to use the software subject to a host of terms and conditions. Tha
software, you are made to click on an “I agree” or “Accept” button. Once you click on this button, you are legally
terms that, among other things, prohibit you from making copies and giving to others. A host of other measures
based activation are used to prevent piracy (illegal copy and use) of software. Despite all these efforts, piracy d
especially in certain parts of the world and companies have to recover the lost revenue from the genuine purch
Richard Stallman has also advocated another condition on such free software – if you develop some modified o
free community-developed software, you must also give the software you developed in this way (with source co
free. This, according to him, is the only way to sustain the free software movement and continue further develo
Software given for free under this condition is called “copyleft” (the exact opposite of copyright). He has design
GPL (General Public License) that enforces all these conditions and he exhorts everyone to release their softw
license means that if you take some code under the GPL and modify/enhance it, you must distribute your enha
the same license i.e. the GPL. In other words, you must also provide your modified software along with its sour
commercial entity cannot take GPLed software, enhance it and sell the enhanced version commercially to mak
do not like such strict “copyleft” restriction. They distribute their software under more “permissive” licenses like
do allow commercial entities to sell software made or enhanced from free software. In a multi-licensing scheme
more than one license and the user is free to select which license they want to obey.
Other strategies include displaying online advertisements and earning revenue from them, giving a basic versio
“premium” version with more features, etc. The latter model is named "freemium". Companies can even make m
details (like email id) through a “free registration” process and then selling these contact details to mass advert
completely free and open source version of particular software, but derive indirect benefits by incorporating the
version by the community into their own commercial offerings. For example, Red Hat Inc., another major Linux
the free and open source Fedora Linux distribution in a major way. Enhancements made in Fedora Linux by the
engineers and thousands of volunteers around the world often find their way into the commercial Red Hat Ente
Do you still think the commercial interests of a for-profit company and free products are just not compatible w
facts –
• On 19th January in the year 2000, shares in Yahoo! Japan became the first stock in Japanese history to
reaching a price of 101.4 million yen ($9,62,140 at that time) for a single share. All of the company’s pro
• In the year 2016, Google’s revenues from advertising stood at $79 billion.
• On 18th May 2012, when Facebook entered the stock market for the first time, the company was valued
provides free social networking services to its users.
Microsoft Windows
Microsoft Windows is a proprietary OS and must be purchased for using it. It is a very user-friendly, easy to use
familiar with it. Because of its popularity, a large number of commercial as well as free software is available for
excellent device driver support. Even though Microsoft has taken significant strides in improving its stability and
versions, lingering doubts about these issues still remain. Being the most popular OS among users has also m
attacks by crackers (highly skilled programmers with malicious intention). Malware like computer viruses, worm
continue to affect systems running Microsoft Windows. Even using a top-notch commercial security solution do
one’s system completely immune to such attacks. Security of Microsoft Windows systems is a continuous head
Microsoft Windows is also infamous for needing too much hardware resources and higher-end configurations to
mix of software from so many different sources on Microsoft Windows systems, the overall experience is some
problem, it becomes difficult to pinpoint the exact source of the trouble. Microsoft Windows officially supports o
(Windows Explorer) and CLI, though third party alternative are available.
Apple OS X
Apple OS X is also a proprietary operating system. It comes bundled with the machine and neither work withou
party experimental solutions). The system is known for its high quality hardware and visual appeal and what ar
best user experience. The entire hardware, operating system and software environment is tightly controlled by
consistent and reliable user experience. OS X also officially supports only the built-in GUI and CLI, though third
to try. Though the systems are considered quite secure; it, too, is not immune from attacks. The major advantag
high-quality user experience. Against that, the user is confined to a narrow world controlled by Apple and third p
limited. Also, the product comes at a high premium. Internally, OS X is a graphical environment that runs on top
Unix subsystem.
Linux
Linux, just like its predecessor Unix, is known for its high performance, security, reliability and portability. No ma
the hardware is, one can find a Linux distribution that would run on it. Even though lack of whole-hearted suppo
providing high quality device drivers dents Linux’s image of being a reliable and portable OS to some extent, it
configurations. It combines the high-power CLI that has traditionally been Unix’s strength with an impressive GU
friendly as the other two OSs. Linux lets us choose from a wide variety of distros, then presents an even wider
to install from and is flexible enough that with experience we can configure it exactly the way we want it to be. H
available under Linux sometimes lack the polish of corresponding Windows applications (especially on the GUI
all the bells and whistles that commercial applications on Microsoft Windows or OS-X platforms provide. But the
time and keep getting improvements from the community. Upgrades are as free as the base OS and it is just a
when they want to upgrade their systems. However, one should be prepared for the occasional glitches. Linux p
the CLI as well as GUI. The most common GUIs are KDE, GNOME and Unity. The newest versions of the GUI
the other two OSs as far as visual attractiveness is concerned, though they, too, require a bit higher configurati
A major advantage of Linux is that not only is it free; it also provides us complete freedom in running the operat
operating systems that require at least one free hard disk partition (that would be erased during the installation)
process, there is a range of choices for running Linux – from a no-risk no-installation trial using a Live CD to ins
(multi-boot configuration) to booting Linux directly off a USB flash disk or even the network – Linux supports it a
interoperability with Microsoft Windows and you can access the Windows partitions on your computer and the o
servers as easily as from Windows. Unfortunately, facility of accessing the Linux partition from Microsoft Windo
only access (we can read the files but cannot modify them) using third party tools. The office suite on Linux – O
provides good interoperability with the Microsoft Office suite with few caveats and some irritants. In essence, Li
an average computer user and, once you settle down, can be as comfortable to use as it can get. And all this is
no strings attached.
The market share of Linux is difficult to estimate because it is free and there is no central point of distribution, b
presence in supercomputers, mainframes, servers and graphics workstation markets. While much of the PC m
Windows and OS X has a considerable presence in the premium segment and has its own loyal fan base, Linu
setups and at the lower end of the spectrum, with low-end PCs. It is also popular among developers. Linux, too
who sneer at people using any other operating system.
Ubuntu Linux is a Linux distribution created by the UK based company Canonical Ltd., established by the South
Shuttleworth. It is in turn based on the Debian GNU/Linux distribution. Ubuntu is an ancient African word mean
philosophy that emphasizes putting common goals and the community above individual interests and believes
open source software community also has similar philosophy, Ubuntu was chosen as the name of the distributi
reason for choosing this name, read the two words after the second “the” in the first line of this paragraph again
source software. Canonical expects to earn money by providing paid support services. While Canonical is the m
supported by the Ubuntu Foundation and large developer and user communities. Ubuntu focuses on usability, s
usability (ease of use) and good device support has allowed it to gain and retain a place among the top Linux d
Ubuntu Versions
Ubuntu has a fixed release cycle, with a new version being released in the April and October months of each ye
denoted by two-digit year, followed by a dot, followed by two-digit month. Thus, Ubuntu 12.04 LTS was released
have two-word names, with the first word being an adjective and the second the name of an animal. For examp
Precise Pangolin, Ubuntu 12.10 was called Quantal Quetzal. Ubuntu 16.10 is called Yakkety Yak. People often
the release. The first words are chosen in alphabetic order, so one can know which version is newer just by loo
Each desktop edition release is officially supported for 9 months. Every two years, a Long Term Support (LTS)
versions are supported for 5 years.
There are several other variants of Ubuntu including a server edition, Edubuntu (a distro aimed at school stude
software), Kubuntu / Ubuntu GNOME (variants using the KDE / GNOME desktop instead of the default Unity de
(lightweight variants for use on low-end computers using the LXDE / Xfce desktop environment), etc.
On the other hand, naive end users often complain that Linux is not as intuitive or easy to use as its proprietary
community provides good support for major issues, minor issues are often relegated to the back burner. Parado
open source software is also a problem. Software changes too fast, leading to a rather steep learning curve. Th
types of software and the preferences continually shift.
Linux is a good platform for those people who have an ideological preference for freedom and openness and w
effort in learning new things. It is also a very good platform for servers, development systems and cloud deploy
To avoid all these problems, the operating system provides a file system interface to secondary storage. The co
after the filing cabinets commonly found in offices, but with new twists. A file system chiefly contains two types
(also known as folders). A file is the basic unit of secondary data storage on computers. Any data that the user
in the file systems. The files are identified by their names, which are much easier for humans to remember than
have a large number of files, directories are used to organize them. A directory is nothing but a container that m
directories known as its subdirectories. The subdirectories may, in turn, contain files as well as subsubdirectorie
well as further directories and so on. In fact, there is no theoretical limit to such nesting (putting one container o
every file system starts with what is called its root directory and then the root directory may contain files as well
on and on like that. The following figure illustrates this concept. Here the green nodes represent directories, wh
As an added convenience, directory names begin with d (except root) and filenames begin with f, though there
Internally, the data is still accessed by disk block numbers, but now the file system component of the operating
or directory is stored in which block number(s) and which blocks are free and which ones are in use. This takes
users. To maintain this information, some data structures are created on the disk.
The file systems follow certain basic rules. Each file system has a single root directory that is the starting point
in the file system contains a number of objects (files and directories), each of which must have a name unique
can never be two objects with the same name in the same directory. However, two different directories can hav
same name. As long as you know the directory containing the object you want to use, knowing its name may be
unique within its directory. Otherwise, you will have to specify the absolute (or full) path leading to the object. Th
directory, then the subdirectory, then the sub-subdirectory, and so on, until you reach to the directory that conta
finally the object itself. Each of these components is separated by a special character that is not permitted in fil
uniquely identifies an object in the entire file system.
The file system structure is generally described as a tree structure, with the root directory forming the only root
forming branches and the files forming the leaves. If a directory is contained inside another directory, the forme
latter and the latter is said to be the parent of the former. Every directory, except the root directory, has a paren
further objects (files or directories) in them, and hence are the end of the branches. They are known as leaves.
are typically drawn upside down, with the root at the top.
A blank disk initially contains no file system. The initial blank file system structure (empty data structures) is cre
formatting the disk. Formatting a disk that already contains a file system destroys the existing file system and re
Certain types of disks such as the hard disks can contain multiple partitions. Each partition may be formatted to
independent file system. Formatting one partition does not affect the others. The operating system provides util
formatting the disks and their partitions.
The command line interface provides commands to navigate the directory structure, while the graphical environ
explore the file system. Common operations provided at the file system level with both the user interfaces includ
directories, copying a file or directory to another part of the file system, moving a file or directory to another par
file or directory, deleting (removing) a file or directory (including all the contents), etc. Often security constraints
user from carrying out certain operations on certain files or directories.
Different devices and different operating systems use different file systems. For example, Microsoft Microsoft W
systems typically use a file system called FAT (File Allocation Table) along with its variants and a file system ca
System). The first one is very simple in nature, but limited in power and performance. It also does not provide a
advanced than the former and provides a host of features, including security. Both file systems are case insens
letters are treated as same. Thus, you cannot have two files with the names myletter and MyLetter in the same
the filename into two parts – the filename proper followed by a . (dot) and the extension. Both use the \ (backw
as the path separator character. The extension part of the filename is used to signify the type of the file. Differe
systems. Linux generally uses some version of the extended file system (ext2, ext3 or ext4), though several oth
These are quite powerful and feature rich file systems. The extended file system is case sensitive, i.e. capital an
different characters. So you may have two files with the names f1 and F1 in the same directory. It uses the / (sl
separator. The concept of using the extension part of the filename to signify its type is not mandatory and is we
memory cards used with mobile phones usually come formatted with the FAT file system when the size is upto
when the size is > 32GB (for example, the micro SDXC cards). CDs generally use the ISO9660 file system, whi
These different file systems have different characteristics.
The Unix/Linux File System
• Hierarchical file system
◦ While the Windows file systems is actually a forest, the UNIX file systems is a proper tree (actually a d
• The root directory is identified by the / (slash) character
• Directories and files
• Identifying a file system object uniquely using path
• Components of the path are separated by the / (forward slash) character
• / (forward slash) v/s \ (backslash)
• Filenames are case sensitive
• Extensions not an essential part of file name (executable files usually have no extension)
• Any character except / can be used in file names
• The notion of current directory and relative paths
• Absolute path v/s relative path
• Interactive users have a home directory. A user has full permissions on one's home directory. The ~ (tilde s
home directory in file system manipulation commands
• Hidden files and directories - any file or directory whose name starts with a . is considered hidden. Hidden
displayed in the nautilus file browser (GUI) or by the ls command (CUI). However, there are options to disp
We may access any other file system by mounting it on any existing directory (this directory is called the mount
contents of that file system appear as the contents of the mount point directory. If the mount point previously co
subdirectories), they are masked (hidden) for the duration of the mount. Now we may access (and modify) the c
the mount point directory. When we no longer need to use the file system, we may unmount it. At this point, the
point directory get unmasked (become visible again). This process is depicted in the following figures a, b, c an
system. Figure b shows the file system on another device. Figure c shows the situation after mounting the file s
directory d3 of Figure a. The original contents of d3 are now masked and the contents of the file system mounte
contents of d3. Figure d shows the situation after unmounting the second file system. The original contents of t
visible again.
Figure a: The root file system
Figure b: File system on another device
Figure c: After mounting the second file system on directory d3
Figure d: After unmounting the second file system from directory d3
However, the common practice is to mount file systems onto empty directories. In the default configuration, Ubu
fixed devices in the system and shows them in the places menu and the left pane of the file browser. They are m
access them. The file browser shows a triangular icon alongside all mounted file systems other than the root file
unmounted by clicking on this icon. It may be mounted again when the user tries to access it again next time. T
unmounted. Removable devices are automatically mounted when they are inserted. Read-only media like optic
simply removing or ejecting them. Media on which writing is possible (like USB flash disks) must be unmounted
the file browser or by right clicking its icon on the desktop and selecting “safely remove device” option. This cau
memory for improved performance to be flushed to the disk. A message at the end of this process announces t
device and the unmount icon disappears from besides the device’s entry in the file browser’s left pane. Only aft
detached from the system. Failure to observe this procedure may result in loss of data or damage to the file sys
While this method of accessing the other storage devices in the system may sound unnecessarily complicated,
and has several distinct advantages.
Not only local file systems, even the remote file systems can also be accessed in the same way. For example, W
on local directories using the SMB (Server Message Block) protocol and then be accessed just like local conten
System), FTP server directories can also be mounted on a directory and accessed as a part of the file system.
Of course, all these procedures can also be carried out using commands. It is also possible to configure the sy
at particular mount points automatically every time the system boots. By default, the system mounts other fixed
system in directories under the /media directory.
User accounts are identified by their names by the human users of the system; but internally, they are identified
special user account with numerical user id 0, usually called root. This user is the most powerful user in the sys
The Shells
Unix offers a variety of shells in both text mode and graphical mode. The graphical mode shells include the GN
LXDE, MATE, etc. The commonly used text mode shells include sh (the original Bourne shell), ksh (Korn shell)
Again SHell), etc.
Multiple screens
• 12 virtual screens (6 text mode screens and 6 graphics mode screens) accessed using the shortcut keys C
• Each graphical screen can be configured to have multiple workspaces. Workspaces are arranged in a rect
rows and some number of columns. To switch between workspaces and to drag and drop windows betwee
Workspace Switcher. Shortcut keys for switching between the workspaces are CTRL-ALT-Arrow Keys. To m
workspace, press ALT-SPACE to open the window menu and select appropriate option; or open Workspac
• In the graphical mode, we may open one or more windows of the GNOME Terminal program to work in tex
we may have one or more tabs. The shortcut key for creating a new tab is CTRL-SHIFT-T and the shortcut
are CTL-PgUp and CTL-PgDown
• Quoting and escaping Strings on the command line can be specified without using any quotes. However,
or some other character having a special meaning to the shell interpreter, the string must be enclosed in qu
special characters must be escaped
◦ Escaping A character having special meaning to the shell can be escaped by preceding it with \ (back
meaning. The special meaning of the backslash itself can also be removed by preceding it with anothe
◦ Single Quotes Almost no processing is carried out inside strings enclosed in single quotes 'aaa bbb
◦ Double Quotes Double quotes also behave like single quotes, but variable / parameter expansion
$variable_name is converted into the value of the variable. Hence if the value of variable name
echo 'Beam me up, $name' outputs Beam me up, $name but echo "Beam me up, $name" outputs
• Operators (Input/Output Redirection, Combining Multiple Commands using Logical Operators)
Examples
vi filename
Shell Variables
• The shell variables need not be declared. A variable is created automatically the first time it is assigned a v
string; but, in some contexts, may be interpreted as numbers. The variable assignment takes the form
variable_name=value
$variable_name
${variable_name}
• Built-in variables of the shell The shell has a number of built-in variables. By convention, their names are
PATH, HOME, SHELL, TERM, etc.
• It is not an error to attempt to access the value of an undefined variable. Such an attempt simply returns a
length)
◦ SHELL : The current shell
◦ HOME : Home directory of the currently logged in user
◦ PATH : A : (clolon) separated list of directories that are searched for external commands
◦ TERM : The type of the current terminal
◦ PS1 : The primary prompt
◦ PS2 : The secondary prompt
• Special parameters The shell has several special parameters
◦ # ($#)
◦ * and @ ($*, "$*", $@, "$@")
◦ $?
• Debugging the shell script
◦ Use set -xv to turn debugging on
◦ Use set +xv to turn debugging off
echo $?
• String tests
◦ -z string Returns true if string has zero length (empty string)
◦ -n string Returns true if string has non-zero length
◦ string1 = string2 Returns true if string1 is equal to string2
◦ string1 != string2 Returns true if string1 is not equal to string2
• Integer tests
◦ no1 -gt no2 Returns true if no1 is greater than no2
◦ no1 -ge no2 Returns true if no1 is greater than or equal to no2
◦ no1 -lt no2 Returns true if no1 is less than no2
◦ no1 -le no2 Returns true if no1 is less than or equal to no2
◦ no1 -eq no2 Returns true if no1 is equal to no2
◦ no1 -ne no2 Returns true if no1 is not equal to no2
• Logical operations on tests
◦ test1 -a test2 (and) Returns true if both the tests evaluate to true
◦ test1 -o test2 (or) Returns true if any one of the tests evaluates to true
◦ !condition (not) Negation / logical inversion of condition
• New line in syntax
◦ A ; (semicolon) can be used wherever the syntax requires a new line
if command1
then
statement1
statement2
...
elif command2
then
statement3
statement4
...
elif command3
then
statement5
statement6
...
...
...
else
statement7
statement8
...
fi
if test condition1
then
statement1
statement2
...
elif test condition2
then
statement3
statement4
...
elif test condition3
then
statement5
statement6
...
...
...
else
statement7
statement8
...
fi
if [ condition1 ]
then
statement1
statement2
...
elif [ condition2 ]
then
statement3
statement4
...
elif [ condition3 ]
then
statement5
statement6
...
...
...
else
statement7
statement8
...
fi
while command
do
statement(s)
done
while [ condition ]
do
statement(s)
done
for ((i=0;i<10;i++))
do
echo $i
done
• break and continue
◦ break can be used in the loops to terminate the loop and jump to the next statement after the loop
◦ continue can be used to terminate the current iteration of the loop and jump to the start of the loop
• The command true does nothing, but returns with an exit status of zero (success / true)
• The command false does nothing, but returns with a non-zero exit status (failure / false)
i=0
while true
do
echo $i
let i++
if [ $i -ge 10 ]
then
break
fi
done
Comments
• The # character is used for writing single-line comments
• All the characters starting from the # upto the end of the line are treated as comment and are ignored by th
• There is no syntax for multi-line comments
#!/bin/bash
#!/usr/bin/perl
#!/usr/bin/python
Output
• echo
◦ echo is used to output its arguments
◦ By default, echo appends a new line at the end of its output
◦ To suppress that new line, use the -n option:
• printf
◦ printf is used for formatted output
◦ It syntax is identical to the printf function in the standard C library, but it is a command
◦ It does not append a new line at the end of its output by default
Input
• read
◦ The read shell builtin can be used to read the values of one or more variables
◦ read x reads a line from the input and assigns it to the variable x
◦ read x y z reads a line from the input, separates the words in the line and assigns them in order to
◦ If there are less words than variables, the remaining variables are not assigned
◦ If there are more words than variables; all but the last variable are assigned one word while the last va
line
◦ The -p option can be used to display a prompt for reading
Integer Arithmetic
• expr
◦ The expr command can be used to evaluate complex expressions involving integers
◦ It outputs the result of the evaluation
◦ Usual operators are available
◦ All the operators and arguments must be separated by white spaces
◦ Rules of precedence and associativity are followed
◦ Brackets can be used to group subexpressions
◦ Charactes having a special meaning in the shell (like ( and * ) must be either quoted or escaped
◦ The output of expr can be assigned to a variable using Command Substitution
expr 10 + 20
expr $x + $y
expr $x + $y \* $z
expr \( $x + $y \) \* $z
expr "(" $x + $y ")" "*" $z
expr 10 + \( $y - $x - \( $x + $y - \( 5 \* 3 \) \) \) \* 3
x=`expr $y + $z`
x=$(expr $y + $z)
• $(( ))
◦ $(( expression )) can be used to evaluate expression
◦ It is a form of Command Substitution. I.e., $(( expression )) in the command line is replaced by th
expression
x=$(( 10*20 ))
x=$(( (10+20)*20 ))
x=$(( ($x+$y)*$z ))
x=$(( (x+y)*z ))
x=$(( 10+(y-x-(x+y-(5*3)))*3 ))
x=$(( y++ ))
• let
◦ let is a shell builtin for integer aritmetic
◦ let expects an expression as a single argument (so the expression must not have spaces in it; or it
◦ let evaluates its argument just like `$(( ... ))
◦ let is not a form of Command Substitution, so assignment must be used inside the let expression to
some variable
let x=10*20
let x=(10+20)*20
let x=y++
let i++
String Operations
• String concatenation
◦ Two strings can be concatenated by simply placing them side-by-side without any intervening space
"abc""xyx"
$x$y
abc$x
${x}abc
• String length
◦ Using expr : expr length string outputs the length of the string
◦ Using bash parameter substitution: ${#variable} results in the length of the variable
• Substring
◦ Using expr : expr substr str pos len outputs a substring of maximum length len from the string
first character has the position 1)
◦ Using bash parameter substitution: ${variable:off:len} returns a substring of maximum length
starting from offset off (the first character has the offset 0)
• String matching
◦ Using expr : expr match str regexp performs an anchored match of the string str with the regular
Table of
Open Files
/dev/tty
/dev/tty
/dev/tty
f1
f2
$ p1
0 stdin /dev/tty
FD Name Associated with
1 stdout /dev/tty
2 stderr /dev/tty
$ p1 1>file1
$ p1 >file1
$ >file1 p1
0 stdin /dev/tty
2 stderr /dev/tty
The file file1 will be opened in write mode by the shell before execution of the command. If it exists, it will be tru
$ >t1
This will create the file t1, if it does not exist; and will truncate the file t1, if it does.
$ p1 1>>file1
$ p1 >>file1
$ >>file1 p1
0 stdin /dev/tty
2 stderr /dev/tty
FD Name Associated with
The file file1 will be opened in append mode by the shell before execution of the command.
$ p1 0<file1
$ p1 <file1
$ <file1 p1
1 stdout /dev/tty
2 stderr /dev/tty
The file file1 will be opened in read mode by the shell before execution of the command. If the file does not exis
$ p1 <file1 >file2
$ p1 >file2 <file1
$ >file2 <file1 p1
2 stderr /dev/tty
The file file1 will be opened in read mode by the shell before execution of the command. If the file does not exis
The file file2 will be opened in write mode by the shell before execution of the command. If it exists, it will be tru
file1 and file2 must not be same files. If the following command is executed:
$ p1 <zzz >zzz
The file zzz will be overwritten before the execution begins and it will be an empty file.
$ p1 2>file1
$ 2>file1 p1
0 stdin /dev/tty
1 stdout /dev/tty
The file file1 will be opened in write mode by the shell before execution of the command. If it exists, it will be tru
If we use 2>> operator in place of 2> operator, the file will be opened in append mode.
$ p1 2>>file1
/dev/null is the null device. Any output sent to it is simply discarded. If we try to perform input from it, we immed
$ p1 << END
INPUT LINE 1
INPUT LINE 2
INPUT LINE 3
INPUT LINE 4
END
This way of providing input from the command line is known as the here document.
Command Substitution
Command substitution means constructing the command line by substituting a command in it by the standard o
$ p1 p1_arg1 p1_arg2 `p2 p2_arg1 p2_arg2 p2_arg3 ...` p1_argx p1_argy p1_argz
The command
will be executed as an independent command and the standard output from it will replace the whole backquote
line. Then the modified command line will be executed.
is
x=10
y=20
z=`expr $x + $y`
+ expr 10 + 20
z=30
New Syntax
$ p1 p1_arg1 p1_arg2 $(p2 p2_arg1 p2_arg2 p2_arg3 ...) p1_argx p1_argy p1_argz
Pipes
$ p1 | p2
Pipe
0 stdin /dev/tty
2 stderr /dev/tty
1 stdout /dev/tty
2 stderr /dev/tty
The processes p1 and p2 will be run concurrently as child processes of the shell, with the standard output of p1
taking its standard input from that pipe.
$ p1 | p2 | p3 | p4 | p5
p1 will take its standard input from the terminal (keyboard). Standard output of p1 will be supplied as standard i
will be supplied as standard input to p3. Standard output of p3 will be supplied as standard input to p4. Standar
standard input to p5. Standard output of p5 will appear on the terminal (monitor). In a chain of commands, each
stage of text processing.
$ p1 >file1 2>file1
$ p1 >file1 2>&1
This means send standard error wherever File Descriptor 1 (standard output) is going.
First the standard output will be redirected to file1 and then the standard error will be redirected to wherever the
file1. Hence, both standard output and standard error will be redirected to file1.
0 stdin /dev/tty
Suppose, instead of
$ p1 >file1 2>&1
we run
$ p1 2>&1 >file1
0 stdin /dev/tty
2 stderr /dev/tty
First the standard error will be redirected to wherever the standard output is going, i.e. the terminal and then the
redirected to file1.
command1 | command2
Filters
A filter is a command that takes its input from standard input, processes it and produces the output on standard
that its input and output can be redirected independently and flexibly. Also, several filters can be chained in a p
^ An imaginary anchor at the beginning of line (only when ^ is at the beginning of the pattern)
$ An imaginary anchor at the end of line (only when $ is at the end of the pattern)
\ is the escape character - it removes the special meaning of the next character; also adds special meaning to s
circumstances as described below.
Character Classes
[a-z0-9] Any one character from between a and z, inclusive; or from between 0 an
[a-zA-Z0-9] Any one character from between a and z, inclusive; or from between A and Z, inclusive; or f
[a-z0-9ABCD] Any one character from between a and z, inclusive or from between 0 and 9, inclus
[^a-z0-9] Any one character other than those between a and z, inclusive and those betwe
[a-z^0-9] Any one character from between a and z, inclusive or ^ or from between betwee
\w equivalent to [a-zA-Z0-9]
\W equivalent to [^a-zA-Z0-9]
Word Matching
The input matches with the pattern \<pat1\> only if the input matches with pattern pat1 and is a w
\<pat1\>
word)
Repetition
{m} in a pattern means the previous element m times. {m,n} in a pattern means the previous element between
means the previous element m or more times.
Notes:
• The input abc will match with the pattern .{3} because the pattern .{3} is treated as equivalent to the pattern
• The pattern matchers are usually greedy; they try to match the given pattern or part of the pattern with the
input.
Alternation
pattern1 | pattern2 matches any input that matches with either pattern1 or pattern2
Any part of the search pattern enclosed between ( and ) is treated as a subexpression / group (considered to h
input that matches with a subexpression is remembered and can be referenced later as \n, where n is the sube
multiple subexpressions in your search pattern and they are numbered serially starting from 1, so \1 means the
subexpression, \2 means the input that matched with the second subexpression and so on).
Examples:
^\(.\)\(.\).\2\1$
Line containing only valid numbers (integers, floating point numbers in usual notation, numbers in scientific not
^[+-]\?[0-9]\+\(\.[0-9]*\)\?\([eE][-+]\?[0-9]\+\)\?$
Note: under GNU/Linux, the functionalities of all three commands have been combined into a single command
Commands List
• File System Handling
◦ pwd Displays the present working directory
◦ ls Displays list of files
▪ -a Display all files, including hidden ones and the implied . and .. directories
▪ -A Display all files, including hidden ones but excluding the implied . and .. directories
▪ -d When an argument is a directory, display the directory (default is to display the contents of the
▪ -h Display human-readable size (20M, 1.5G, etc.)
▪ -i Display the inode number also
▪ -l Display a long list
▪ -r Use reverse (descending) order while sorting
▪ -R Display the contents of the arguments recursively (in case of a directory, display the subdirecto
▪ -S Sort list on file size
▪ -t Sort list on modification time
▪ -X Sort list on filename extension
▪ -1 Single-line output, even on a terminal
▪ --color=always|never|auto Produce color output always/never/decide automatically based on the
◦ cat Output standard input / a file / concatenate multiple files and output
◦ cd Change directory
◦ pushd Push the current directory on the directory stack and change to the argument directory
◦ popd Pop a directory from the directory stack and change to that directory
◦ dirs Display the current directory stack
◦ mkdir Make one or more directories
◦ rmdir Remove one or more directories (must be empty)
◦ rm Remove file(s) (and directories)
▪ -r Remove file(s) and directories recursively
▪ -i Remove interactively (prompt before deleting each file/directory)
▪ -f Ignore non-existant files, never prompt
◦ cp Copy file(s)
▪ -r Copy file(s) and directories recursively
▪ -i Copy interactively (prompt before deleting each file/directory)
◦ mv Move/rename files and directories
▪ -i Move/rename files and directories interactively (prompt before deleting each file/directory)
▪ -f Move/rename forcefully, do not prompt before overwriting
◦ touch Set the last modification time stamp of the argument file to current date & time, create the argum
◦ chmod change the mode (permissions) of the file
▪ Symbolic syntax
▪ Numeric syntax
▪ Special permissions
▪ -R Change mode recursively
◦ chown Change the owner and/or group of files and directories
▪ Changing only the owner
▪ Changing both the owner and group
▪ Changing only the group
▪ -R Change the owner and/or group recursively
◦ chgrp Change the group of files and directories
▪ -R Change the group recursively
◦ umask Set the default file permissions mask
◦ ln Create a link (hard link by default, symbolic link with the -s option)
▪ -s Create a symbolic link
◦ mount Mount a file system onto a directory
▪ -t Specify the file system type
▪ -a Mount all file systems from /etc/fstab having the auto option
▪ -o Supply mount options (e.g. -o loop, -o rw)
▪ -r Mount read only
▪ -w Mount for read/write
◦ umount Unmount a file system
• Editing
◦ vim
• Process Management
◦ ps process Status; display a list of running processes (by default, only processes in the current sessio
▪ -a (all) processes belonging to the current user sessions except the session leaders (like the shel
process hierarchy for the session)
▪ -e (every) Displays all the interactive as well as non-interactive processes of all the users, includin
▪ -f (full) Show the full information including parent process id and the full command line
◦ kill Send a signal to another process
▪ -9 Send the kill signal to another process to kill it
• Basic Filters
◦ cut Extract one or more fields (columns) from input
▪ -c Specify column positions (for use with fixed-width input)
▪ -d Specify delimiter (for use with delimited input)
▪ -f Specify fields to be extracted (for use with delimited input)
◦ grep (egrep, fgrep)
▪ -E Enable extended regular expression
▪ -e Specify a pattern (used to specify multiple patterns)
▪ -F Use fixed strings (work like fgrep)
▪ -f Specify a file containing patterns, one per line
▪ -i Ignore case when matching patterns
▪ -c Output a count of matching lines
▪ -v Invert match, output lines other than those having a match for the pattern(s)
▪ -w word match, pattern must match with a whole word in the line
▪ -l Output only a list of files that have one or more matches
▪ -n Output line numbers along with matching lines
▪ -o Output only the matched (non-empty) parts of a matching line, with each such part on a separa
▪ --color=always|none|auto Produce color output always/never/decide automatically based on the
◦ pgrep Search processes based on name / command line arguments
▪ -a Display the full command line of the process that matched
▪ -f Match the full command line rather than just the process name
◦ wc Word Count; count the number of lines, words and characters in standard input or a file
▪ -l Output line count
▪ -w Output line count
▪ -c Output line count
◦ head Display the first few lines of a file or standard input (10 by default)
▪ -n number of lines from the beginning to be displayed
◦ tail Display the last few lines of a file or standard input (10 by default)
▪ -n number of lines from the end to be displayed
▪ -f continue to wait for further input even after reaching end of file; useful for watching a continuou
◦ paste "Join" files side-by-side
◦ sort Sort the input
▪ -k Specify key (starting column, ending column) on which to sort. In case of delimited input, spec
number, e.g. -k2,2. In case of fixed-width input, specify 1.starting character position and 1.ending
May be repeated for sorting on multiple keys
▪ -r sort in reverse (descending) order
▪ -t Specify the delimiter
▪ -d Sort as per dictionary (lexical) order (default)
▪ -f Fold lowercase to uppercase (ignore case while sorting)
▪ -n Sort numerically
▪ -h Sort numerically, human readable sizes (K, M, G, etc.)
◦ uniq Output unique or repeated lines (assumes the input is sorted)
▪ -c Prefix lines by a count of how many times the line is repeated
▪ -d Only output duplicated (repeated) lines
▪ -i ignore case
▪ -u Only output unique lines (default)
◦ tr Translate - convert or delete individual characters
▪ -s Squeeze - convert multiple consecutive occurrences of the given characters into a single occur
▪ -d Delete the given characters from the input
◦ tee Copy standard input to given file as well as to standard output to standard output
▪ -a append to file rather than overwrite
• Advanced Filters
◦ sed Stream editor. Used to edit a file programmatically (from script)
▪ -n Do not perform default output
▪ -f Specify sed script filename
▪ commands
▪ s Substitute
▪ i Insert line(s) before
▪ a Append line(s) after
▪ d delete line
▪ p print (output) line
◦ awk Powerful data manipulation program
▪ -f Specify awk script filename
▪ Built-in Variables
▪ ARGC Count of command line arguments
▪ ARGV Argument vector (array of command line arguments)
▪ ENVIRON Array of environment variables
▪ FILENAME Name of the current file
▪ FNR File Number of Record (line number of the current line in the current file)
▪ FS Field separator
▪ NF Number of fields in the current line
▪ NR Number of Record (a cumulative line number for all the lines from all the files processed
▪ OFS Output field separator (inserted between fields by print)
▪ Built-in Functions (Note: s/t → string, r → regular expression, n → number, i → index, a → array
▪ length(s) length of string s
▪ index(s, t) 1-based index of substring t in s, 0 if t is not found in s
▪ match(s, r) returns the 1-based index of the first longest match of regular expression r in s, 0
▪ split(s, a, r) Splits string s into fields using the separators in r (if omitted, default is white spa
as elements starting with index 1
▪ sub(r, s, t) Substitution. First match of r in t is replaced by s
▪ gsub(r, s, t) Global substitution. Every match of r in t is replaced by s
▪ substr(s, i, n) Return substring of s, starting at index i (1-based) and of length n. If n is omitt
i
▪ tolower(s) Converts s to lower case
▪ toupper(s) Converts s to upper case
▪ print(expr-list) Print (output) each argument separated by OFS
▪ printf(format, expr_list) Just like the printf function in the C programming language
▪ sprintf(format, expr-list) Just like printf, but instead of performing output, returns a string co
▪ atan2(y, x) Arctan of y/x between -pi and pi
▪ cos(x) Cosine of x (x in radians)
▪ exp(x) exponential of x
▪ int(x) integer portion of x, truncated towards 0
▪ log(x) natural logarithm of x
▪ rand() returns a random number between 0 and 1
▪ sin(x) Sine of x (x in radians)
▪ sqrt(x) square root of x
▪ getline var < filename opens the file if it is not already open and reads the next line from it in
reads into $0 and updates the fields and NF. If filename is omitted, the current file is used
▪ close(filename) closes the file
▪ system(cmd) runs the command cmd in a subshell and returns its exit status
• Other Commands
◦ bash run a child shell, If a file name is passed as an argument, interpret it as a shell script and exit fro
▪ -c run the command c in a child shell and exit from the child shell
◦ clear clear the screen
◦ more displays a file or standard input one page at a time. Press ENTER for next line, SPACE for next
supported with pipes), q to quit, /patternENTER search, n/N to search again in forward/backward direc
◦ less More powerful version of more, supports two-way scrolling with pipes as well
◦ echo outputs its arguments followed by a newline
▪ -n do not output a newline at the end
◦ read var1 var2 var3... reads a line, performs word-splitting and assigns each word to corresponding v
than the number of variables then the remaining variables remain unassigned. If there are more words
then one word is assigned to each variable except the last one; the last variable holds all remaining in
▪ -p display the argument as a prompt if the input comes from a terminal
▪ -s do not echo (display) the characters as they are read (useful for input of passwords)
◦ test test various conditions
▪ string tests
▪ -z str True of the string str is zero length (empty string)
▪ -n str True of the string str is non-zero length
▪ str1 = str2 True if str1 is equal to str2 (string comparison)
▪ str1 != str2 True if str1 is not equal to str2 (string comparison)
▪ integer tests
▪ no1 -gt no2 True if no1 is greater than no2
▪ no1 -ge no2 True if no1 is greater than or equal to no2
▪ no1 -lt no2 True if no1 is less than no2
▪ no1 -le no2 True if no1 is less than or equal to no2
▪ no1 -eq no2 True if no1 is equal to no2 (integer comparison)
▪ no1 -ne no2 True if no1 is not equal to no2 (integer comparison)
▪ file related tests
▪ -e file1 True if the file file1 exists
▪ -d file1 True if the file file1 exists and is a directory
▪ -f file1 True if the file file1 exists and is a regular file
▪ -r file1 True if the file file1 exists and is readable for the current user
▪ -w file1 True if the file file1 exists and is writable for the current user
▪ -x file1 True if the file file1 exists and is executable for the current user
▪ -s file1 True if the file file1 exists and has a size greater than zero
◦ expr evaluate expressions
▪ arithmetic expressions expr
▪ string expressions String Operations
◦ bc arbitrary precision integer and floating arithmetic tool
◦ printf Works just like the printf() function in the C programming language. As it is a command, its
printf format-string arg1 arg2 arg3 ...
◦ man show the manual page for the argument from the first section in which it exists
▪ -a show manual pages for the argument from all the sections in which it exists one after another
◦ info more detailed on line manual (Linux only)
◦ whatis Only display the heading of the manual page for the argument
◦ apropos Search the headings of all manual pages for the given arguments and display the matching h
command when one doesn't know the command name)
◦ which display the executable corresponding to a command by searching PATH (e.g. which ls outputs
commands
◦ type displays from where a command will be run by the shell, works for both internal and external com
◦ file Guess the type of content in a file by looking at some initial portion of the file content
◦ comm display lines that are common to two files and lines that are not (files are assumed to be sorted
▪ -1 do not display the first column (lines unique to the first file)
▪ -2 do not display the second column (lines unique to the second file)
▪ -3 do not display the third column (lines common to both the files)
▪ --check-order check that the input is correctly sorted
▪ --nocheck-order do not check that the input is correctly sorted
◦ diff compare two files and output differences between them
▪ -i ignore case while comparing
▪ -e produce output compatible with the ed editor
◦ patch apply a diff patch to the original file to convert it to the modified file (note: the original file is mod
◦ join join two files based on some common field(s), like a join in a relational database
▪ -a print unpairable lines from file filenum (an argument, must be 1 or 2)
▪ -e replace missing input fields with empty strings
▪ -i ignore case when comparing fields for join condition
▪ -t specify field separators
▪ -1 specify the field number of the join field in the first file
▪ -2 specify the field number of the join field in the second file
◦ who display a list of currently logged-in users
▪ -a display all information about currently logged-in users
▪ am i display information about who is the logged-in user in the current session
◦ whoami display only the name of who is the logged-in user in the current session
◦ date get/set the system date in a variety of formats, convert dates between formats, extract componen
▪ -d Use the given date instead of the system date
▪ -s set the system date
▪ formats
▪ %a abbreviated week name (Sun..Sat)
▪ %A full week name (Sunday..Saturday)
▪ %b abbreviated month name (Jan..Dec)
▪ %B full month name (January..December)
▪ %d day of the month (01..31)
▪ %Y Year in four digits
▪ %H hour in 24-hour format (00..23)
▪ %I hour in 12-hour format (01..12)
▪ %m month number (01..12)
▪ %M minute (00..59)
▪ %p AM/PM as applicable
▪ %P am/pm as applicable
▪ %s number of seconds since 1970-01-01 00:00:00 UTC
▪ %S seconds (00..60)
▪ %u day of the week as a number (1..7, 1 is Monday)
◦ cal Display the calender of the given month and year (year must be 4-digit)
◦ find find files in the given directory recursively matching given criteria
▪ Predicates
▪ -name fname match filename with fname
▪ -iname fname match filename with fname, case insensitive
▪ -path p match a part of the file's path, including filename with p
▪ -type t match files having type t, t may be f for regular file, d for directory
▪ Numeric arguments
▪ n means exactly equal to n
▪ +n means >= n
▪ -n means <= n
▪ -mmin n files modified n minutes ago
▪ -mtime n files modified n days ago
▪ -empty match empty (zero-length) files
▪ -size n match files having size n. Suffixes like c (bytes), k (KiB), M (MiB), G (GiB) can be use
▪ -user u match the file's owner with u
▪ -group g match the file's group with g
▪ -readable match files on which the current user has read permission
▪ -writable match files on which the current user has write permission
▪ -executable match files on which the current user has execute permission
▪ -perm p files having symbolic or numeric permissions p
▪ actions
▪ -delete delete the matching file
▪ -exec execute the given command on the matching file (must be terminated with \;)
▪ -ok same as -exec, but prompt for confirmation before executing the command
▪ -print display the filename with path (default action)
▪ Operators
▪ -a and
▪ -o or
▪ ! not
▪ () Brackets can be used for grouping
◦ tty display the filename of the current terminal
◦ tar tape archiver. Combines several files into a single archive file (but does not compress it by default)
▪ -c create an archive
▪ -x extract from the archive
▪ -t list from the archive
▪ -f specify the filename of the archive
▪ -v verbose mode, display each file as it is processed
▪ -z compress/uncompress the file using the zip algorithm
◦ gzip replace each file by its compressed version (using the zip algorithm) and add extension .gz, can
◦ gunzip replace each file by its uncompressed version (using the zip algorithm) and remove extension
individual files
◦ dd Disk Dump. Used to read/write storage devices directly. Can be used to create and restore disk im
◦ eval The arguments are executed by the shell as a single command and its exit status is returned. Us
generated shell commands
◦ df show free disk space on all mounted file systems. By default usage is shown in terms of 1024 byte
▪ -h show human readable figures (200M, 2.3G, etc.)
◦ du show the amount of disk space used by the argument files/directories. In case of directories, show
and its contents (calculated recursively). By default usage is shown in terms of 1024 byte blocks
▪ -s show only summary (total) for each argument
▪ -h show human readable figures (200M, 2.3G, etc.).
◦ hd Hex Dump. Used to view the contents of binary files
◦ hostname Output the name of the computer system
◦ uname Output system information
◦ sudo Execute the given command as a superuser. The currently logged-in user must have administra
current user's password for the first time, remembers the authorization for 15 minutes or until the sess
▪ -k Forget authorization, will prompt for password next time sudo is executed
▪ -s Run a shell with administrative privileges
◦ gksudo Run a graphical program with administrative privileges (e.g. gksudo nautilus /)