Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 34

Linux Introduction and GNU Commands

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

Introduction

Linux at lowest level, is based on linux kernel the very low-level software that manages our computer hardware, multi-tasks the many programs that are running at any given time, and other such essential things Linux Operating System has various utilities, for example shell (that provides a command prompt), cp (a program to copy files) etc. Finally, software companies (and sometimes volunteer groups) add on lots of extra software, like KDE,GNOME,Xfree86 X Windows System, games , etc. Together, the operating system kernel, system software (such as cp, shell etc), and application software(GNOME,KDE,XFree86 etc) collectively, is called as "Linux.
Copyright 2004 Virtusa Corporation | CONFIDENTIAL

Application Software

Linux Kernel System Software

General Organization of the system

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

Components of a Linux System

Like most UNIX implementations, Linux is composed of three main bodies of code; the most important distinction between the kernel and all other components. The kernel is responsible for maintaining the important abstractions of the operating system.

Kernel code executes in kernel mode with full access to all the physical resources of the computer. All kernel code and data structures are kept in the same single address space.

The system libraries define a standard set of functions through which applications interact with the kernel, and which implement much of the operating-system functionality that does not need the full privileges of kernel code. The system utilities perform individual specialized management tasks.
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 4

Design Principles

Linux is a multiuser, multitasking system with a full set of UNIXcompatible tools.. Its file system adheres to traditional UNIX semantics, and it fully implements the standard UNIX networking model. Main design goals are speed, efficiency, and standardization. Linux is designed to be compliant with the relevant POSIX documents; at least two Linux distributions have achieved official POSIX certification. The Linux programming interface adheres to the SVR4 UNIX semantics, rather than to BSD behavior.

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

The Unix Architecture 1

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

Unix Architecture 2

Kernel

Hardware is surrounded by Operating System software Operating System is often called System Kernel or Kernel Isolated from users and applications Mostly Monolithic

System Call Interface


Users services and interfaces considered as part of OS Includes Shell, Other interface software and C compiler components

(compiler,assembler,loader) Provides interface to users and applications

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

Unix Architecture 3

Unix Commands & Libraries

Operating System contains primitive routines that allow direct hardware access Provides interface for user interaction Users gain access to specific kernel functions through Unix commands

User written Applications



Mostly written in C or high level languages Tailored specific to user requirements Provides interface for user interaction User programs can invoke OS services either directly or through library programs

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

History

Written by Linus Benedict Torvalds.

In 25th August 1991 he sent a mail to Newsgroups: comp.os.minix stating about his project (Linux), which became a huge success after wards.
Taxonomy Linux in Desktop & Enterprise

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

FreeBSD Vs Linux Vs Windows 2000


FreeBSD Reliability Performance Security File System Device Drivers Commercial Applications Y Y Y Y Ok Ok Linux Y Ok X X X Ok Windows X X X X X Y

Free Applications
Development Environment Development Infrastructure

Y
Y Y

Y
Ok Ok

X
X X

Support
Price

Y
Y

Y
Y
Copyright 2004 Virtusa Corporation | CONFIDENTIAL

Ok
X
10

Linux Installation

Partitioning
File System /dev/hda1 Memory 200-500 MB Mounted On /boot

/dev/hda2 /dev/hda3 /dev/hda5 /dev/hda6 /dev/hda8 /dev/hda9 /dev/hda10

1GB 500MB 1GB 3-10 GB 3-5 GB 500MB-1GB 3-5 GB Rest

Swap / /usr /var /tmp /opt /home

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

11

Installation

Linux needs about 10MB for a very minimal installation. Some popular vendors of Linux: redhat, suse, mandrake, gentoo, debian, slackware, turbo linux, Lycoris, stampede,Tiny Linux, phat linux etc.

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

12

RPM

RPM ( Redhat Package Management): Provides following advantages

Ease of installation and uninstallation Ease of upgrading already-installed packages Protection of configuration files Simple tracking of installed files

Example
To install a new software: rpm ivh pckg_name To install a software forcibly: rpm ivh force pckg_name To remove a software: rpm e pckg_name To remove a software without checking dependencies: rpm e nodep pck_name To Upgrade an existing software : rpm uvh pckg_name To query for a software: rpm a pckg_name To query for software from all list: rpm qa | grep pckg_name
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 13

GNU Commands

cd: change directory cp: copy filesCat: print out file onto Screen mv: rename or move a file mkdir: Make a Directory ls: show directory, in alphabetical order. rm: remove a file more: view a file, pausing every screenful. who: show up who you are locate: find a file passwd: cahnge password. man: shows help on specific command df:shows disk space available on system du: shows how much disk space being used up Free: display information about free and used memory Gzip/zip/bzip: to compress a file Tar: combines mulitple files into one file or vice versa.
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 14

Commonly Used Commands

Appropos: search the what is database for string Makewhatis: create the what is datdabase Whatis: search what is database for sort: to sort files in a directory. comp: to compare files. diff: difference between two files. grep: search for a string in a file. finger: shows more information about a user find: to find a file netstat: print network connections, routine tables etc. ifconfig: configure a network interface. cmp: to compare two files. Ps: report process status Pstree: display a tree of process. Top: to display top CPU process.
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 15

GNU Commands Shell Variables

Prompt String PS1


The special variable holds the contents of the command prompt that are displayed when bash is ready to accept commands. $echo $PS1

PATH
Contains list of all directories that hold commands or other programs that are likely to be executed $echo $PATH

Environment Variables
Environment variables are passed on to programs and other shells, and together they are said to form the environment in which the programs execute $export MYVAR

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

16

Commands at the Command Prompt

List files ls
$ls l $ls a $ls *.c $ls la

$w

Give list of users

Man
Inbuilt help $man helptopic

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

17

Command History

!! !n !-n ! String !? String ^ string1^string2

Refers to the most recent command. Refer to command n from the history. You'll use the history command to display these numbers. Refer to the current command minus n from the history. Refer to the most recent command starting with string. Refer to the most recent command containing string. Quick substitution. Repeat the last command, replacing the first occurrence of string1 with string2.

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

18

Process Text Streams Using Text-Processing Filters - 1

$cut options [files]

Cut out selected columns or fields from one or more files Frequently used options -b list Print bytes in list positions. -c list Print characters in list columns. -d delim Set field delimiter for -f. -f list Print list fields. $ cut -c 1 /etc/passwd $ cut -d: -f1 /etc/passwd

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

19

Process Text Streams Using Text-Processing Filters - 2

$join [options] file1 file2 Print a line for each pair of input lines, one each from file1 and file2, that have identical join fields. Frequently used options -j1 field Join on field of file1. -j2 field Join on field of file2. -j field Join on field of both file1 and file2. Example File 1 File2 $join j 1 File1 File2 1 one 1 11 1 one 11 2 two 2 22 2 two 22 3 three 3 33 3 three 33
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 20

Process Text Streams Using Text-Processing Filters - 3

Head
$head [options] files Print the first few lines of one or more files.

Nl
$nl [options] [files] Used for numbering lines in the body of the text.

Paste
Paste together corresponding lines of one or more files into vertical columns. File1 file2 $paste file1 file2 1 A 1 A 2 B 2 B 3 C 3 C

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

21

Process Text Streams Using Text-Processing Filters - 4

Paste
File1 1 2 3 File1 1 2 3 file2 A B C file2 A B C $paste d@ file1 file2 1@A 2@B 3@C $paste s file1 file2 1 2 3 A B C

Split
Splitting a file into specified number of line groups, with output going into a succession of files Frequently used option -n Split the infile into n-line segments. The default is 1000.

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

22

Process Text Streams Using Text-Processing Filters - 5

Split

Example File1 1 one 2 two 3 three 4 four 5 five 6 six $split 2 file1 splitout_ yields three new files splitout_aa, splitout_ab, splitout_ac

Tac

Prints text files to standard output,with lines in reverse order

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

23

Process Text Streams Using Text-Processing Filters - 6

Tail [options] [files]

Print the last few lines of one or more files.

$tr [options] [[string1 [string2]]

Translate characters from string1 to the corresponding characters in string2. Frequently used options -d Delete characters in string1 from the output. -s Squeeze out repeated output characters in string1 $ cat file1 | tr a-z A-Z $ cat file1 | tr -s a cat file1 | tr -d abc

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

24

Process Text Streams Using Text-Processing Filters - 7

Wc

Print counts of characters, words, and lines for files. Frequently used options -c Print the character count only. -l Print the line count only. -w Print the word count only $ wc -l file1 $wc file1

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

25

Perform Basic File Management 1

Copy Files
$cp [options] file1 file2 $cp [options] files directory

Make Directory
$mkdir source $mkdir good bad ugly $mkdir good bad ugly

Move Files
$mv src tgt

Remove Files
$rm [options] files

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

26

Perform Basic File Management 2

Remove Directories
$rmdir [options] direcotories

Create Empty File


$touch [options] file1 file2 file3

Move Files
$mv src tgt

Remove Files
$rm [options] files

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

27

Process Monitoring 1

$ps [options]

This command generates a one-time snapshot of the current processes on standard output. $ps
$ ps -aux | grep httpd

$pstree [options] [pid|user]

Displays the hierarchical list of processes in a tree format $pstree -p

$top [command-line options]


Similar to ps, but in a continuously updated display.

$kill [-s sigspec | -sigspec ] [pids]


Kill is generally used to send termination signals.
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 28

Process Monitoring 2

Shell job Control

$mozilla &
$bg [jobspec] Place jobspec in the background, as if it had been started with & $fg [jobspec] This command places the specified job in the foreground, making it the current job.

$jobs List the active jobs.

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

29

Making Use of Regular Expressions 1

Grep Search files or standard input for lines containing a match to regular expression regex. $grep [options] regex [files] Frequently used options -c Display only a count of matched lines, but not the lines themselves. -h Display matched lines, but do not include filenames for multiple file input. -i Ignore uppercase and lowercase distinctions, allowing abc to match both abc and ABC. -n Display matched lines prefixed with their line numbers. When used with multiple files, both the filename and line number are prefixed. -v Print all lines that do not match regex.

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

30

Making Use of Regular Expressions 2

Regular Expression

Description

Match at the beginning of a line. This interpretation makes sense only when the ^ character is at the lefthand side of the regex. Match at the end of a line. This interpretation makes sense only when the $ character is at the righthand side of the regex.

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

31

Making Use of Regular Expressions 3

[abc][a-z]

Single-character groups and ranges. In the first form, match any single character from among the enclosed characters a, b, or c. In the second form, match any single character from among the range of characters bounded by a and z. The brackets are for grouping only and are not matched themselves.

[^abc] [^a-z]

Inverse match. Match any single character not among the enclosed characters a, b, and c or in the range a-z. Be careful not to confuse this inversion with the anchor character ^, described earlier. Match words. Words are essentially defined as being character sets surrounded by whitespace and adjacent to the start of line, the end of line, or punctuation marks. The backslashes are required and enable this interpretation of < and >. Match any single character except a newline. As mentioned in the section on quoting earlier, turn off (escape) the special meaning of the character that follows, turning met characters in to literals.
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 32

\<word\>

. (the single dot)

Making Use of Regular Expressions 4

Stream Editor sed


sed [options] 'command1' [files] sed [options] -e 'command1' [-e 'command2'] [files] sed [options] -f script [files] $ sed '/^$/ d' file1 The regular expression ^$ matches blank lines and the d command removes those matching lines from sed's output.

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

33

Further References.

http://www.linuxjournal.com/ http://www.linuxcentral.com/_v3/ http://www.linuxgazette.com/

Copyright 2004 Virtusa Corporation | CONFIDENTIAL

34

You might also like