Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

linux commands

Linux is an operating system that manages computer hardware and provides a standard interface for applications, making them more efficient and reliable. It is a cross-platform, free operating system that allows users to modify its source code, which contributes to its rapid development and improvement. Linux has a rich history rooted in Unix and has evolved to offer superior performance, compatibility, and user satisfaction compared to other operating systems like Windows and Solaris.

Uploaded by

nagendraduhan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

linux commands

Linux is an operating system that manages computer hardware and provides a standard interface for applications, making them more efficient and reliable. It is a cross-platform, free operating system that allows users to modify its source code, which contributes to its rapid development and improvement. Linux has a rich history rooted in Unix and has evolved to offer superior performance, compatibility, and user satisfaction compared to other operating systems like Windows and Solaris.

Uploaded by

nagendraduhan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 55

What is Linux?

Linux is an operating system, a software program that controls your computer. Most vendors load an
operating system onto the hard drive of a PC before delivering the PC, so, unless the hard drive of your
PC has failed, you may not understand the function of an operating system.

An operating system solves several problems arising from hardware variation. As you're aware, no two
PC models (or models of other computers, for that matter) have identical hardware. For example, some
PCs have an IDE hard drive, whereas others have a SCSI hard drive. Some PCs have one hard drive,
others have two or more. Most PCs have a CD-ROM drive, but some do not. Some PCs have an Intel
Pentium CPU, whereas others have an AMD K-6, and so on. Suppose that, in a world without operating
systems, you're programming a new PC application, perhaps a new multimedia word processor. Your
application must cope with all the possible variations of PC hardware. As a result, it becomes bulky and
complex. Users don't like it because it consumes too much hard drive space, takes a long time to load,
and - because of its size and complexity - has more bugs than it should.

Operating systems solve this problem by providing a single standard way for applications to access
hardware devices. When an operating system exists, applications can be more compact, because they
share the commonly used code for accessing the hardware. Applications can also be more reliable
because this code is written only once, and by expert programmers, rather than by every application
programmers.

As you'll soon learn, operating systems do many other things as well; for example, they generally provide
a filesystem so that you can store and retrieve data, and a user interface so that you can control the
operation of your computer. However, if you think of a computer's operating system as its subconscious
mind, you won't be far off the mark. It's the computer's conscious mind - applications such as word
processors and spreadsheets - that do useful work. But, without the subconscious - the operating
system - the computer would cease breathing and applications would not function.

Linux is distinguished from many popular operating systems in three important ways.

 Linux is a cross-platform operating system that runs on many computer models. Only Unix, an
ancestor of Linux, rivals Linux in this respect. In comparison, Windows 95 and Windows 98 run
only on CPUs having the Intel architecture. Windows NT runs only on CPUs having the Intel
architecture or the DEC Alpha.

 Linux is free, in two senses. First, you may pay nothing to obtain and use Linux. On the other
hand, you may choose to purchase Linux from a vendor who bundles Linux with special
documentation or applications, or who provides technical support. However, even in this case, the
cost of Linux is likely to be a fraction of what you'd pay for another operating system. So, Linux is
free or nearly free in an economic sense.

Second, and more important, Linux and many Linux applications are distributed in source form.
This makes it possible for you and others to modify or improve them. You're not free to do this
with most operating systems, which are distributed in binary form. For example, you can't make
changes to Microsoft Windows or Microsoft Word - only Microsoft can do that. Because of this
freedom, Linux is being constantly improved and updated, far outpacing the rate of progress of
any other operating system. For example, Linux will likely be the first operating system to support
Intel's forthcoming Merced 64-bit CPU.

 Linux has attractive features and performance. Free access to Linux source code lets
programmers around the world implement new features, and tweak Linux to improve its
performance and reliability. The best of these features and tweaks are incorporated in the
standard Linux kernel or made available as kernel patches or applications. Not even Microsoft
can mobilize and support a software development team as large and dedicated as the volunteer
Linux software development team, which numbers in the hundreds of thousands, including
programmers, code reviewers, and testers.

1.2.2.1 The origins of Linux

Linux traces its ancestry back to a mainframe operating system known as Multics (Multiplexed Information
and Computing Service). Begun in 1965, Multics was one of the first multi-user computer systems and
remains in use today. Bell Telephone Labs participated in the development of Multics, along with the
Massachusetts Institute of Technology and General Electric.

Two Bell Labs software engineers, Ken Thompson and Dennis Richie, worked on Multics until Bell Labs
withdrew from the project in 1969. One of their favorite pastimes during the project had been playing a
multi-user game called Space Travel. Now, without access to a Multics computer, they found themselves
unable to indulge their fantasies of flying around the galaxy. Resolved to remedy this, they decided to port
the Space Travel game to run on an otherwise unused PDP-7 computer. Eventually, they implemented a
rudimentary operating system they named Unics, as a pun on Multics. Somehow, the spelling of the name
became Unix.

Their operating system was novel in several respects, most notably portability. Most previous operating
systems had been written for a specific target computer. Just as a tailor-made suit fits only its owner, such
an operating system could not be easily adapted to run on an unfamiliar computer. In order to create a
portable operating system, Ritchie and Thompson first created a programming language, called C. Like
assembly language, C let a programmer access low-level hardware facilities not available to
programmers writing in a high-level language such as FORTRAN or COBOL. But, like FORTRAN and
COBOL, a C program was not bound to a particular computer. Just as a ready-made suit can be
lengthened or shortened here and there to fit a purchaser, writing Unix in C made it possible to easily
adapt Unix to run on computers other than the PDP-7.

As word of their work spread and interest grew, Ritchie and Thompson made copies of Unix freely
available to programmers around the world. These programmers revised and improved Unix, sending
word of their changes back to Ritchie and Thompson, who incorporated the best such changes in their
version of Unix. Eventually, several Unix variants arose. Prominent among these was BSD (Berkeley
Systems Division) Unix, written at the University of California, Berkeley, in 1978. Bill Joy, one of the
principals of the BSD project, later became a founder of Sun Microsystems, which sold another Unix
variant (SunOS) to power its workstations. In 1984, AT&T, the parent company of Bell Labs, began selling
its own version of Unix, known as System V.

1.2.2.2 Free software

What Ritchie and Thompson had begun in a distinctly non-commercial fashion ended up spawning
several legal squabbles. When AT&T grasped the commercial potential of Unix, it claimed Unix as its
intellectual property and began charging a hefty license fee to those who wanted to use its Unix. Soon,
others who had implemented Unix-like operating systems were distributing licenses only for a fee.
Understandably, those who had contributed improvements to Unix considered it unfair for AT&T and
others to appropriate the fruits of their labors. This concern for profit was unlike the democratic, share-
and-share-alike spirit of the early days of Unix.

Some, including MIT scientist Richard Stallman, yearned for the return of those happier times and the
mutual cooperation of programmers that then existed. So, in 1983, Stallman launched the GNU (GNU's
not Unix) project, which aimed at creating a free Unix-like operating system. Like early Unix, the GNU
operating system was to be distributed in source form so that programmers could read, modify, and
redistribute it without restriction. Stallman's work at MIT had taught him that, by using the Internet as a
means of communication, programmers the world over could improve and adapt software at incredible
speed, far outpacing the fastest rate possible using traditional software development models, in which few
programmers actually see one another's source code.

As a means of organizing work on the GNU project, Stallman and others created the Free Software
Foundation (FSF), a non-profit corporation that seeks to promote free software and eliminate restrictions
on the copying, redistribution, understanding, and modification of software. Among other activities, the
FSF accepts tax-deductible charitable contributions and distributes copies of software and documentation
for a small fee, using this revenue to fund its operations and support the GNU project.

If you find it peculiar that the FSF charges a fee - even a small fee - for "free" software, you should
understand that the FSF intends the word free to refer primarily to freedom, not price. The FSF believes in
three fundamental software freedoms:

 You can copy GNU software and give it away to anyone you choose.

 If you're a programmer, you can modify GNU software any way you like, because you have
access to the source code.

 You can distribute improved versions of GNU software. However, you cannot charge anyone a
fee for using your improved version (although you can charge a fee for providing a user with a
physical copy of your software).

Linux Features and Performance

The origins of Linux and the availability of its source code set it apart from other operating systems. But
most users choose an operating system based on features and performance - and Linux delivers these in
spades. Table 1.4compares certain features and performance characteristics of Linux with those of
Microsoft Windows NT 4.0 and Sun Microsystems Solaris 2.6.[ 5] Each of these three operating systems
can be run on an Intel-architecture PC.

[5] Source: Adapted from SunWorld, August 1998.

Table 1.4: Linux Features and Performance Comparison

Characteristic Linux Windows NT Solaris


Range of compatible hardware Very wide Modest Narrow
Minimal hardware 386 PC 486 PC Pentium
Representative cost of hardware $200 $1300 $1600
Average downtime Very low As low as 30 min./week Very low
Performance High Comparable to Linux Half of Linux to same as Linux
Multi-processing capabilities Excellent Modest Excellent
IP Security (IPSec) Yes Planned 1999
IPv6 Available Privately demonstrated Beta
Overall user satisfaction, per Datapro Highest Lowest Medium
Source code readily available Yes No No
Table 1.4: Linux Features and Performance Comparison

Characteristic Linux Windows NT Solaris


Installed base Millions Millions Hundreds of thousands

As you can see, Linux fares well in this comparison. It runs on a wider range of hardware platforms and
runs adequately on less costly and powerful systems. Moreover, the typical downtime of a Linux system is
less than that of a Windows NT system and its performance surpasses that of a Solaris system. Its multi-
processing capabilities exceed those of Windows NT and its support of advanced TCP/IP networking
facilities is superior to that of Windows NT and Solaris. As a group, Linux users are more satisfied than
Windows NT users and Solaris users. Linux source code is readily available. And, the Linux installed
base dwarfs that of Solaris and approaches that of Windows NT.

But this impressive inventory of selling points doesn't end the matter. Let's consider some other technical
characteristics of Linux that distinguish it from the pack. Foremost in the minds of many is the low cost of
Linux. Comparable server operating systems can cost more than $100,000. The low cost of Linux makes
it practical for use even as a desktop operating system. In that mode, it truly eclipses the competition.

Many desktop systems are occasionally, even regularly, employed as servers. Because Linux was
designed for use as a server operating system, its features and performance readily outshine those of
desktop operating systems used as makeshift servers. For example, Microsoft's software license for
Windows NT Workstation restricts the number of simultaneous client connections to 10; if your Windows
NT Workstation computer accepts more than 10 client connections, it is operating in breach of license.
However, Linux imposes no such restriction: your Linux desktop is free to accept as many client
connections as you think it can handle.

Again, because it was designed as a server, Linux provides more reliable data storage than competing
desktop operating systems. Most Linux users store their disk data using the EXT2 filesystem, which is
superior in performance and reliability to filesystems (partition types) provided by Microsoft operating
systems, including FAT, FAT32, and NTFS.

Issuing Linux Commands


4.1 The System Use Cycle

This section introduces you to the cycle of Linux system use. If you're a user of Microsoft Windows, you're
accustomed to a pattern of system use that forms a cycle:

 Boot the system

 Identify yourself to the system

 Use the system

 Shutdown the system

The cycle of Linux system use is similar, even though you perform the tasks somewhat differently.
4.1.1 Booting the System

Most Linux users boot their system from its hard drive. Of course, if you made a boot diskette during
system installation, you can use it to boot your system.

First, you must prepare your system for booting. If your system is running, you must shut it down by
following the proper procedure for shutting down the operating system that's active. For example, if you're
running Microsoft Windows, click Start Shut Down and select the Shut Down option in the Shut Down
dialog box. Press OK to begin the system shutdown. After a few seconds, Windows displays a screen
telling you that it's safe to turn off power to your system. Turn off the power or, if your system
automatically powers down, wait a few seconds until the system powers itself down.

Next, you must set your system to boot from the desired device. To boot your system from its hard drive,
remove any floppy diskette from your system's floppy drive. To boot your system from a floppy diskette,
insert your Linux boot diskette into your system's floppy drive.

Now, you're ready to boot your system. Switch your system on (or press your system's reset button, if
your system is powered on) and watch as it performs its self test. Shortly thereafter, you should see
a boot: prompt on the system's monitor. If you like, you can list the available boot configurations stored on
the boot device by pressing Tab. To boot the system, type the name of the desired configuration and
press Enter, or simply press Enter to boot using the default configuration.

Once it loads, Linux begins probing your system and its devices, printing status information on your
system's monitor. This status information is helpful if your system fails to boot properly, because it
discloses the point in the boot process where the problem occurred.

When Linux has completed its boot process, your system's monitor will display a login prompt similar to
this:

Debian GNU/Linux 2.1 desktop tty1


desktop login:

4.1.2 Logging In

Before you can use the system, you must identify yourself by logging in. The install program created a
special user named root; by identifying yourself as the root user, you can gain access to the system.
Normally, you use the rootuserid only when performing system administration tasks, because
the root user has special capabilities that other users lack.

To log on, type root and press Enter. The system prompts you for the password associated with
the root userid. Type the password you established during the installation process and press Enter. To
prevent anyone nearby from learning your password, Linux does not display it as you type. If you suspect
you've typed it incorrectly, simply press Enter and start over; or press Backspace once (or more) for
each character you've entered and then re-enter it. If you type the userid or password incorrectly, Linux
displays the message "login incorrect" and prompts you to try again.

Like other members of the Unix family, the Linux operating system is case sensitive. Be sure to type the
userid root just as it appears, using all lowercase characters. Similarly, you must type the password
exactly as you entered it in the Root Password dialog box during system installation.

Also, some Linux programs require you to type Ctrl-BACKSPACE, rather than BACKSPACE. If you press
BACKSPACE and see ^H echoed to the console, try pressing Ctrl-BACKSPACE instead.
When you've successfully logged in, you'll see a command prompt that looks something like this:

root@desktop:/root#

This prompt tells you that the Linux bash shell is ready to accept your commands.

4.1.3 Issuing Commands

The component of Linux that interprets and executes commands is called the shell. Linux supports a
variety of different shells, but the most popular is the bash shell. This chapter presents the basics of using
the bash shell; you'll learn more about the shell in Chapter 13, Conquering the BASH Shell.

The Linux bash shell presents the user with a command-line interface (CLI). CLIs are familiar to Windows
users who have worked in the MS-DOS Prompt window, and indeed the Microsoft Windows MS-DOS
Prompt window is a kind of command-line shell for Windows. The Linux bash shell works much like the
MS-DOS Prompt window. You type text commands and the system responds by displaying text replies.
As your first Linux command, type w and press Enter. Your screen should look something like this:

root@desktop:/root#

w
11:12am up 6 min, 1 user, load average: 0.00, 0.08, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 11:13am 0.00s 0.20s 0.11s -bash

The w command tells Linux to display the system status and a list of all system users. In the example, the
output of the command tells you that it's now 11:12 a.m., that the system has been up for 6 minutes, and
that only one user -root - is currently logged in. Notice that the command output is very terse, packing
much information into a few lines. Such output is typical of Linux commands. At first, you may find Linux
output cryptic and difficult to read, but over time you'll grow to appreciate the efficiency with which Linux
communicates information.

Linux provides many commands besides the w command; so many that you may despair of learning and
recalling them. Actually, the number of commands you'll use regularly is fairly small. Soon, these will
become second nature to you.

Now try a second command, the date command:

root@desktop:/root#

date
Tue Feb 23 11:15:20 PST 1999

The date command displays the current date and time.

If you find working with MS-DOS distasteful or intimidating, you may not immediately enjoy working with
the Linux command line. However, give yourself some time to adjust. The Linux command line has
several features that make it easier to use, and more powerful, than MS-DOS. If, after working with the
Linux command line for several days, you don't find yourself at home, don't despair. Linux provides a
graphical user interface in addition to its command-line interface. You'll learn about the graphical user
interface in Chapter 6, Using the X Window System.
4.1.4 Correcting Commands

Sometimes you may type a command incorrectly, causing Linux to display an error message. For
example, suppose you typed dat instead of date:

root@desktop:/root#

dat
bash: dat: command not found

In such a case, carefully check the spelling of the command and try again. If you notice an error before
pressing Enter, you can use the Backspace key to return to the point of the error and then type the
correct characters.

Just as a web browser keeps track of recently visited sites, Linux's BASH shell keeps track of recently
issued commands. This list is called the history list, and you can scroll back through it using the Up arrow
key, or back down using the Down arrow key, just as you would with the Back and Forward buttons on a
web browser. In fact, the history list provides several powerful ways to remember and reuse frequently
issued commands, as we'll see inChapter 13.

The Up and Down arrow keys let you scroll through a list of commands recently issued. This feature is
handy when you want to repeat a command. Simply use the Up arrow key to find the command and
press Enter to re-execute it. You can also use this feature when you want to issue a command similar to
one you recently issued. Use the Up arrow key to find the original command. Then, use the Left and Right
arrow keys to position the cursor and make whatever changes to the command you like. Finally,
press Enter to execute the command.

4.1.5 Using Virtual Consoles

In Microsoft Windows, you can have several MS-DOS Prompt windows simultaneously active. Although
the bash shell doesn't have a graphical user interface, you can nevertheless work with several instances
of the shell, by using Linux virtual consoles. Linux provides six virtual consoles; you can use special
keystrokes to switch between them. The keystroke Alt-F n, where n is the number of a virtual console (1-
6), causes Linux to display virtual console n. For example, you can display virtual console 2 by typing Alt-
F2. You can view only a single console at a time, but you can switch rapidly between consoles by using
the appropriate keystroke.

Virtual consoles are handy when you've started a time-consuming task and want to be able to perform an
unrelated task while the original task is working. You'll also find them useful after you've established
several userids on your system, because you can log on as one userid on one virtual console while you're
logged on as another userid on a different console.

Virtual consoles have a screen saver feature like that found on Microsoft Windows. If a virtual console is
inactive for an extended period, Linux blanks the monitor screen. To restore the screen without disturbing
its contents, press the Shift key.

4.1.6 Logging Out

When you're done using a virtual console, you should log out by typing the command exit and
pressing Enter. When you log out, the system frees memory and other resources that were allocated
when you logged in, making those resources available to other users.
When the system logs you out, it immediately displays a login prompt. If you change your mind and want
to access the system, you can login simply by supplying your userid and password.

4.1.7 Shutting Down the System

You shouldn't turn off power to a computer while it's running Linux; instead, you should shut down the
operating system and then turn off power. To shut down a Linux system, you use
the shutdown command, which resides in a directory named /sbin:

root@desktop:/root#

/sbin/shutdown -h now

Don't type the prompt, which automatically appears on the command line. Only the root user can issue
the shutdown command. If you want to restart a Linux system, you can use an alternative form of
the shutdown command:

root@desktop:/root#

/sbin/shutdown -r now

Or, even more conveniently, you can use the familiar MS-DOS "three-finger salute": Ctrl-Alt-Del, which
simply issues a shutdown command on your behalf.

When you shut down a system, Linux automatically logs off all users, terminates all running programs,
and closes all open files. Before shutting down a system, you should check each virtual console to
determine if an important operation is in progress. If so, you should delay shutting the system down until
the operation completes.

Working with the Linux Command Prompt

To make Linux commands easy to use, they share a simple, common structure. This section describes
their common structure and explains how you can obtain helpful information on the commands available
to you.

4.2.1 Command Structure

Linux commands share the common form:

command option(s) argument(s)

The command identifies the command you want Linux to execute. The name of a Linux command almost
always consists of lowercase letters and digits. Remember that, unlike Microsoft Windows, Linux is case
sensitive; be sure to type each character of a command in the proper case.

Most commands let you specify options or arguments. However, in any given case, you may not need to
do so. For example, typing the w command without options and arguments causes Linux to display a list
of current users.
Options modify the way that a command works. Most options consist of a single letter, prefixed by a dash.
Often, you can specify more than one option; when you do so, you separate each option with a space or
tab. For example, the -h option of the w command causes the output of the command to omit the header
lines that give the time and the names of the fields. Typing:

root@desktop:/root#

w -h

prints a list of users without the header lines.

Arguments specify filenames or other targets that direct the action of the command. For example,
the w command lets you specify a userid as an argument, which causes the command to list only logins
that pertain to the specified userid. Typing:

root@desktop:/root#

w root

prints a list of current logins by the root user. Some commands let you specify a series of arguments; you
must separate each argument with a space or tab.

4.2.2 Getting Help

Because Linux provides so many commands and because Linux commands provide so many possible
options, you can't expect to recall all of them. To help you, Linux provides the man command and
the apropos command, which let you access a help database that describes each command and its
options.

4.2.2.1 Using man

Each Linux command is described by a special file called a manual page. The manual pages are stored in
a group of subdirectories comprising a help database. To access this database, you use
the man command, which resembles the MS-DOS help command. For example, to get help on using
the w command, type:

root@desktop:/root#

man w

Figure 4.1 shows the resulting output, which the command displays one page at a time. Notice the colon
prompt, which appears at the bottom left of the screen. To page forward, press the Space key; to page
backward, press the bkey. To exit the man program, press the q key.

The manual pages are organized according to a common format. At the beginning of a manual page,
you'll find the name of the page and the section of the manual page database from which the page
comes, shown in parentheses. For example, the figure shows the manual page named w, which comes
from section 1 of the manual page database. Table 4.1 describes the sections of the manual page
database; most sections are primarily of interest to programmers. As a user and administrator, you'll be
interested primarily in sections 1 and 8.
Table 4.1: Manual Page Sections

Section Description
1 Executable programs and shell commands
2 System calls (provided by the kernel)
3 Library calls (provided by system libraries)
4 Special files (for example, device files)
5 File formats and conventions
6 Games
7 Macro packages and conventions
8 System administration commands
9 Non-standard kernel routines

Figure 4.1: A typical man page

Next in the output comes the name and brief description of the command. Then comes a synopsis of the
command, which shows the options and arguments that you can specify. Brackets enclose parts of a
command that you can choose to include or omit. Next comes a detailed description of the operation of
the command, followed by a description of its options.

As you're learning your way around Linux, you may find it convenient to reserve a virtual console for
running the man command. That way, you can enter commands in a separate virtual console, switching
between consoles to refresh your recollection of the options and arguments of commands as you type
them.

4.2.2.2 Using apropos

The man command searches the manual pages and displays detailed information about a specified
command. The apropos command also searches the manual pages; however, it displays summary
information about manual pages that contain a specified keyword. (The search is limited to the short
description that appears at the beginning of each manual page). For example, typing the command:

root@desktop:/root#
apropos files

Commands
Terminal
CLI preceded GUI as a computer interface. Since GUIs are common now, why should we still care about
CLI? Some advantages of using the command line are:
1. It can save you time.
2. It can help when you are unable to use the GUI, such as a system crash or a configuration issue.
3. It can enable you to use Linux in ways that using a GUI exclusively can not (such as scripting
repetitive tasks).
For example, you have been called by the systems administrator that you have used too much space.
You want to quickly work out where the most space is used, so using a graphical interface, start your
timer - go. Now, go to a command line and type: du | sort -n (we will describe more later). See? It is faster
to do some things on the command line (and other times, easier for graphical).

How to invoke it
Methods of launching a CLI can vary by desktop environment:

Unity (Ubuntu 11.04)

Dash -> Search for Terminal


Dash -> More Apps -> 'See More Results' -> Terminal
Dash -> More Apps -> Accessories -> Terminal

Shell

The shell is a program that takes commands from the keyboard and gives them to the operating system
to perform. In the old days, it was the only user interface available on a Unix-like system such as Linux.
Nowadays, we have graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) such
as the shell.

On most Linux systems a program called bash (which stands for Bourne Again SHell, an enhanced
version of the original Unix shell program, sh, written by Steve Bourne) acts as the shell program.
Besides bash, there are other shell programs that can be installed in a Linux system. These
include: ksh, tcsh and zsh.

What's a "Terminal?"

It's a program called a terminal emulator. This is a program that opens a window and lets you interact with
the shell. There are a bunch of different terminal emulators you can use. Most Linux distributions supply
several, such as: gnome-terminal, konsole, xterm, rxvt, kvt, nxterm, and eterm.

Starting A Terminal
Your window manager probably has a way to launch a terminal from the menu. Look through the list of
programs to see if anything looks like a terminal emulator. If you are a KDE user, the terminal program is
called "konsole," in Gnome it's called "gnome-terminal." You can start up as many of these as you want
and play with them. While there are a number of different terminal emulators, they all do the same thing.
They give you access to a shell session. You will probably develop a preference for one, based on the
different bells and whistles each one provides.

cat

cat [OPTION] [FILE]...

1. Display Contains of File

In the below example, it will show contains of /etc/passwd file.

# cat /etc/passwd

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
narad:x:500:500::/home/narad:/bin/bash

2. View Contains of Multiple Files in terminal

In below example, it will display contains of test and test1 file in terminal.

# cat test test1

Hello everybody
Hi world,

3. Create a File with Cat Command

We will create a file called test2 file with below command.

# cat >test2

Awaits input from user, type desired text and press CTRL+D (hold down Ctrl Key and type ‘d‘) to exit. The text will be

written in test2 file. You can see contains of file with following cat command.

# cat test2

hello everyone, how do you do?


4. Use Cat Command with More & Less Options

If file having large number of contains that won’t fit in output terminal and screen scrolls up very fast, we can use

parameters more and less with cat command as show above.

# cat song.txt | more


# cat song.txt | less

5. Display Line Numbers in File

With -n option you could see the line numbers of a file song.txt in the output terminal.

# cat -n song.txt

1 "Heal The World"


2 There's A Place In
3 Your Heart
4 And I Know That It Is Love
5 And This Place Could
6 Be Much
7 Brighter Than Tomorrow
8 And If You Really Try
9 You'll Find There's No Need
10 To Cry
11 In This Place You'll Feel
12 There's No Hurt Or Sorrow

6. Display $ at the End of File

In the below, you can see with -e option that ‘$‘ is shows at the end of line and also in space showing ‘$‘ if there is

any gap between paragraphs. This options is useful to squeeze multiple lines in a single line.

# cat -e test

hello everyone, how do you do?$


$
Hey, am fine.$
How's your training going on?$
$

7. Display Tab separated Lines in File

In the below output, we could see TAB space is filled up with ‘^I‘ character.
# cat -T test

hello ^Ieveryone, how do you do?

Hey, ^Iam fine.


^I^IHow's your training ^Igoing on?
Let's do ^Isome practice in Linux.

8. Display Multiple Files at Once

In the below example we have three files test, test1 and test2 and able to view the contains of those file as shown

above. We need to separate each file with ; (semi colon).

# cat test; cat test1; cat test2

This is test file


This is test1 file.
This is test2 file.

9. Use Standard Output with Redirection Operator

We can redirect standard output of a file into a new file else existing file with ‘>‘ (greater than) symbol. Careful,

existing contains of test1 will be overwritten by contains of test file.

# cat test > test1

10. Appending Standard Output with Redirection Operator

Appends in existing file with ‘>>‘ (double greater than) symbol. Here, contains of test file will be appended at the end

of test1 file.

# cat test >> test1

11. Redirecting Standard Input with Redirection Operator

When you use the redirect with standard input ‘<‘ (less than symbol), it use file name test2 as a input for a command

and output will be shown in a terminal.

# cat < test2

This is test2 file.


12. Redirecting Multiple Files Contain in a Single File

This will create a file called test3 and all output will be redirected in a newly created file.

# cat test test1 test2 > test3

13. Sorting Contains of Multiple Files in a Single File

This will create a file test4 and output of cat command is piped to sort and result will be redirected in a newly created

file.

# cat test test1 test2 test3 | sort > test4

ls

List Files using ls with no option

ls with no option list files and directories in bare format where we won’t be able to view details like file types, size,

modified date and time, permission and links etc.

# ls

0001.pcap Desktop Downloads index.html install.log.syslog Pictures Templates


anaconda-ks.cfg Documents fbcmd_update.php install.log Music Public Videos

2 List Files With option –l

Here, ls -l (-l is character not one) shows file or directory, size, modified date and time, file or folder name and owner

of file and it’s permission.

# ls -l

total 176
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap
-rw-------. 1 root root 1586 Jul 31 02:17 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Desktop
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Documents
drwxr-xr-x. 4 root root 4096 Aug 16 02:55 Downloads
-rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php
-rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html
-rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log
-rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Music
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Pictures
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Public
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Templates
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Videos

3. View Hidden Files

List all files including hidden file starting with ‘.‘.

# ls -a

. .bashrc Documents .gconfd install.log .nautilus .pulse-cookie


.. .cache Downloads .gnome2 install.log.syslog .netstat.swp .recently-used.xbel
0001.pcap .config .elinks .gnome2_private .kde .opera .spice-vdagent
anaconda-ks.cfg .cshrc .esd_auth .gtk-bookmarks .libreoffice Pictures .tcshrc
.bash_history .dbus .fbcmd .gvfs .local .pki Templates
.bash_logout Desktop fbcmd_update.php .ICEauthority .mozilla Public Videos
.bash_profile .digrc .gconf index.html Music .pulse .wireshark

List Files with Human Readable Format with option -lh

With combination of -lh option, shows sizes in human readable format.

# ls -lh

total 176K
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap
-rw-------. 1 root root 1.6K Jul 31 02:17 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Desktop
drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Documents
drwxr-xr-x. 4 root root 4.0K Aug 16 02:55 Downloads
-rw-r--r--. 1 root root 21K Aug 12 12:42 fbcmd_update.php
-rw-r--r--. 1 root root 46K Jul 31 09:58 index.html
-rw-r--r--. 1 root root 48K Jul 31 02:17 install.log
-rw-r--r--. 1 root root 12K Jul 31 02:13 install.log.syslog
drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Music
drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Pictures
drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Public
drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Templates
drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Videos
5. List Files and Directories with ‘/’ Character at the end

Using -F option with ls command, will add the ‘/’ Character at the end each directory.

# ls -F

0001.pcap Desktop/ Downloads/ index.html install.log.syslog Pictures/ Templates/


anaconda-ks.cfg Documents/ fbcmd_update.php install.log Music/ Public/ Videos/

6. List Files in Reverse Order

The following command with ls -r option display files and directories in reverse order.

# ls -r

Videos Public Music install.log fbcmd_update.php Documents anaconda-ks.cfg


Templates Pictures install.log.syslog index.html Downloads Desktop 0001.pcap

7. Recursively list Sub-Directories

ls -R option will list very long listing directory trees. See an example of output of the command.

# ls -R

total 1384
-rw-------. 1 root root 33408 Aug 8 17:25 anaconda.log
-rw-------. 1 root root 30508 Aug 8 17:25 anaconda.program.log

./httpd:
total 132
-rw-r--r-- 1 root root 0 Aug 19 03:14 access_log
-rw-r--r--. 1 root root 61916 Aug 10 17:55 access_log-20120812

./lighttpd:
total 68
-rw-r--r-- 1 lighttpd lighttpd 7858 Aug 21 15:26 access.log
-rw-r--r--. 1 lighttpd lighttpd 37531 Aug 17 18:21 access.log-20120819

./nginx:
total 12
-rw-r--r--. 1 root root 0 Aug 12 03:17 access.log
-rw-r--r--. 1 root root 390 Aug 12 03:17 access.log-20120812.gz

8. Reverse Output Order

With combination of -ltr will shows latest modification file or directory date as last.
# ls -ltr

total 176
-rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog
-rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log
-rw-------. 1 root root 1586 Jul 31 02:17 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Desktop
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Videos
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Templates
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Public
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Pictures
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Music
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Documents
-rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html
-rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php
drwxr-xr-x. 4 root root 4096 Aug 16 02:55 Downloads
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap

9. Sort Files by File Size

With combination of -lS displays file size in order, will display big in size first.

# ls -lS

total 176
-rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log
-rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html
-rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php
-rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Desktop
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Documents
drwxr-xr-x. 4 root root 4096 Aug 16 02:55 Downloads
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Music
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Pictures
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Public
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Templates
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Videos
-rw-------. 1 root root 1586 Jul 31 02:17 anaconda-ks.cfg
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap

10. Display Inode number of File or Directory

We can see some number printed before file / directory name. With -i options list file / directory with inode number.
# ls -i

20112 0001.pcap 23610 Documents 23793 index.html 23611 Music 23597 Templates
23564 anaconda-ks.cfg 23595 Downloads 22 install.log 23612 Pictures 23613 Videos
23594 Desktop 23585 fbcmd_update.php 35 install.log.syslog 23601 Public

11. Shows version of ls command

Check version of ls command.

# ls --version

ls (GNU coreutils) 8.4


Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Richard M. Stallman and David MacKenzie.

12. Show Help Page

List help page of ls command with their option.

# ls --help

Usage: ls [OPTION]... [FILE]...

13. List Directory Information

With ls -l command list files under directory /tmp. Wherein with -ldparameters displays information of /tmp directory.

# ls -l /tmp
total 408
drwx------. 2 narad narad 4096 Aug 2 02:00 CRX_75DAF8CB7768
-r--------. 1 root root 384683 Aug 4 12:28 htop-1.0.1.tar.gz
drwx------. 2 root root 4096 Aug 4 11:20 keyring-6Mfjnk
drwx------. 2 root root 4096 Aug 16 01:33 keyring-pioZJr
drwx------. 2 gdm gdm 4096 Aug 21 11:26 orbit-gdm
drwx------. 2 root root 4096 Aug 19 08:41 pulse-gl6o4ZdxQVrX
drwx------. 2 narad narad 4096 Aug 4 08:16 pulse-UDH76ExwUVoU
drwx------. 2 gdm gdm 4096 Aug 21 11:26 pulse-wJtcweUCtvhn
-rw-------. 1 root root 300 Aug 16 03:34 yum_save_tx-2012-08-16-03-34LJTAa1.yumtx
# ls -ld /tmp/
drwxrwxrwt. 13 root root 4096 Aug 21 12:48 /tmp/

cd

Change from current directory to /usr/local.

avi@tecmint:~$ cd /usr/local

avi@tecmint:/usr/local$

2. Change from current directory to /usr/local/lib using absolute path.

avi@tecmint:/usr/local$ cd /usr/local/lib

avi@tecmint:/usr/local/lib$

3. Change from current working directory to /usr/local/lib using relative path.

avi@tecmint:/usr/local$ cd lib

avi@tecmint:/usr/local/lib$

4. (a) Move one directory back from where you are now.
avi@tecmint:/usr/local/lib$ cd -

/usr/local

avi@tecmint:/usr/local$

4. (b) Change Current directory to parent directory.

avi@tecmint:/usr/local/lib$ cd ..

avi@tecmint:/usr/local$

5. Show last working directory from where we moved (use ‘–‘ switch) as shown.

avi@tecmint:/usr/local$ cd --

/home/avi

6. Move two directory up from where you are now.

avi@tecmint:/usr/local$ cd ../ ../


avi@tecmint:/usr$

7. Move to users home directory from anywhere.

avi@tecmint:/usr/local$ cd ~

avi@tecmint:~$

or

avi@tecmint:/usr/local$ cd

avi@tecmint:~$

8. Change working directory to current working directory (seems no use of in General).

avi@tecmint:~/Downloads$ cd .

avi@tecmint:~/Downloads$

or
avi@tecmint:~/Downloads$ cd ./

avi@tecmint:~/Downloads$

9. Your present working Directory is “/usr/local/lib/python3.4/dist-packages/ ”, change it to “/home/avi/Desktop/ ”, in

one line command, by moving up in the directory till ‘/’ then using absolute path.

avi@tecmint:/usr/local/lib/python3.4/dist-packages$ cd ../../../../../home/avi/Desktop/

avi@tecmint:~/Desktop$

10. Change from current working directory to /var/www/html without typing in full using TAB.

avi@tecmint:/var/www$ cd /v<TAB>/w<TAB>/h<TAB>

avi@tecmint:/var/www/html$

11. Navigate from your current working directory to /etc/v__ _, Oops! You forgot the name of directory and not

supposed to use TAB.

avi@tecmint:~$ cd /etc/v*
avi@tecmint:/etc/vbox$

Note: This will move to ‘vbox‘ only if there is only one directory starting with ‘v‘. If more than one directory starting with

‘v‘ exist, and no more criteria is provided in command line, it will move to the first directory starting with ‘v‘,

alphabetically as their presence in standard dictionary.

12. You need to navigate to user ‘av‘ (not sure if it is avi or avt) home directory, without using TAB.

avi@tecmint:/etc$ cd /home/av?

avi@tecmint:~$

13. What are pushd and popd in Linux?

Pushd and popd are Linux commands in bash and certain other shell which saves current working directory location

to memory and bring to the directory from memory as current working directory, respectively as well as changes

directory.

avi@tecmint:~$ pushd /var/www/html

/var/www/html ~

avi@tecmint:/var/www/html$

The above command saves the current location to memory and changes to the requested directory. As soon as popd

is fired, it fetch the saved directory location from memory and makes it current working directory.
avi@tecmint:/var/www/html$ popd

avi@tecmint:~$

14. Change to a directory containing white spaces.

avi@tecmint:~$ cd test\ tecmint/

avi@tecmint:~/test tecmint$

or

avi@tecmint:~$ cd 'test tecmint'

avi@tecmint:~/test tecmint$

or

avi@tecmint:~$ cd "test tecmint"/

avi@tecmint:~/test tecmint$
15. Change from current working directory to Downloads and list all its settings in one go.

avi@tecmint:/usr$ cd ~/Downloads && ls

service_locator_in.xls

sources.list

teamviewer_linux_x64.deb

tor-browser-linux64-3.6.3_en-US.tar.xz

...

date and time


This is simplest use of unix date command. just type date in the command prompt and it will show you the
current date and time in the timezone your machine is.

~/java date
Thu Jul 14 14:31:35 MPST 2011

Convert seconds since the epoch (1970-01-01 UTC) to a date

$ date --date='@2147483647'

Show the time on the west coast of the US (use tzselect(1) to find
TZ)

$ TZ='America/Los_Angeles' date

Show the local time for 9AM next Friday on the west coast of the US
$ date --date='TZ="America/Los_Angeles" 09:00 next Fri'

cal - displays a calendar

SYNOPSIS
cal [-smjy13] [[month] year]

DESCRIPTION
Cal displays a simple calendar. If arguments are not specified, the current month is displayed. The options are as
follows:

Tag Description

-1 Display single month output. (This is the default.)

-3 Display prev/current/next month output.

-s Display Sunday as the first day of the week. (This is the default.)

-m Display Monday as the first day of the week.

-j Display Julian dates (days one-based, numbered from January 1).

-y Display a calendar for the current year.

man command itself is extremely easy to use. Its basic syntax is


man [option(s)] keyword(s)

man is most commonly used without any options and with only one keyword. The keyword is the exact name of the
command or other item for which information is desired. For example, the following provides information about
the ls command (which is used to list the contents of any specified directory):

man ls

As another example, the following displays the man page about the man pages:

man man
man automatically sends its output through a pager, usually the program less. A pager is a program that causes the
output of any program to be displayed one screenful at a time, rather than having a large amount of text scroll down
the screen at high (and generally unreadable) speed.

echo

echo [option(s)] [string(s)]

1. Input a line of text and display on standard output

$ echo Tecmint is a community of Linux Nerds

Outputs the following text:

Tecmint is a community of Linux Nerds

2. Declare a variable and echo its value. For example, Declare a variable of xand assign its value=10.

$ x=10

echo its value:

$ echo The value of variable x = $x

The value of variable x = 10


Note: The ‘-e‘ option in Linux acts as interpretation of escaped characters that are backslashed.

3. Using option ‘\b‘ – backspace with backslash interpretor ‘-e‘ which removes all the spaces in between.

$ echo -e "Tecmint \bis \ba \bcommunity \bof \bLinux \bNerds"

TecmintisacommunityofLinuxNerds

4. Using option ‘\n‘ – New line with backspace interpretor ‘-e‘ treats new line from where it is used.

$ echo -e "Tecmint \nis \na \ncommunity \nof \nLinux \nNerds"

Tecmint

is

community

of

Linux

Nerds

5. Using option ‘\t‘ – horizontal tab with backspace interpretor ‘-e‘ to have horizontal tab spaces.
$ echo -e "Tecmint \tis \ta \tcommunity \tof \tLinux \tNerds"

Tecmint is a community of Linux Nerds

6. How about using option new Line ‘\n‘ and horizontal tab ‘\t‘ simultaneously.

$ echo -e "\n\tTecmint \n\tis \n\ta \n\tcommunity \n\tof \n\tLinux \n\tNerds"

Tecmint

is

community

of

Linux

Nerds

7. Using option ‘\v‘ – vertical tab with backspace interpretor ‘-e‘ to have vertical tab spaces.

$ echo -e "\vTecmint \vis \va \vcommunity \vof \vLinux \vNerds"


Tecmint

is

community

of

Linux

Nerds

8. How about using option new Line ‘\n‘ and vertical tab ‘\v‘ simultaneously.

$ echo -e "\n\vTecmint \n\vis \n\va \n\vcommunity \n\vof \n\vLinux \n\vNerds"

Tecmint

is

a
community

of

Linux

Nerds

Note: We can double the vertical tab, horizontal tab and new line spacing using the option two times or as many

times as required.

9. Using option ‘\r‘ – carriage return with backspace interpretor ‘-e‘ to have specified carriage return in output.

$ echo -e "Tecmint \ris a community of Linux Nerds"

is a community of Linux Nerds

10. Using option ‘\c‘ – suppress trailing new line with backspace interpretor ‘-e‘ to continue without emitting new line.

$ echo -e "Tecmint is a community \cof Linux Nerds"


Tecmint is a community avi@tecmint:~$

11. Omit echoing trailing new line using option ‘-n‘.

$ echo -n "Tecmint is a community of Linux Nerds"

Tecmint is a community of Linux Nerdsavi@tecmint:~/Documents$

12. Using option ‘\a‘ – alert return with backspace interpretor ‘-e‘ to have sound alert.

$ echo -e "Tecmint is a community of \aLinux Nerds"

Tecmint is a community of Linux Nerds

Note: Make sure to check Volume key, before firing.

13. Print all the files/folder using echo command (ls command alternative).

$ echo *

103.odt 103.pdf 104.odt 104.pdf 105.odt 105.pdf 106.odt 106.pdf 107.odt 107.pdf 108a.odt 108.odt 108.pdf 109.odt
109.pdf 110b.odt 110.odt 110.pdf 111.odt 111.pdf 112.odt 112.pdf 113.odt linux-headers-3.16.0-
customkernel_1_amd64.deb linux-image-3.16.0-customkernel_1_amd64.deb network.jpeg

14. Print files of a specific kind. For example, let’s assume you want to print all ‘.jpeg‘ files, use the following

command.

$ echo *.jpeg
network.jpeg

15. The echo can be used with redirect operator to output to a file and not standard output.

$ echo "Test Page" > testpage

## Check Content

avi@tecmint:~$ cat testpage

Test Page

echo Options

Options Description

-n do not print the trailing newline.

-e enable interpretation of backslash escapes.

\b backspace

\\ backslash

\n new line

\r carriage return
\t horizontal tab

\v vertical tab

pwd?

‘pwd‘ stands for ‘Print Working Directory‘. As the name states, command ‘pwd‘ prints the current working directory or

simply the directory user is, at present. It prints the current directory name with the complete path starting from root

(/). This command is built in shell command and is available on most of the shell – bash, Bourne shell, ksh,zsh, etc.
Basic syntax of pwd:

# pwd [OPTION]

Options used with pwd

Options Description

-L (logical) Use PWD from environment, even if it contains symbolic links

-P (physical) Avoid all symbolic links

–help Display this help and exit

–version Output version information and exit

If both ‘-L‘ and ‘-P‘ options are used, option ‘L‘ is taken into priority. If no option is specified at the prompt, pwd will

avoid all symlinks, i.e., take option ‘-P‘ into account.

Exit status of command pwd:

0 Success
Non-zero Failure

This article aims at providing you a deep insight of Linux command ‘pwd‘ with practical examples.

1. Print your current working directory.

avi@tecmint:~$ /bin/pwd

/home/avi

Print Working Directory

2. Create a symbolic link of a folder (say /var/www/html into your home directory as htm). Move to the newly created

directory and print working directory with symbolic links and without symbolic links.

Create a symbolic link of folder /var/www/html as htm in your home directory and move to it.

avi@tecmint:~$ ln -s /var/www/html/ htm

avi@tecmint:~$ cd htm

Create Symbolic Link

3. Print working directory from environment even if it contains symlinks.

avi@tecmint:~$ /bin/pwd -L
/home/avi/htm

Print Current Working Directory

4. Print actual physical current working directory by resolving all symbolic links.

avi@tecmint:~$ /bin/pwd -P

/var/www/html

Print Physical Working Directory

5. Check if the output of command “pwd” and “pwd -P” are same or not i.e., if no options are given at run-time does

“pwd” takes option -P into account or not, automatically.

avi@tecmint:~$ /bin/pwd

/var/www/html

Check pwd Output

Result: It’s clear from the above output of example 4 and 5 (both result are same) thus, when no options are specified

with command “pwd”, it automatically takes option “-P” into account.

6. Print version of your ‘pwd’ command.


avi@tecmint:~$ /bin/pwd --version

pwd (GNU coreutils) 8.23

Copyright (C) 2014 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

Written by Jim Meyering.

Check pwd Version

Note: A ‘pwd’ command is often used without options and never used with arguments.

Important: You might have noticed that we are executing the above command as “/bin/pwd” and not “pwd”.

So what’s the difference? Well “pwd” alone means shell built-in pwd. Your shell may have different version of pwd.

Please refer manual. When we are using /bin/pwd, we are calling the binary version of that command. Both the shell

and the binary version of command Prints Current Working Directory, though the binary version have more options.

7. Print all the locations containing executable named pwd.

avi@tecmint:~$ type -a pwd

pwd is a shell builtin


pwd is /bin/pwd

Print Executable Locations

8. Store the value of “pwd” command in variable (say a), and print its value from the variable (important for shell

scripting perspective).

avi@tecmint:~$ a=$(pwd)

avi@tecmint:~$ echo "Current working directory is : $a"

Current working directory is : /home/avi

Store Pwd Value in Variable

Alternatively, we can use printf, in the above example.

9. Change current working directory to anything (say /home) and display it in command line prompt. Execute a

command (say ‘ls‘) to verify is everything is OK.

avi@tecmint:~$ cd /home

avi@tecmint:~$ PS1='$pwd> ' [Notice single quotes in the example]

> ls

Change Current Working Directory

10. Set multi-line command line prompt (say something like below).
/home

123#Hello#!

And then execute a command (say ls) to check is everything is OK.

avi@tecmint:~$ PS1='

> $PWD

$ 123#Hello#!

$'

/home

123#Hello#!

Set Multi Commandline Prompt

11. Check the current working directory and previous working directory in one GO!

avi@tecmint:~$ echo “$PWD $OLDPWD”

/home /home/avi

Check Present Previous Working Directory

12. What is the absolute path (starting from /) of the pwd binary file.
/bin/pwd

13. What is the absolute path (starting from /) of the pwd source file.

/usr/include/pwd.h

14. Print the absolute path (starting from /) of the pwd manual pages file.

/usr/share/man/man1/pwd.1.gz

15. Write a shell script analyses current directory (say tecmint) in your home directory. If you are under

directorytecmint it output “Well! You are in tecmint directory” and then print “Good Bye” else create a

directory tecmintunder your home directory and ask you to cd to it.

Let’s first create a ‘tecmint’ directory, under it create a following shell script file with name ‘pwd.sh’.

mkdir

avi@tecmint:~$ mkdir tecmint

avi@tecmint:~$ cd tecmint

avi@tecmint:~$ nano pwd.sh

$ mkdir

By default, running mkdir without any parameter will create directory under the current directory. Here’s a sample of it
:
From screenshot above, we created directory called office. When we run mkdir command, we are
in/home/pungki directory. So then the new directory, which is office, is created under /home/pungkidirectory. If we
put an exact location - for example : /usr/local - , then Linux will create a directory under /usr/local directory.

When Linux found that the directory which suppose to be created is already exist, then Linux will telling us that Linux
can’t cretate it.

Another pre-requisite of creating directory that you must have access to the location where the directory want to be
created. When you don’t have it then mkdir will report an error.

Create multiple directories

We can also create multiple directories at the same time. Let say we want to create directories namedubuntu, redhat
and slackware. Then the syntax will be like this :

$ mkdir ubuntu redhat slackware

Add directory include its sub-directory


When you want to created a include its sub-directory, you will need to use -p parameter. This parameter will create
parent directory first, if mkdir cannot find it. Let say we want to create directory named letter and directory
named important under directory letter. Then the syntax will be like this :

$ mkdir -p letter/important

Set access privilege

Using -m parameter, we can also set the access privilege for the new directory on-the-fly. Here’s an example.

$ mkdir -m=r-- letter

The above command will create a directory named letter and give access privilege read-only for thedirectory
owner, directory group owner and anybody.

Print message a message for each created directory

If we want, we can use -v parameter to do this. Here’s an example.

$ mkdir -v ubuntu redhat slackware


rm command

To run rm command, type rm followed by filename. Please remember, that by default rm will not ask any
confirmation. Here’s an example of rm in action.

Remove a file

$ rm computer.log

To remove a file named computer.log, we can do it with the command above.

Remove multiple file with specific extension

If you have multiple file with the same extension and you want to delete them, you can use this syntax :

$ rm *.log
From the above screenshot, all files with .log extension are deleted at the same time.

Remove a directory

Removing directory is a little bit tricky. If you are sure that the directory is empty, then we can use -dparameter to
remove it.

$ rm -d documents/

But when the directory is not empty, you have to empty the directory first, or you can remove them recursively. To
remove recursively, use -r or -R parameter.

$ rm -r movie/

Add interactive confirmation before deleting

If you feel more comfortable to have interactive confirmation, you can use -i parameter with rm command. Here’s a
sample of deleting directory recursively with interactive confirmation.
$ rm -ri movie/

Using force deletion

Using force deletion mean that rm will remove all files without any confirmation, even the file is write-protected or
not. Here’s some samples.

Remove file with write-protected access

We see that movie.list has acces read-only for owner, group owner and everyone. When we tried to remove it, rm
will ask a confirmation about it, but the file is successfully deleted. Using -f parameter, rm will not ask any
confirmation. Take a look at screenshot below.

But if the directory where the files is located is write-protected, then the file cannot be removed, even the file itself
is not write-protected.
rmdir command syntax

mdir [OPTION] {directory-name}

Delete / remove directory

To delete directory called foo, enter:

rmdir foo

Remove DIRECTORY and its ancestors

For example remove directory structure sales/99/march

rmdir -p sales/99/march

Recursive delete

Remove all directories and subdirectories, use rm command with -r option:

rm -rf /home/data/2000

ps
Run ps without any options

This is a very basic ps usage. Just type ps on your console to see its result.
By default, it will show us 4 columns of information.

 PID is a Process ID of the running command (CMD)


 TTY is a place where the running command runs
 TIME tell about how much time is used by CPU while running the command
 CMD is a command that run as current process
This information is displayed in unsorted result.

2. Show all current processes

To do this, we can use -a options. As we can guess, -a is stand for “all”. While x will show all process even the
current process is not associated with any TTY (terminal)

$ ps -ax

This result might be long result. To make it more easier to read, combine it with less command.

$ ps -ax | less
3. Filter processes by its user

For some situation we may want to filter processes by user. To do this, we can use -u option. Let say we want to see
what processes which run by user pungki. So the command will be like below

$ ps -u pungki

Kill command send a signal, a specified signal to be more perfect to a process. The kill command can be executed in

a number of ways, directly or from a shell script.


Using kill command from /usr/bin provide you some extra feature to kill a process by process name using pkill. The

common syntax for kill command is:

# kill [signal or option] PID(s)

For a kill command a Signal Name could be:

Signal Name Signal Value Behaviour

SIGHUP 1 Hangup
SIGKILL 9 Kill Signal
SIGTERM 15 Terminate

Clearly from the behaviour above SIGTERM is the default and safest way to kill a process. SIGHUP is less secure

way of killing a process as SIGTERM. SIGKILL is the most unsafe way among the above three, to kill a process

which terminates a process without saving.

In order to kill a process, we need to know the Process ID of a process. A Process is an instance of a program.

Every-time a program starts, automatically an unique PID is generated for that process. Every Process in Linux, have

a pid. The first process that starts when Linux System is booted is – init process, hence it is assigned a value of ‘1‘ in

most of the cases.

Init is the master process and can not be killed this way, which insures that the master process don’t gets killed

accidentally. Init decides and allows itself to be killed, where kill is merely a request for a shutdown.

Synaptic Package Manager


You can install it by searching in the software-center for synaptic and clicking on Synaptic Package Manager

Installing with CLI


Or, alternatively, open a terminal, and enter:
sudo apt-get install synaptic
Getting Started
To launch Synaptic, choose
1. System > Administration > "Synaptic Package Manager"
Or if you are using the Unity interface, open the dash and search for synaptic.
The main window is divided into three sections: a package browser on the left, the package list on the upper right,
and package details on the lower right. The status bar shows you the system state at a glance.

And if you would like to see more details about a package, use a mouse right-click on a package and
choose Properties
Browsing the package database
To browse the (very large) list of available packages by category, section, package status, custom filters, or recent
searches. Click on the corresponding button at the bottom of the left window pane. You can also create your own
filters. See the Filters section for details.
To search for packages by name or description, click on the Search button in the toolbar:

1.
or use the "Quick search" field in the toolbar:

1.
You can examine a number of package details in the lower right window pane such as its size, its dependencies,
recommended or suggested additional packages, and a short description.

How to apply filters


1. To be added
Repositories
Repositories are like shops (currently almost always free), warehouses or archives full of almost all the software,
drivers, codecs, libraries and other packages that are available for the release of Ubuntu (or whichever distro) you are
using.
It is up to the package project's team to get their package into the repositories for the various releases of the various
distros. Also it is up to the team developing a release to make sure that the repositories have plenty of the right sort of
packages to meet people's needs. Think of a shop. Companies need to get their product onto shelves and shops
need to show they have plenty to sell. This saves individual users from having to identify the 'correct' website for a
product and assess whether or not the site has been compromised and whether they are getting a genuine product or
something stuffed full of malware.
The standard repositories are all free as are the Medibuntu repositories and most others that are easily found and
added. Theoretically there is nothing stopping a games manufacturer (for example) setting up a one-off or monthly
charge for accessing a specialist repository. The ethics and licensing agreements would have to be looked into if
people or companies chose this route.
Adding or removing repositories is fairly easy.

Managing Repositories
Either from the top taskbar
System - Administrator - "Software Sources"
or from inside Synaptic using the Settings menu, select Repositories
The first tab of the pop-up is where Cd/Dvds can be added (or removed) as repositories to search. Usually the
various online "repos" are already included so you might be installing a more recent version of something that is listed
on the Cd/dvd and also in the online repos. The package manager will automatically choose the most recent by
default although one of the other tabs in the pop-up can change the priorities, or in thePreferences pop-up from
the Setttings menu.

As a front-end to apt, Synaptic uses the system-wide list of software repositories file located at
1. /etc/apt/sources.list
For more on managing software repositories, see the Repositories wiki page.

Updating the Package List


Click Reload or press Ctrl + R to make Synaptic aware of the latest updates and any changes to the list of
repositories.
Although this is done automatically when you open Synaptic it can be a good idea to update the database from time
to time while running Synaptic. The database is a list of packages on your system to keep track of installed software.
All the package managers share the same list and the same list of repositories but each one presents the information
slightly differently. The main time you will need to update the lists is when/if you have made changes to the list of
software channels or if you have made changes to Synaptic's configuration.

Adding or Removing Software

Adding Packages

Mark the Chosen Packages


1. Right-click on each chosen package and choose Mark for Installation from the context menu, or press Ctrl +
I. If the package requires the installation of another package, a dialog box appears:
Synaptic will warn you if your choices conflict with packages that are already installed on your system. If
this is the case, the dialog box will show you any packages that need to be removed. If you are not sure you
don't need the package(s) that will be removed, make sure you look up its function and use before you apply
the changes you've made.
2. Click Mark to allow the installation of the additional package(s).

Installing Packages

Without an Internet Connection


Search for and "Mark" all the applications that you want to install/upgrade in the usual way but don't click the "Apply"
button. Instead use the Filemenu to "Generate a download Script".
With no internet connection at all of course you wont be able to Update the Package List and so packages may be
older versions. An intermittent, occasional or slow connection could usefully update the list and then use the Script
method to get updates via a 2nd machine which would not have to be running Ubuntu. The Script is designed to work
on Windows or Mac machines too.
There are a few guides
1. https://help.ubuntu.com/community/Synaptic/PackageDownloadScript
2. https://help.ubuntu.com/community/Synaptic/Offline
or use apt-get instead of Synaptic
1. https://help.ubuntu.com/community/AptGet/Offline
or an alternative approach, 'simply' download the entire repository!
1. https://help.ubuntu.com/community/AptGet/Offline/Repository

With a Broadband Connection


1. Once you are satisfied with your choices, click on Apply in the toolbar or press Ctrl + P.
2. A dialog box appears with a summary of changes that will be made.
3. Confirm the changes by clicking on Apply.

You might also like