0% found this document useful (0 votes)
19 views29 pages

LPI101 Notes Day 1

Uploaded by

pou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views29 pages

LPI101 Notes Day 1

Uploaded by

pou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

LPI 101

Module 0: Introduction

Introduction

● LPI
● LPIC-1
● Linux+
● Certification
● LPI 101
● Timetable
● Skytap

Linux Professional Institute (LPI)

“The Linux Professional Institute Inc. (LPI) is a non-profit


organization that provides vendor-independent professional
certification for Linux system administrators and
programmers.

The Linux Professional Institute Certifications (LPIC)


provide a qualification that can be used to indicate that
someone is competent at a certain level.”
LPI Courses

● Linux Essentials

● LPIC-1

● LPIC-2

● LPIC-3

LPIC-1
● Earned by passing two exams
○ LPI-101
○ LPI-102
● Focuses on general usage of core system
and utilities
○ Later courses focus much more specialised
applications, network services etc.
● Holders of LPIC-1 are eligible to skip the entry level
Suse Linux Enterprise (SCA) exam and certify directly
at SCE level

Linux+

● Earned by passing two exams


○ LX0-103
○ LX0-104
● The exam objectives for Linux+ are the
same as those for LPI
● Candidates who achieve Linux+ certification
are eligible to apply for LPIC-1
Linux Training Programmes

LPI 101

● This course will address the objectives for


the LPI 101 Exam
● The LPI courses are not specific to any
Linux distribution, but this course will focus
mostly on CentOS for examples and
exercises
○ Some tasks will use Ubuntu

Updated LPI Objectives

● The LPI objectives are updated every few years


● The current objectives are version 4
● Version 5 is in beta and will launch later this year.
○ The changes are listed on the page
https://wiki.lpi.org/wiki/LPIC-1_Summary_Version_4.0_To_5.0
● This course will cover both the current and future
objectives.
○ New objectives are noted in green
○ Objectives for removal are marked in red
Timetable

Monday Command Line Tools & Working with Files

Tuesday Filesystems & Permissions

Wednesday System Boot, Software & File Management

Thursday Hardware & Performance

Friday Virtualization
Install Lab
Certification Review
Q&A

Materials

● Slides will be provided for


each session
● Recommended Manual
○ CompTIA Linux+ Powered by
Linux Professional Institute
Study Guide: Exam LX0-103
and Exam LX0-104 , 3rd
Edition

Skytap

● A cloud based lab environment is provided


for the duration of the course
● A unique URL will be provided for each
student
LPI 101
Module 1: Command Line Tools & Working with
Files

Module Objectives

● 103.1 Work on the command line


● 103.4 Use streams, pipes and redirects
● 103.2 Process text streams using filters
● 103.3 Perform basic file management
● 103.7 Search text files using regular expressions

Module 1

103.1 Work on the


command line
Bash Shell

Shell Environment

● env
● echo
● export
● set
● unset

Shell Environment

[andrew@pc ~]$ echo $PATH

/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/b
in:/usr/local/sbin:/usr/sbin:/sbin:/home/andrew/
bin
Shell Environment
[andrew@pc ~]$ echo $PATH | tr ':' '\n'
/usr/lib64/qt-3.3/bin
/usr/local/bin
/bin
/usr/bin
/usr/local/sbin
/usr/sbin
/sbin
/home/andrew/bin

Shell Environment type ~= which


[andrew@pc ~]$ type bash
bash is /bin/bash

[andrew@pc ~]$ which bash


/bin/bash

Shell Environment

[andrew@pc ~]$ export CLASS=lpi101


[andrew@pc ~]$ echo $CLASS
lpi101
[andrew@pc ~]$ unset CLASS
[andrew@pc ~]$ echo $CLASS

[andrew@pc ~]$
Shell Environment

● cd
● pwd

Commands

command [options]

command [options] file

command [options] sourcefile destinationfile

Files
[andrew@pc ~]$ ls -l example.txt
-rw-rw-r--. 1 andrew andrew 0 Nov 18 22:03 example.txt

[andrew@pc ~]$ ls -l ./example.txt


-rw-rw-r--. 1 andrew andrew 0 Nov 18 22:03 ./example.txt

[andrew@pc ~]$ ls -l ~/example.txt


-rw-rw-r--. 1 andrew andrew 0 Nov 18 22:03 /home/andrew/example.txt

[andrew@pc ~]$ ls -l /home/andrew/example.txt


-rw-rw-r--. 1 andrew andrew 0 Nov 18 22:03 /home/andrew/example.txt
Filenames

Never Use: *, ?, /, \, “

Best Practice:
● Use lowercase only
● Avoid spaces
● Use dashes (-), underscores (_) and dots (.)

Shell Environment

● history
● ~/.bash_history

● Tab Completion

Documentation

● man
● info
● /usr/share/doc
Man Categories

1 User Programs ls(1), cp(1), mv(1)

2 System calls provided by the Kernel open(2), poll(2), wait(2)

3 Library Calls cos(3), strlen(3),

4 Device files sd(4), fd(4), lp(4)

5 File formats crontab(5), fstab(5), inittab(5)

6 Games sol(6), four-in-a-row(6), gnome-chess(6)

7 Miscellaneous man(7), regex(7), signal(7)

8 Admin Programs fsck(8), shutdown(8), yum(8)

Online Documentation

● serverfault.com etc.
● Vendor Documentation
● The Linux Documentation Project (tldp.org)
● Google

uname (1)
uname - print system information, eg,

[andrew@pc ~]$ uname


Linux

[andrew@pc ~]$ uname -a


Linux pc.example.com 4.2.3-200.fc22.x86_64 #1 SMP
Thu Oct 8 03:23:55 UTC 2015 x86_64 x86_64 x86_64
GNU/Linux
Module 1

Exercise 1

Review: Objective 103.1


● Use single shell commands and one line command
sequences to perform basic tasks on the command line.
● Use and modify the shell environment including
defining, referencing and exporting environment
variables.
● Use and edit command history.
● Invoke commands inside and outside the defined path.

Review: Objective 103.1

● bash ● set
● echo ● unset
● env ● man
● export ● uname
● pwd ● history
● type ● .bash_history
● which ● Quoting
Module 1

103.4 Use streams, pipes


and redirects

Streams

Stream File Descriptor Description

stdin 0 Standard Input

stdout 1 Standard Output

stderr 2 Standard Error (Output)

Redirection Operators

Operator Effect

> Redirect stdout. Overwrite any existing file.

>> Append stdout to a file

2> Redirect stderr. Overwrite any existing file.

2>> Append stderr to a file

&> Redirect both streams. Overwrite any existing file.

&>> Append both streams to a file (introduced in Bash 4)

< Use the contents of a file as stdin


Redirection Operators

[andrew@pc ~]$ echo $PATH > path.txt

[andrew@pc ~]$ cat path.txt

/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/b
in:/usr/local/sbin:/usr/sbin:/sbin:/home/andrew/
bin

Pipes

While redirection operators work with files,


pipes allow for the output of a command to be
used as the input to the next, eg

ls /home | grep ‘*.txt’


cat /etc/hosts | sort

tee (1)

tee - read from standard input and write to


standard output and files, eg,

ls /home | tee homes.txt


xargs (1)

xargs - build and execute command lines from


standard input

xargs [options] [command [initial-arguments]]

Command Substitution
Command substitution allows the output of a
command to replace the command itself.

Command substitution occurs when a command is enclosed as:


$(command)
or

`command`

Escape Characters

Character Description

\ Interpret next character as its ASCII equivalent

“...” Interpret all characters between the quotes as ASCII characters


except: $ ` \

‘...’ Interpret all characters between the quotes as ASCII


characters
Review: Objective 103.4

● Redirecting standard input, standard output and standard error.


● Pipe the output of one command to the input of another command.
● Use the output of one command as arguments to another
command.
● Send output to both stdout and a file.

Review: Objective 103.4

● Redirection Operators
● tee
● xargs

Module 1

103.2 Process text


streams using filters
Text Processing

● less
● more
● cat

Text Processing

● head
● tail
■ -f, follow
■ -n, number of lines
■ -n +X, start at line number X

wc (1)

wc - print newline, word, and byte counts for each file

[andrew@pc ~]$ wc /usr/share/doc/systemd/README


198 772 7174 /usr/share/doc/systemd/README

Lines Words Bytes


wc (1)
[andrew@pc ~]$ wc -l /usr/share/doc/systemd/README
198 /usr/share/doc/systemd/README

[andrew@pc ~]$ wc -w /usr/share/doc/systemd/README


772 /usr/share/doc/systemd/README

[andrew@pc ~]$ wc -c /usr/share/doc/systemd/README


7174 /usr/share/doc/systemd/README

sed (1)

sed - stream editor for filtering and transforming


text, eg,

sed ‘s/old/new/’ example.txt

sed -i ‘s/old/new/’ example.txt

sed ‘/old/d’ example.txt

awk (1)

awk - pattern scanning and processing


language, eg,

awk ‘{print $2, $1}’ example.txt


ifconfig | awk '/inet/ {print $2}'
tr (1)

tr - translate or delete characters, eg,

echo $PATH | tr ':' '\n'


tr ‘[:upper:]’ ‘[:lower:]’
tr -d ‘\n’

sort (1)

sort - sort lines of text files


■ -f, Ignore Case
■ -n, Numeric
■ -h, Human Numeric Sort
■ -r, Reverse

uniq (1)

uniq - report or omit repeated lines

■ -c, count
■ -d, only print duplicates
■ -u, only print unique lines
Checksums

[andrew@pc ~]$ md5sum /usr/share/doc/systemd/README


bf28afcb8b8cac317448c77424441cce /usr/share/doc/systemd/README

[andrew@pc ~]$ sha1sum /usr/share/doc/systemd/README


9e8de8acb143aa1d93d05ff2c27fa85cefcb673d /usr/share/doc/systemd/README

[andrew@pc ~]$ sha256sum /usr/share/doc/systemd/README


1bdc511b64e4074a3721ed9a6900d51cd34eb6a26a548642aad9cf499db9b4e5 /usr/share/doc/systemd/README

[andrew@pc ~]$ sha512sum /usr/share/doc/systemd/README


b81ad86f3ae24bd473d3626399383da45cbd80ec3f23a2c0838e388d5bd7182737155f83e7de26fd1ba9daab7a53614489c84bfb137903f9fbc55b0a9c5876b0 /usr/share/doc/systemd/README

■ -c, count
■ -d, only print duplicates
■ -u, only print unique lines
Text Processing
● tac: cat in reverse
● nl: number lines of files
● od: dump files in octal and other formats
● paste: merge lines of files
● split: split a file into pieces
● cut: remove sections from each line of files
● expand: convert tabs to spaces
● unexpand: convert spaces to tabs
● fmt: simple optimal text formatter
● join: join lines of two files on a common field
● pr: convert text files for printing

Exercise 2
Review: Objective 103.2

Send text files and output streams through text utility


filters to modify the output using standard UNIX
commands found in the GNU textutils package.

Review: Objective 103.2

● cat ● nl ● split
● cut ● od ● tail
● expand ● paste ● tr
● fmt ● pr ● unexpand
● head ● sed ● uniq
● join ● sort ● wc
● less

Module 1

103.3 Perform basic file


management
File Management

● ls
■ -l, List
■ -ld, List Directory
■ -la, List all (show hidden)

● file

Filename Expansion - Globbing

ls *.txt

ls ???.txt
ls [abc].txt
ls [a-z].txt

ls {a,z}.txt

find (1)

find - search for files in a directory hierarchy


■ -iname, Name (case insensitive)
■ -user, User
■ -type
○ f, File
○ d, Directory
find (1)

examples:

find /home/andrew -iname “*.txt”


find / -user jim
find / -mtime 0

File Management

● touch
● mkdir
■ mkdir -p (make all directories on path)

File Management
● cp
■ cp -a (archive)

● mv
● rm
■ rm -rf (recursive, force)

● rmdir
File Compression

● gzip, gunzip
● bzip2, bunzip2
● xz, unxz
● zcat, bzcat, xzcat etc.
○ zmore, zless, zgrep etc.

tar (1)

tar - an archiving utility, eg,

tar -cvvf archive.tar /directory


tar -czvvf archive.tar.gz /directory

tar -xf archive.tar

dd (1)

dd - convert and copy a file, eg,

dd if=centos.iso of=/dev/sdb

dd if=/dev/zero of=/dev/sda count=1024


bs=1024
Exercise 3

Review: Objective 103.3

● Copy, move and remove files and directories individually.


● Copy multiple files and directories recursively.
● Remove files and directories recursively.
● Use simple and advanced wildcard specifications in commands.
● Using find to locate and act on files based on type, size, or time.
● Usage of tar, cpio and dd.

Review: Objective 103.3

● cp ● rmdir ● file
● find ● touch ● gzip
● mkdir ● tar ● gunzip
● mv ● cpio ● bzip2
● ls ● dd ● bunzip2
● rm ● globbing ● xz
● unxz
Module 1

103.7 Search text files


using regular expressions

grep (1)

grep - print lines matching a pattern

■ -R, recursive
■ -i, Case Insensitive
■ -L, Show files that match
■ -c, Count matches
■ -q, Quiet

Extended Regular Expressions

● Use the -E option with grep (or egrep) to use the extended regular
expression syntax

Grep understands three different versions of regular expression syntax: “basic,” “extended” and “perl.”
In GNU grep, there is no difference in available functionality between basic and extended syntaxes.
In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning;
instead use the backslashed versions \?, \+, \{, \|, \(, and \).
Traditional egrep did not support the { meta-character, and some egrep implementations support \{
instead, so portable scripts should avoid { in grep -E patterns and should use [{] to match a literal {.
GNU grep -E attempts to support traditional usage by assuming that { is not special if it would be the
start of an invalid interval specification. For example, the command grep -E '{1' searches for the
two-character string {1 instead of reporting a syntax error in the regular expression. POSIX allows this
behavior as an extension, but portable scripts should avoid it.
Regular Expressions

● The fundamental building blocks are the regular


expressions that match a single character. Most
characters, including all letters and digits, are regular
expressions that match themselves. Any meta-character
with special meaning may be quoted by preceding it
with a backslash.

● The period . matches any single character.

Character Classes & Bracket Expressions

● A bracket expression is a list of characters enclosed


by [ and ]
● It matches any single character in that list
○ if the first character of the list is the caret ^ then it matches any
character not in the list.
● Within a bracket expression, a range expression
consists of two characters separated by a hyphen, eg,
○ [a-k]
○ [a-zA-z]
○ [0-9]

Character Classes & Bracket Expressions

● certain named classes of characters are predefined


within bracket expressions, as follows. [:alnum:],
[:alpha:], [:cntrl:], [:digit:],
[:graph:], [:lower:], [:print:],
[:punct:], [:space:], [:upper:],
and [:xdigit:].
Anchoring

● The caret ^ and the dollar sign $ are


meta-characters that respectively match the
empty string at the beginning and end of a
line.

Repetition

A regular expression may be followed by one of


several repetition operators:
● ? The preceding item is optional and matched at most once.
● * The preceding item will be matched zero or more times.
● + The preceding item will be matched one or more times.
● {n} The preceding item is matched exactly n times.
● {n,} The preceding item is matched n or more times.
● {,m} The preceding item is matched at most m times.
● {n,m} The preceding item is matched at least n times, but not more than m
times.

Regular Expressions

● regexes
■ Bracket: [aeiou]
■ Range: [a-z]
■ Start: ^
■ End: $
■ Or: |
■ Repetition: ?, +
sed(1)

The same regex syntax can be used with sed,

sed 's/gr[ae]y/blue/'
sed 's/[[:digit:]]/X/'

Module 1

Exercise 4

Review: Objective 103.7

● Create simple regular expressions containing several notational


elements.
● Understand the differences between basic and extended regular
expressions.
● Understand the concepts of special characters, character classes,
quantifiers and anchors.
● Use regular expression tools to perform searches through a
filesystem or file content.
● Use regular expressions to delete, change and substitute text.
Review: Objective 103.7

● grep
● egrep
● fgrep
● sed
● regex(7)

You might also like