Top Banner
Valentine udoh
33

Introduction to Linux- Lesson 4

Apr 07, 2018

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 1/33

Valentine udoh

Page 2: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 2/33

Using text editors In Linux Understanding the Linux directory structure

Installation in Linux Linux variables

Page 3: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 3/33

Used to write text documents and/or editconfiguration files

Similar to notepad or WordPad in Microsoftwindows

Better and more flexible than creatingviewing and editing with the less, head, tail,touch and cat commands.

Three basic text editors are the nano, vi/vimand the nedit.

Page 4: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 4/33

In order to view or create a file using the vi texteditor, type vi filename 

In the text editor, it is in a default read-onlystate. In you want t insert words, type the “I” keyand when you are through, type the “esc” key togo back to read only mode

Navigate with the arrow keys

If you are done editing press the “:” key (makesure that you have left edit mode first) then type wq to save and exit q! to exit without saving

Followed by the “enter” key 

Page 5: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 5/33

Page 6: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 6/33

/bin: This directory must be present for OS to boot, contains utilitiesused during startup, executable files necessary to manage and run theLinux system, including shells (such as bash) and file systemmanagement utilities such as cp and rm.

There are four major bin directories (none of which should be used forstoring junk files :)

/bin

/sbin

/usr/bin /usr/local/bin

All of the bin directories serve similar but distinct purposes; the division of binary files serves several purposes including ease of backups,

administrationand logical separation.

Page 7: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 7/33

/sbin: Literally "System Binaries". This directory containsfiles that should

generally only be used by the root user, though the Linux file

standard dictates that no access restrictions should be

placed on normal users to these files. The /sbin directory

should contain essential system management and

administration files, such as fdisk, fsck, ifconfig, init, mkfs,

halt, system event control (restart and shutdown

programs) and certain networking programs.

Page 8: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 8/33

 /boot: This directory contains your bootloaderfiles, which are required to boot your system.

 /dev :This directory contains special files thatare used to represent the various hardwaredevices installed in the system. SCSI hard disk

drive in a system is called sda and the first IDEhard drive in a system is called hda. The files thatrepresent these devices are stored in /dev

Page 9: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 9/33

/etc: This directory contains text-based configuration filesused by the system as well as services running on thesystem. You can edit these files with a text editor tocustomize how Linux behaves. Some of the configuration

files in /etc include. /etc/fstab : Lists the partitions and file systems that will beautomatically mounted when the system boots.

/etc/group Contains local group definitions.

/etc/grub.conf Contains configuration parameters forthe GRUB bootloader (assuming it’s being used on thesystem).

/etc/hosts Contains a list of hostname-to-IP address

mappings the system can use to resolve hostnames.

Page 10: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 10/33

/etc/inittab Contains configuration parametersfor the init process.

/etc/init.d/ A subdirectory that contains startupscripts for services installed on the system. On aFedora or Red Hat system, these are located in/etc/rc.d/init.d.

/etc/modules.conf Contains configurationparameters for your kernel modules.

etc/passwd Contains your system user accounts. /etc/shadow Contains encrypted passwords for

your user accounts. /etc/X11/ Contains configuration files for X

Windows

Page 11: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 11/33

/opt: This directory contains files for some programs youinstall on the system.

/root: This directory is the root user’s home directory.

Notice that it is located separately from the homedirectories for other users in /home.

/srv: This directory contains subdirectories where servicesrunning on the

system (such as httpd and ftpd) save their files.

/sys:This directory contains information about thehardware in your system.

/tmp: This directory contains temporary files created byyou or by the system.

Page 12: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 12/33

/usr: This directory contains application files. In fact, mostof the application files used on your system are saved in asubdirectory of /usr.

/var: This directory contains a variety of variable data,including your system log files.

Subdirectory Contents lib : Library files created by various services and

applications running on the system log : Log files from your system and from services

running on the system

spool : Print queues

Page 13: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 13/33

/home: This directory contains subdirectories that serve ashome directories for each user account on your Linuxsystem.

■ /lib: This directory contains code libraries used byprograms in /bin and /sbin. Your kernel modules are alsostored in the modules subdirectory of /lib.

■ /media: This directory is used by some Linuxdistributions (such as SUSELinux) to mount external

devices, including CD drives, DVD drives, and floppydrives.

■ /mnt: This directory is used by some Linux distributions(such as Fedora or Red Hat) to mount external devices,

including CD drives, DVD drives, and floppy drives.

Page 14: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 14/33

This is the act of putting files, folders, andsub-programs in specific known places,linking them and enabling them to

communicate, for the proper function of aprogram unit or system. Prerequisites may be needed to install

programs There are two basic forms of installation in

Linux The binary installation The source code installation

Page 15: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 15/33

Program to be installed usually comes in aprecompiled package containing all the neededdata

it is usually in object code which is moreunderstandable to computers

it is usually installed by another type of programcalled a package manager

It is usually in a particular format that thepackage manager can understand e.g. rpm, bin

It is relatively easy to install as it places different

data in specific default locations

Page 16: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 16/33

software management tools for downloading,installing and configuration of additionalsoftware packages for your system

Software comes mostly precompiled bundled inpackages, hence the name package manager.

The package manager can resolvedependencies between packages automatically.

The package manager can also update the

system without operator interaction.Installs packagesremoves packagesconfigures packages

keeps track of the installed packages using a database

Page 17: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 17/33

Default package manager for RHEL5  Other packet managers include Yum,

dpm(apt,dpkg) The default format of binary packages is the

.rpm format It is installed by typing the command

rpm  –ivh rpmname.rpm

Some rpms require prerequisites to install

Page 18: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 18/33

Relatively more difficult Requires more manual attention

It contains a lot of shell scripts, files, foldersand involves configuration that is moreunderstandable to human beings and less tocomputers

Requires a program called compiler totranslate the source code to object code.

Page 19: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 19/33

Program specifically to translate source code It is the main prerequisite to be installed

before a source code installation can beperformed Example gcc, g++

Page 20: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 20/33

Performed in the last class

Page 21: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 21/33

This can be done using the rpmbuild –bbcommand

Some source codes come with a specificationfile (.spec) prereq

Page 22: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 22/33

Variables are a way of passing informationfrom the shell to programs when you run

them. Programs look "in the environment" for

particular variables and if they are found willuse the values stored

Some are set by the system, others by you,yet others by the shell, or any program thatloads another program.

Page 23: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 23/33

variables are split into two categories,environment variables and shell variables

In broad terms, shell variables apply only to

the current instance of the shell and are usedto set short-term working conditions. Theyusually have lower case names.

environment variables have a fartherreaching significance, and those set at loginare valid for the duration of the session. They

have UPPER CASE names

Page 24: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 24/33

An example of an environment variable is theOSTYPE variable. The value of this is the currentoperating system you are using. Typeecho $OSTYPE

More examples of environment variables are

USER (your login name) HOME (the path name of your home directory)

HOST (the name of the computer you are using) ARCH (the architecture of the computersprocessor)

PATH (the directories the shell should search tofind a command)

Page 25: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 25/33

ENVIRONMENT variables are: set using the setenv command

displayed using the printenv or envcommands, and unset using the unsetenv command.

To show all values of these variables, typeprintenv | less

Page 26: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 26/33

An is the history variable. The value of this ishow many shell commands to save, Typeecho $history

More examples of shell variables are cwd (your current working directory) home (the path name of your home directory) path (the directories the shell should search to

find a command) prompt (the text string used to prompt for

interactive commands shell your login shell)

Page 27: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 27/33

SHELL variables are both set and displayedusing the set command. They can be unset by

using the unset command. To show all values of these variables, type

set | less

Page 28: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 28/33

In general, environment and shell variables that havethe same name (apart from the case) are distinct andindependent, except for possibly having the sameinitial values. There are, however, exceptions.

Each time the shell variables home, user and term arechanged, the corresponding environment variablesHOME, USER and TERM receive the same values.However, altering the environment variables has no

effect on the corresponding shell variables. PATH and path specify directories to search for

commands and programs. Both variables alwaysrepresent the same directory list, and altering either

automatically causes the other to be changed.

Page 29: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 29/33

Each time you login to a UNIX host, the system looks in your homedirectory for initialisation files. Information in these files is used toset up your working environment. The C and TC shells uses twofiles called .login and .cshrc (note that both file names begin with adot).

At login the C shell first reads .cshrc followed by .login  .login is to set conditions which will apply to the whole session

and to perform actions that are relevant only at login. .cshrc is used to set conditions and perform actions specific to the

shell and to each invocation of it. The guidelines are to set ENVIRONMENT variables in the .login 

file and SHELL variables in the .cshrc file. WARNING: NEVER put commands that run graphical displays

(e.g. a web browser) in your .cshrc or .login file.

Page 30: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 30/33

Setting shell variables in the .cshrc file For example, to change the number of shell

commands saved in the history list, you need to setthe shell variable history. It is set to 100 by default, but

you can increase this if you wish. % set history = 200 Check this has worked by typing % echo $history However, this has only set the variable for the lifetime

of the current shell. If you open a new xterm window,it will only have the default history value set. ToPERMANENTLY set the value of history, you will needto add the set command to the .cshrc file.

Page 31: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 31/33

Page 32: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 32/33

Setting the path When you type a command, your path (or PATH)

variable defines in which directories the shell will lookto find the command you typed. If the system returns

a message saying "command: Command not found",this indicates that either the command doesn't existat all on the system or it is simply not in your path.

For example, to run units, you either need to directlyspecify the units path (~/units174/bin/units), or youneed to have the directory ~/units174/bin in yourpath.

You can add it to the end of your existing path (the$path represents this) by issuing the command:

Page 33: Introduction to Linux- Lesson 4

8/4/2019 Introduction to Linux- Lesson 4

http://slidepdf.com/reader/full/introduction-to-linux-lesson-4 33/33

set path = ($path ~/units174/bin) Test that this worked by trying to run units in

any directory other that where units isactually located.

cdunits

To add this path PERMANENTLY, add thefollowing line to your .cshrc AFTER the list of other commands.

set path = ($path ~/units174/bin)