Graphical User Interfaces in Linux

GNOME/KDE/X-window system

—————————

– X-window system

. It is the main GUI component of linux.

. It is based on client/server Architechure.

. Applications are called x-clients & display is called x-server.

. x-cleints communicates with x-server using x-protocol.

. x window system was developed by Athena project of MIT; now handled by

xc-consortium.

. It is plateform independent.

. It should not be pluralized.

GNOME (global network object model environment)

. It is default & consistent desktop environment.

. It has been developed using GTK toolkit.

KDE (K Desktop environment)

. It is also consistent desktop environment of Redhat Linux.

. It has been developed using QT-toolkit.

Window Managers

—————–

– Metacity  – GNOME window manager

KWM – KDE

-Display Manager (GUI login screen)

#runlevel

N 5 (current runlevel)

1= single user mode

3- only text-based terminals (f1-f6) are available

5 – both text-based terminals ( f1-f6) & GUI (f7) are available

to switch level

—————-

#init <runlevel> to switch into the specified runlevel

eg. #init 5

To add runlevel at system startup

open

# vi /etc/inittab

change

id:5:initdwefault:

change 5 into 3 or desired

to logout from GUI mode

press ALT+CTRL+<backspace>

GDM= GNOME display manager

XDM= xfree86  ,,       ,,

to change display manager

—————————

#vi /etc/sysconfig/desktop

DESKTOP=”GNOME”

remove above desktop=”gnome” line and add following

DISPLAYMANAGER=”GNOME”

OR

“KDE”

OR

“XDM”

-Desktop switching load

14 June 05 RHCE Preparation Course

GNOME/KDE/X-windows system (Contd..)

GNU Applications

* GUI Terminals

#gnome-terminal – gnome terminal

#konsole – KDE

#xterm – XFree86

* GUI Editors

#gedit – GNOME Editor

#kwrite – KDE

#gvim – GUI version of vi

#xemacs – ,, ,, ,, emacs

* Web Browsers

#mozilla – standard web browser

#konqueror – KDE ,, ,, ,,

#nautilus – Web browser/file manager

* Email Clients

#Mozilla Mail – Standard email client

#kmail – KDE ,, ,, ,,

#evolution – Gnome ,, ,,

* Office Applications

#office.org Office suit

#oowriter – word processing application

#oocalc – Calculator

#ooimpress – Presentation software etc…..

* Some more GNOME applications

#gnumeric – Spread sheet

#mrproject – Project management software

#gnomemeeting – Video conferencing software

Introduction to Processes

Introduction to process

————————–

What is a process?

———————

.Each running application is called a process.

.Each process are identified by a no. called preocess idification no. (PID)

.PID of ‘init” process is always 1.

init= it is the first process that is started at boot time.,

it is called also grand parent of all the process

* Types of process

———————–

I. foreground process

II. backgroup process

States of process

——————

Runnable – R

Sleeping – S

Stopped –  T

uninterruptiable sleep -D

Zombie (defunct) – Z

Additional states

——————–

Process with high priority – <

,,       ,,  low   ,,      – N

,,       ,,  having pages locked into memory – L

,,      ,,   np resident pages into memory – W

Note using #pstree (displays process ancestory)

Viewing process states

#ps (displays all the process that are running in the foreground under the control of current terminal

#ps -A (all the terminal

#ps -x (displays all the background prcoess

#ps -l ( ,,     long listing of processs)

#ps -u (,,    user owner of the process)

#top – (text based process monitoring tool)

PRI= System priority

NI = Nice value (user managed priority)

Altering process scheduling priority

—————————————

Max priority (Nice value) –> -20

Min  ,,          ,,        ,, +19

default ,,      ,,        ,,  0

nice – used to set priority of an application when it is run.

renice – used to after priority of a runing application(process).

#renice -5 -P 1

-5=priority(nice value)

-P=option to specify pid

1=pid of process

Introduction to process (contd…)

Sending signals to process

—————————-

kill                               [signal]                       [pid]

-15      –>                   Soft signal (default signal. als                                                                   o used while processing CTRL+C

[-TERM]

-9

[-kill]    –>                   Strong signal

Killall                          [signal]                       [application_name]

-15                              to kill the application form all                                                                     the terminal

-9

Running process into background

———————————

#find / -name httpd.conf >httpdout & (running process in backgroud and print output in httpdout

#find / -name httpd.conf >httpdout 2>httderr &

#jobs – Displays the status of all the background & stopped jobs.

* Stopping a process

#find / -name *.conf

use CTRL+Z to pause the current job (process)

* Resuming stopped process

—————————-

#bg %job_id – to resume the stopped process into background

#fg %job_id – to resume the stopped prcoesss into foreground

#kill %job_id – to kill the stopped process

Introduction to Shell Scripting

Bash Shell scripting

———————

-What is a shell script?

. Shell script is a normal text file that contains commands to perform some specific tasks.

.Shell scripting is extensively used in system administration to automate routine task like creating backup, scanning disks etc.

.Shell scripts are also used to create simple applications.

Creating a Shell script

————————

before using this , use this command

#echo “Testing shell script”

# (hash is used to give comments in script0

#! (hash and exclamation is called she-bang) is used to specify interpreter’s path

Bash Shell scripting (contd…)

Options

1.         String operator

str1 [option] str2

= True if string is equal to string 2

! true if string1 is not equal to string2

-z Str – true if the string size is equal to zero

-n Str – true if the string size is not equal to zero

2.         Numeric operators

Num1 [option] num2

-eq – true if num1=num2

-ne – true if ,,   not = to

-lt – ,,   ,,  ,,  < ,,

-le – ,,  ,,   ,,  <= ,,

-gt – ,, ,,   ,,   > ,,

-ge – ,,  ..   ,, >= ,,

3. Logical operators

-a logical AND

-o ,,      OR

!  ,,      NOT

4 File operators

-e file – true if tjhe file exists

-f file  – ,,  ,,   ,,  ,, is a normal file

-d file ,,  ,,      if it is a dir

-h file ,,   ,,      ,,,   ,, symbolic link

-r file  ,,   ,,   ,,    ,,, if the file is readable

-w file true writable

-x file ,,         ,,   executable

-O file true if the file is effectivly owened by user owener of the file

-G file true if the file is effectivly owened by group owner of the file

Linux Shell Basics

The bash shell:

Sh:      Bourne shell, developed by Steven Bourne in AT & T lab.

-A traditional unix shell.

Csh: C shell, C programming language was used.Developed by Bill Joy

(many features such as:

-command line complition

-command line editing

-History of command for each user is mantained.

Ksh: Korn shell developed by David Korn at AT & T lab.

Bash shell: The Bourne again shell is the Linux standard command line interpreter.

It was developed by GNU project and has Captured all the good features of ‘sh’ and Korn Shell.

– for more help #man bash

to see the current shell

#echo $SHELL

History for the command for each user.

#history

for history file

# /.bash.history

#!! 9repeats the previous command)

#!n (repeats command which is in line number ‘n’ in history file)

eg.

#!23

#!m (repeats prevous command starting with m)

#!l

#!-N (repeats command executed ‘n’ command back)

eg. #!-23 (repeats command entered 23 command back)

bash use of wild card character:

? Matches a single character

* Matches all characters

[a-z]     Matches in the range a to z

[^a-e]   Doesn’t match in the range a to e

[be]      match in the set b and e

[^be]    doesn’t match in the set n and e

#rm -rf [^a-d]*

bash contined…

#mkdir /var/xyz/test (it could not create test dir if not exist /var/xyz)

#mkdir -p /var/xyz/test (also creates the parent directories)

#mkdir -p /var/hmg/ministry/{home,finance,agr,health,def}/{sec,officer,executives}

#cd ../finance;ls

Command alias

#alias

eg. find /-name grub -and -user root

alis search=’find / -name  grub -and -user root’

Use of quotes:-

‘ Single quote: Treats everything even a special character as ordinary character./

” Double quote: Expands the especial characters.

` Backquote: Command can be executed

Variables

————–

Two types of variables

1.         Local shell bariable: Available to the current shell only

2.         Environment variable: Available to the current shell as well as sub-shlls.

#env – displays env. shell variable only.

@set – displays both local and env. shell variables.

#ps – displays the current running(foreground) process

#/home/.bash_profile- Containms user-specific shell variables

/etc/profile – contains system-wide shell(globally) shell variables.

#export (variable name) – to make the variable env. variable.

eg. export myvar

#set

#env

#echo $myvar

#ps

#bash

#ps

#echo $myvar

Finding Files and Directories

finding files and directories

Find command searches for files and directories as per the defined criteria.

find command also searches inside the sub-dir of specified path.

Syntax:

find [path] <criteria> <action>

path=where to search

Criteria can be:

-name <filename>   [name based search]

-iname <filename> [name based search, but ignorecase]

-perm <perm>                       [permission ,,     ,, ]

-atime -N,+N,N                      [access time ,, ,,]

-mtime -N,+N,N                     [modified  ,,  ,,]

-user <user>             [modified ,,  ,,]

-group <group>                    [group ownership based search]

-size <size>               [size based search eg. 20M,20K or give 20c to treat size as character].

-type                           [type can be f d c b etc]

eg.

#find / -name passwd   (/ is before root) (it searches all the files of passwd inside the /)

#find / -perm 660

#find -mtime 3 (it searches before 3 days file)

Processing the find files:

-exec (doesn’t give interactive message)

-ok       (Interactively)

{}          place holder for found files.

eg.

#find / -name groub.conf -and -user root -ok cp {} /test11 \;   (termination of command)

Slocate/Locate:-

Slocate and locate commands searches for files and directories in the updated database. The files and directories matching the pattern are returned.

-By default system updates the database in every 24 hours (eg. a daily task)

Syntax:

locate/slocate pattern

#slocate httpd.conf (locates httpd.conf from our system)

#slocate hosts.allow

#updatedb (updates the slocate database)

Calculating Default Permissions

Calculating default permission

1. file – Maximum allowed permission at the time of file creation (666)

-umask

Default permission on a file

0022

1st zero is special permission

2nd zero is owner perm.

2. Directory

Max. allowed permission at the time if dir creation (777)

Default permission on a dir.

Questions:

Set the value of umask such that file created after changing umask value have read & write perm. for owner but no permission to group members & others.

Answer:

umask 066

-sets value of umask for the curent session

#umask

#cat>newfile

3rd zero group perm.

Color Codes in Linux

Color codes

———–

White color – Normal text file

Blue                Dir

Green             Executable file (.exe,.com,bat..bash etc)

Cyan              Symbolic link

Yellow                        devie file

Red                 Compressed file or archive file (.gx,.bz2,tar etc)

Magenta                    Picture file (.jpg.bmp.xpm etc)

Location of file

/etc/DIR_COLORS

User Groups and Permissions

– Users

Types: UID

1.         Root user       0

2.         System users            1-499

3.         normal users >500

/etc/passwd – User database

format

Username:x:UID:GID:<comment>:home_dir:shell

X=Encricpted password

(/etc/shadow)

Groups

Types:                        GID

1. Root users group 0

2. System User group          1-499

3. Normal user group          >500

/etc/group database file

Format

Groupname:x.GID:<members_of_the_group>

X=encripted password

(/etc/gshadow)

User Information commands

# whoami (displays login name)

#who

#users

#w

above three commands displays list of currently logged in users

#groups

#id

above two commands displays the list of groups of which the logged in user is

a member

Unit 5 Uses, Groups & Permission (contd…)

* Switching users account

# su – username

eg. # su – sbogati (It asks password for loging user)

* User Categories

Owner -u

Group -g

others-o

all(ugo)-a

Permission types:

Permissions  Symbolic represatation       Numeric value(octual value)

Read                          r                       4

Write                           w                     2

Execute                                 x                      1

No Permission                      –                       0

Permission operators

Options                                  Meaning

——-                           ———

+                                  to add permission

[on existing one]

–                                   to remove pewrmission

(from existing one)

=                                  to absolutly assign permission

(overwriting existing one)

* Effects of permission:

Permission    Effects on a file                    Efects on a dir

1. Read (r)     1. It allows to view the         1. It allows to list the content                                                                         s of a dir

[ls]

2. Write (w)    2. It allows to modify the     2. It allows to create/remove/re                                                                     name files/dirs. inside the

directory

[cat>, mkdir, mv, rm etc.]

3. Execute (x)            3. It allows to execute the file

if it is a program file.         3. It allows to enter into the

dir

[cd]

contents of a file

[vi nano,..]

contents of a file

[cat, vi, less

* Umask

——–

It is a value that determines default permission (ig. permission at the time of

file/dir. creation) on a file or dir.

———-

1. – type

2. d dir

3. l symbolic link

4. b block device file

5. c character device file

Above 9 tpye are called permission string

first 3 are owners permission, sedond 3 are group permission and last 3 are others permissions

Vi Editor

The VI editor

The standard Unix/Linux editor

-Now we have vim-improved with move feature.

-When Vi is used system invokes ‘Vim’ because vi is defined alias to vim.

Starting:

# Vi filename

(Open an existing file or editing or a new file is created if the current buffer is saved)

Three operating modes of vi:

1.Command Mode: All the vi command and cursor movement key-strokes can be used. Command such as copying, pasting (put), undo, redo is run is command mode

2.Insert Mode: Actually whatever we want to write from the keyboard to the file is done in this mode. Simply insert mode takes input to the file.

3. Execution Mode: Searching for text, saving, quitting etc is done from here normally followed by (/ or :)

Note:   1. Use: set nu (or number) to display the line number)

2 Use: set nonu (to hide line number)

3. To use color full text in vi this package should be installed

# rpm -q vim-enhanced

INSERT:

a- Insert after the cursor

i- Insert before the cursor

o- Insert to a line below

A= Append to the end of line

I= Insert at the beginning of the file

O= Insert to a line above

Copy, Paste, Delete, Undo, Redo

——————————–

yy – to copy the current line

3yy- copies 3 lines below the cursor position

p – Put below (paste) below the line.

P – Paste above the line

dd – Deletes the current line

5dd -Deletes 5 lines below the cursor

u – Undo the recent change

U – Undo the changes to present line

Ctrl+r -redo

Execution Mode:

:w – write but stay in the buffer.

:q – quit q! (Forcefully quit the buffer)

:wq – write and quit

:x     ,,    ,,   ,,

zz – from command mode.

:wq /var/test (saves in different location)

:r /etc/hosts (opens different file in the same buffer)

:r !cal , :!date – to execute commands

/ and enter searching word to find

eg. /Linux  (text -forward

? And enter searching word to find (backward)

:set ignorecase or set ic (it igone the text case)

:set noic (to disable case)

n= next search in same

N= Next search in reverse direction

Sorting

sorting is the arrangement of data/information in increasing (ascending) or decreasing(descending) pattern.

#sort <options> filename

Options: -r -reverse order

-n -numeric order

-t -as field separator, delimiter

-k position

-u unique sort

#sort /etc/passwd

#sort -r /etc/passwd

#cut -d:-f7 /etc/passwd|sort -u

#sort -t: -K1 /etc/passwd

Uniq: uniq moves the duplication and returns only the unique items.

# cut -d -f7 /etc/passwd|uniq -c (also counts number of counts for the item)