Вы находитесь на странице: 1из 44

Introduction

19/06/17 Introduction - Linux Training 1/42


Outline
Introduction to Linux
Linux File System
Linux Basic Commands

19/06/17 Introduction - Linux Training 2/42


A brief history of Linux OS

The problem between the 1980 and 1990


expensive UNIX Operating System
inexpensive Personal Computers(PC)

Explode research into a system similar to UNIX


running on PC
In 1991, Linus Torvalds led the creation of an OS similar to UNIX
and publish it on Internet with name Linux
this became an important open source project people were able
to obtain it freely and develop applications to improve it the way it
was license also deprived people from claiming ownership.

19/06/17 Introduction - Linux Training 3/42


What is Linux Distribution?

Linux OS = core (kernel) + no. of applications this


means even if you get the core (kernel), you still
require to get additional applications.
Note: Although, additional application is free, it was
difficult getting them. (download!!)
Linux Distribution = Kernel + all additional applications

normally on CD or DVD

commercial companies do provide unique additional application
Obtaining Linux OS does not require a license fee.

no pirated copies!
19/06/17 Introduction - Linux Training 4/42
Terminology

Linux Kernel:
provide a technology to interact with computer hardware.

Linux Operating System:


kernel, installation and configuration programs

Linux Distribution:
kernel, needed components to make up the OS and enough
application to create full working environment.

Linux Server:
no clear definition, but normally a stable and reliable platform for
mission critical services.

Desktop:
User Desktop system with ease_to_use applications that takes
advantage of the computers full power.
19/06/17 Introduction - Linux Training 5/42
Difference between Linux & Windows

Linux is case sensitive:


lower-case and upper-case are not the same

e.g. hello.txt Hello.txt

Slash instead of Backslash


in windows backward slash is use (\) but Linux (/)

In Linux there are no device characters


In windows hard disk is C:

There are no EXE file in Linux


In Linux executable files do not have .exe instead
executable permission is set.

In Linux Graphical User interface Is not part of OS


No GUI in Linux stability, performance and flexibility

19/06/17 Introduction - Linux Training 6/42


Linux Kernel

The Kernel by Tolvards became public


Rapid development of Linux OS
Was developed under GNU-GPL

Kernel Types:
Mach kernel(BSD), GNU Hurd Kernel, Linux kernel

Kernel Functions:
Input & output control
Device control
Process management
File management, etc...
19/06/17 Introduction - Linux Training 7/42
Multi-user Environment

Like Unix, Linux is also a multi-user OS

Multi-user capability Multitasking

Normal Situation:
Multiprocessor --> multi-user + multitasking

Unix & Linux uses a pre-emptive strategy to implement


multitasking.

Why?
A non-pre-emptive strategy can lead to a deadlock situation.

19/06/17 Introduction - Linux Training 8/42


Important Terms

Program: exist only once in a system


Process: started by a program


Thread: several can be started by a process


Multi-threading: several threads co-existing.

19/06/17 Introduction - Linux Training 9/42


Linux Distro for Hackers

Kali Linux:
debian-based distro for forensics and penetration testing.

BackBox
Ubuntu-based distro for security assessment and pentration testing.

CAINE
Ubuntu-based GNU/Linux live distribution created as a project of digital
forensics
BlackArch/ArchAssault
Arch-based GNU/ Linux distribution for pentesters and security researchers
Pentoo:
Pentoo is a security-focused livecd based on Gentoo

19/06/17 Introduction - Linux Training 10/42


Other Linux Distros
Distro Where to obtain it

Debian www.debian.org

Redhat www.redhat.com

Suse www.novell.com

CentOS www.centos.org
...

Choice of a distribution over the other varies
Single important choice of Vendor over stock Linux - time

Downloading time

Installation time

Learning time

Quality assurance time
19/06/17 Introduction - Linux Training 11/42
File System and Commands

19/06/17 Introduction - Linux Training 12/42


File System Hierarchy Standard (FHS)

FHS is a De-facto file hierarchy standard for


Linux OS

FHS Characteristic
FHS is becoming a standard
FHS specify directory directly under /
Makes working on Unix and Linux easy
All directory specified need not be on one machine.
FHS is not concern about directory content

19/06/17 Introduction - Linux Training 13/42


File System Hierarchy Standard

Root directory (/)


System Binaries (/sbin)

Essential binaries (/bin)


Data directories for services (/srv)

Boot directory (/boot)


Temporary directory (/tmp)

Device Files (/dev)


The hierarchy below (/usr)

Configuration File (/etc)


Variable Files (/var)

User directory (/home)


Process Files (/proc)

Libraries (/lib) System information diretory (/sys)


Mount points for Removable media (media)



Temporary mountpoint (/mnt)

Application directory (/opt)

Root home (/root)

19/06/17 Introduction - Linux Training 14/42


Example Typical Directory Structure

19/06/17 Introduction - Linux Training 15/42


FHS Directories

/ root

Where all file system begins

Must be mounted before booting!!

/bin Essential binaries



Contains common programs run by both normal and
admin. Users

eg. cd, ls, bash, etc...

/boot Boot directory



Contains all files needed to boot the system except
configuration files not needed for booting.

Where the kernel lives
19/06/17 Introduction - Linux Training 16/42
FHS Directories 2

/dev dev directory



Contains device and special files

NB: in Linux everything device is a file

We have two types of device files

Major device file : main driver for the device (disk)

Minor device file : drivers for various partition on the disk

For example try: ls -l /dev/hda*

Serial port : /dev/ttyS*

Parallel port : /dev/lp*

Usb port : /dev/usb7lp*

IDE tape drive: /dev/ht*

19/06/17 Introduction - Linux Training 17/42


FHS Directories 3

/etc configuration directory



Contains system configuration files(cf)

cf is a local file use to control a program

Files are in ASCII format

Normal users can view almost all the files

Examples:

/etc/X11 configuration files for the X-Server

/etc/samba configuration files for samba server

/etc/sysconfug/network contains network configuration files

/etc/passwd contains users configuration info.

/etc/shadow contains user password information

/etc/group contains group information

19/06/17 Introduction - Linux Training 18/42


FHS Directories 4

/home home directory



By default all individual users home are created within
this directory.

User home directory - /home/$USER (~/)

Hidden files files names beginning with (.)

It also contains personal configuration files


Examples :

.bashrc bash configuration file

.bash_history contains history of all commands typed in bash
shell.

19/06/17 Introduction - Linux Training 19/42


FHS Directories 5

/lib library directory



Contains shared libraries for programs

This can be compared to dll in windows

The library have (.so) extensions

/media media mount directory



Use to mount removable devices

cd-rom, dvd, usb sticks, etc.

/sys System Information directory



Contains information on various devices such as hardware
buses, hardware devices, etc..

19/06/17 Introduction - Linux Training 20/42


FHS Directories 6

/mnt temporary mount directory



A generic mount point for filesystems and media

Note: it is used to mount only temporal filesystems.

/tmp temporary directory



All temporary files are kept here

/srv service data directory



Contains sub-directories with service data for ftp, http,

19/06/17 Introduction - Linux Training 21/42


FHS Directories 7

/sbin System binary directory



Contains all programs run by System Administration

Some of the command found here are:

reboot

route

mkfs, etc...

/var variable directory



Contains information generated during system run

Some are shareable other are not

Examples: /var/log/, /var/lock, /var/lib, etc...

19/06/17 Introduction - Linux Training 22/42


FHS Directories 8

/usr user directory



Contains all user binaries, libraries , header files, their
documentation, etc..

? not in /bin, bin is distribution specific

Initially all user's home directories were in /usr

Examples:

/usr/bin user binaries

/usr/lib libraries for the programs kept here

/usr/src source files for programs

/usr/share/doc program documentation

/usr/share/man manual pages

/usr/share/info info pages

/usr/local locally installed program related files
19/06/17 Introduction - Linux Training 23/42
Linux Basic Commands

19/06/17 Introduction - Linux Training 24/42


Basic File and Directory Command

ls command: is used to display specified files or directory content.

It can also be used to get more information about files such as


- file type
- creation date & time
- file owner and owner's group, etc...

Exercise: Start virtual terminal 1 Ctrl+Alt+F1 and login with username & password
1.) type ls
2.) type ls /etc (list the content of /etc)

Options:

- None : display the content of current directory in columns


-l : display a detail information of files & directories
-F : display the file type
-a : display all hidden files

19/06/17 Introduction - Linux Training 25/42


Basic File and Directory Command 2
Typically ls is aliased to color_ls --> /etc/DIR_COLORS
This enable file identification without ls

Color Scheme Default suffix scheme

Blue --> directories Nothing --> regular file

Red --> compressed files / --> directory

White -->text files * --> executable

Pink --> image


@ -- > links

Cyan ---> links


= --> socket

Yellow --> device


| --> named pipe

Green --> executables

19/06/17 Introduction - Linux Training 26/42


Changing directory
cd command: used to change between directories

Variant:

- cd : changes directory to home


- cd . : points to the current directory
- cd .. : moves to the parent directory
- cd - : moves to the last valid directory
- cd ../.. : move to two directory level higher

19/06/17 Introduction - Linux Training 27/42


Text File creation

touch command: is use to create file


touch can also be use to modify file properties

Options:

-a : change the access time only

-m : change modification time

-c : does not create file if file do not exist

Examples:

touch file1

touch file2, file3. files 4

touch /tmp/file4

19/06/17 Introduction - Linux Training 28/42


View File content

cat command: use to view the content of a file


default output medium is the monitor
can be use to redirect output to other file
Examples:

cat file1

cat file2

cat /tmp/file4

cat file1 file10

cat file2 > file11

more command: use to display the content of the file


at once.
19/06/17 Introduction - Linux Training 29/42
View File content 2

less command: use to display the content of a file


one page/ a window at a time
gives you the ability to navigate through the file keystrokes.

the way it works with keystrokes:


for navigation use the direction keys

b : moves one tip mask

such through the file using
/ : search forward
? : search backwards
n for next

19/06/17 Introduction - Linux Training 30/42


Head & Tail commands
head command:
enables you to view the first few lines in a text file
tail command:
enables you to view the last few lines in a text file
BUT! tail gives more
can allow you to view the last few lines continuous
mode with option (-f)
Syntax for both is
command [option] filename

19/06/17 Introduction - Linux Training 31/42


Operations on Files

cp command:
cp is use to copy file(s) and directories
cp will normally overwrite existing file

Syntax:
cp fromfile tofile

Options:
-i : interactive copying
-r /R: use for recursive copying
-s : us to create a symbolic links
-p : preserve ownership
19/06/17 Introduction - Linux Training 32/42
Operations on Files 2

mv command:
mv is use to move file(s) and directories
mv will normally overwrite existing file

Syntax:
mv currentposition newposition

Options:
-i : interactive moving
-f : non interactive moving
19/06/17 Introduction - Linux Training 33/42
Directory operations

mkdir command:
is use to create a directory
-p : use to create parent directories as when needed.

Syntax:
mkdir new_directory_name

rm command:
is use to delete files and directories
with (-r) option you can delete recursively
rmdir is use to delete empty
19/06/17 Introduction - Linux Training 34/42
Link files

A link refer to a physical file on harddisk

soft link
has own inode number
point to the inode of the original file
delete the original file link is lost
ln -s original_file softlink_file

hard link
uses the inode of the original file
delete the original file the link still works
any update affects the original file
ln original_file hlink_file_name
19/06/17 Introduction - Linux Training 35/42
Regular Expressions Basics
Used in many programs to express patterns in text
Very useful for searching for patterns
Two forms simple and extended
Use depends on the program
Extended:
Bracket expression: use to match any of the characters
within the bracket. e.g [abc] / b[aeiou]g
Range expression: use to list start and end of range eg.
a[2-4]z

19/06/17 Introduction - Linux Training 36/42


Regular Expressions Basics -2
Extended:
Any single character: the dot (.) use to represent any
character except newline. eg. a.z
Start and end of line: the carat (^) represent start of line
and ($) denotes end of line
Repetition operators: (*) denotes zero or many
occurrences and (+) denotes one or many occurrences.
Parentheses: ( ) use to surround subexpressions.
Escapeing: (\) use to specify special characters like ?, +, |
etc...
19/06/17 Introduction - Linux Training 37/42
Finding files

The following commands will be treated


find


which


type


whereis

19/06/17 Introduction - Linux Training 38/42


Finding files 2

find command:
searches one or more directories for files matching certain
criteria

Syntax
find path option(s)

Options:
-name file_name (*,?,[]) are applicable
-type file_type (f,d,s,l, etc..)
-user owner_name
-group group_name
-ctime [-/+] days
-exec command
19/06/17 Introduction - Linux Training 39/42
Finding files 3

Example
find /home -type f -name file_1

searches through /home and its sub-directories file_1

find ~ -type d -name Documents



searches the home directory of the user login for directory
Documents

find ~ -name letter -type f -exec cat {} \;



searches user home for file letter pass it as an argument
to command cat to display the the content
19/06/17 Introduction - Linux Training 40/42
Finding command files

whereis command:
attempt to find (-s)source, (-m)manual page, (-b) binaries of specified
command

Syntax:
whereis [option(s)] command

Example:
whereis ls
whereis cat
whereis -b ifconfig
Exercise: (TRY)where can you find the binaries of route?
19/06/17 Introduction - Linux Training 41/42
Finding command file 2

which command:
specify the version which is run when command is type
search for command using PATH environment variable

Syntax:
which command

Example:
which ls
which cat
which ifconfig
19/06/17 Introduction - Linux Training 42/42
Finding command file 3

type command:
shows whether a command is shell built-in or from an external
source

Syntax:
type command

Example:
type ls
type cd
type type
type which
19/06/17 Introduction - Linux Training 43/42
Search file content

grep command:
use to search for a pattern in a file or list of files without
opening them.
pattern can be a keyword or a phrase.

Syntax:
grep [option(s)] pattern file_name
Options:

(-i) if you want to ignore state

(-v) print out lines that do not contain the pattern

(-n) show line numbers

(-L) file that do not contain the pattern
19/06/17 Introduction - Linux Training 44/42

Вам также может понравиться