0% found this document useful (0 votes)
80 views

Linux Fun

The document provides an overview of the Linux operating system. It describes Linux as a fully-networked, multi-user, multi-tasking operating system that includes Unix tools, compilers, and network tools. It can run on multiple hardware platforms and includes open source code. Users can obtain Linux by downloading distributions from the Internet that package the Linux kernel with graphical and server software as well as installation tools. The document notes Linux's growing popularity for its speed, stability, and free licensing. It closes by reviewing Linux's dominance in web serving.

Uploaded by

Shady Mohamed
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)
80 views

Linux Fun

The document provides an overview of the Linux operating system. It describes Linux as a fully-networked, multi-user, multi-tasking operating system that includes Unix tools, compilers, and network tools. It can run on multiple hardware platforms and includes open source code. Users can obtain Linux by downloading distributions from the Internet that package the Linux kernel with graphical and server software as well as installation tools. The document notes Linux's growing popularity for its speed, stability, and free licensing. It closes by reviewing Linux's dominance in web serving.

Uploaded by

Shady Mohamed
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/ 72

Linux Fundamentals

0
Prepared by: Eng. Anwar Fouad NTI
What is Linux?

A fully-networked 32/64-Bit Unix-like Operating System


 Unix Tools Like sed, awk , find, and grep (explained later)
 Compilers Like C, C++, Fortran, …etc.
 Network Tools Like telnet, ftp, ping, traceroute

Multi-user, Multitasking, Multiprocessor


Has the X Windows GUI
Coexists with other Operating Systems
Runs on multiple hardware platforms
Includes the Source Code

4
Prepared by: Eng. Anwar Fouad NTI
How do you get it?

Download it from the Internet


From a ―Distribution‖ (e.g. Red Hat)
 Linux kernel
 X Windows system and GUI
 Web, e-mail, FTP servers
 Installation & configuration support
 3rd party apps
 Hardware support

7
Prepared by: Eng. Anwar Fouad NTI
Popular Linux Distributions

8
Prepared by: Eng. Anwar Fouad NTI
Why is it significant?

Growing popularity
Powerful
 Runs on multiple hardware platforms
 Users like its speed and stability
 No requirement for latest hardware
It‘s ―free‖
 Licensed under GPL
 Vendors are distributors who package Linux

9
Prepared by: Eng. Anwar Fouad NTI
Linux’s place in the market

Impacts:
 Applications:
 Web servers (65%)
 Web Infrastructure (mail, DNS) (15%)
 File/Print (15%)
 DB & DB Applications (2%)
 Observations
 Linux/Apache share of Web serving high
 Many SMB and small ISP
 Strong mindshare among developers

Update : w3techs.com

12
Prepared by: Eng. Anwar Fouad NTI
NTI

The Linux Operating System


Linux Concepts
Linux Fundamentals
The Linux Operating System

User commands includes executable programs


and scripts

The shell interprets user commands. It is Utilities (User commands)


responsible for finding the commands and
starting their execution. Several different Shell (Command interpreter)
shells are available. Bash is popular,
Kernel File Systems

Device Drivers

The kernel manages the hardware resources.


Hardware

14
Prepared by: Eng. Anwar Fouad NTI
Linux Operating System

No direct access to the kernel

3 main components
 Kernel
 Command interpreter (Shell)
 Utilities

17
Prepared by: Eng. Anwar Fouad NTI
Linux Operating System

Kernel
 Manage Physical (hardware) resources
 Set of Procedure (written mainly in C)
Command interpreter (SHELL)
 Several shell (Bourn-Shell, TC or C-shell, k-shell, Bash-shell …)
 Language of command (script or command Line)
 Commands (executable programs)
Utilities
 Text editors (vi, emacs, gedit, nano ….)
 Programming languages (C, Fortran,…)
 Syntax analyzer (yacc,…)
 Web tools
 ...

18
Prepared by: Eng. Anwar Fouad NTI
NTI

Linux Concepts: User, File, Process

Linux Fundamentals
Linux User

20
Prepared by: Eng. Anwar Fouad NTI
Login and Logout

To work with Linux, a user first opens a session through a connection


procedure: login
 User name (UID, GUID)
 Password (/etc/passwd)

After validation, the user's current directory is set to his Home directory
and the associated executable file is launched:
– most frequently, the latter will be a command interpreter (shell):
sh, csh, ksh. Bash, tcsh

At the end of his work, the user closes the session: logout

21
Prepared by: Eng. Anwar Fouad NTI
Logging In : local side

A typical Linux system will run 5 virtual consoles and one


graphical console
 Server systems often have only virtual consoles
 Desktops and workstations typically have both

Switch among virtual consoles by typing: Ctrl-Alt-F[2-6]


Access the graphical console by typing Ctrl-Alt-F1

22
Prepared by: Eng. Anwar Fouad NTI
Logging In: Command Line

Before you can use it you must login by specifying your


account and password:
Username : test
Password : rootadmin
User name Password
(UID, GUID) (/etc/passwd)

Linux 2.2.13 (penguinvm.princeton.edu) (tty1)

penguinvm login: test


Password:
Last login: Tue Jan 4 10:13:13 from
linuxtcp.princeton.edu
[test@penguinvm ~]$

23
Prepared by: Eng. Anwar Fouad NTI
Logging In : GUI

24
Prepared by: Eng. Anwar Fouad NTI
Logging In : remote side

Connect to the Linux system using telnet or ssh :


 vt100, vt220, vt320
 ansi
 tty
 X-windows
Able to login more than once with same user

Example:
C:> telnet 41.65.222.215
Username : student#
Password : rootadmin

25
Prepared by: Eng. Anwar Fouad NTI
Rule Number 1

 Do not login as root unless you have to root is the


system superuser (the ―maint‖ of Linux but more
―dangerous‖)
 Normal protection mechanisms can be overridden
 Careless use can cause damage
 Has access to everything by default
 root is the only user defined when you install
 First thing is to change root‘s password
 The second job is to define ―normal‖ users for everyday use

26
Prepared by: Eng. Anwar Fouad NTI
Linux File

Linux generalizes the notion of disk file.

A file refers to a resource:


Hardware: physical resource such as a terminal, a
printer, a disk or floppy drive or, in general, any kind of
peripheral.
Software: files on a disk, in the usual sense of the word,
and containing information.

All the files are managed by a kernel module: the


File Management System.

27
Prepared by: Eng. Anwar Fouad NTI
Linux File Types

Every file has a type determining the set of allowed


operations on it.

Linux file types are:


 Regular file (-),
 Directory (d),
 Symbolic link (l),
 Special ( b: block, c: characters, etc)

28
Prepared by: Eng. Anwar Fouad NTI
Regular File

Linux/Unix philosophy:
 the way in which the information contained within a file
should be interpreted is the concern of the software
application that uses it.

Content of a regular file:


 linear, non structured stream of bytes.
No internal organization:
 no notion of record, sequential access, indexed
access, and so on, existing in other operating systems
 no special characters to mark the end of the file (EOF).
 End of a file detected by the FSM using the associated size
(or length) attribute: number of bytes.

29
Prepared by: Eng. Anwar Fouad NTI
Linux File System Basics

Linux files are stored in a


Directories root
single rooted,
hierarchical file system
 Data files are stored in
directories (folders)
 Directories may be nested
as deep as needed User home
directories

Data files

30
Prepared by: Eng. Anwar Fouad NTI
Special directories

/home - all users‘ home directories are stored here


/bin, /usr/bin - system commands
/sbin, /usr/sbin - commands used by sysadmins
/etc - all sorts of configuration files
/var - logs, spool directories etc.
/dev - device files
/proc - special system files

31
Prepared by: Eng. Anwar Fouad NTI
Naming Files

Files are named by


 naming each containing
directory
 starting at the root
This is known as the
pathname /etc/passwd

/home/neale/b

32
Prepared by: Eng. Anwar Fouad NTI
The Current Directory

Is the current working


directory
 Use pwd to find out where
you are

Current working
directory
doc/letter
./doc/letter
/home/neale/doc/letter

33
Prepared by: Eng. Anwar Fouad NTI
Some Special File Names

Some file names are special:


/ The root directory (not to be confused with the root user)
. The current directory
.. The parent (previous) directory
~ My home directory
Examples:
./a same as a
../jane/x go up one level then look in directory jane for x

34
Prepared by: Eng. Anwar Fouad NTI
File Pathname

 Pathname of a file:
 Used to refer to a file (whatever its type)
 Sequence of physical links
 May be absolute or relative.
 Absolute pathname of a file:
 Sequence of physical links describing the path to follow from the root
directory to reach the file.
 Examples:
/home/marty
/etc/passwd
/home/neale/doc/letter

35
Prepared by: Eng. Anwar Fouad NTI
Relative Pathname

 Relative pathname:
 Sequence of physical links describing the path to follow from the
working directory to reach the file.

 Examples:
Action
Reach the letter directory founded in directory doc:
working directory relative pathname

neale doc/letter
scully ../neale/doc/letter

To reach the fd0 file founded in directory dev:


working directory relative pathname

marty ../../dev/fd0

36
Prepared by: Eng. Anwar Fouad NTI
Relative Pathname

/dev/fd0

doc/letter ../../dev/fd0
../neale/doc/letter

/home/neale/doc/letter
37
Prepared by: Eng. Anwar Fouad NTI
Linux Process

38
Prepared by: Eng. Anwar Fouad NTI
Parent And Child Process

A Linux process is always created by another Linux process, called its


parent process.

The child process inherits many attributes and information from its
parent. For example:
 table of descriptors of opened files
 owners
 environment variables, and so on

The child process, however, cannot modify its parent's environment.

39
Prepared by: Eng. Anwar Fouad NTI
NTI

Using the system

Linux Fundamentals
NTI

Linux Command Basics


Working with files and directories
Linux Fundamentals
Syntax Of Basic Commands

<command name> [<options>] [<arg1> <arg2> ... <arg n>]


Expressions between brackets [ ] are optional.
<options>: sequence of letters preceded by ‗-‘ character.
each letter represents one option.
the order of the options has no importance.
<arg i>: string of characters
its meaning depends on the current command
(usually, they are file pathnames)
<command name>: command name
usually an executable filename.
Different command elements are delimited by at least one space
character.
Linux/Unix is case-sensitive.

42
Prepared by: Eng. Anwar Fouad NTI
Execute a command line

To execute a command, type its name and arguments at the


command line

ls -l /etc

Command name Arguments


Options
(flags)

43
Prepared by: Eng. Anwar Fouad NTI
Simple Commands

date - display date and time


# date
Fri Mar 16 21:04:25 EET 2012
# date '+%A %m-%d-%Y %H:%M:%S‗
# date "+%A %d %B %Y %H:%M %p"
# date -s Mar14
Wed Mar 14 00:00:00 EET 2012
# date -s 21:04
Fri Mar 16 21:04:00 EET 2012
cal - display calendar
 $ cal -3
pwd - Displays the absolute path to the shell's cwd

44
Prepared by: Eng. Anwar Fouad NTI
Getting Help

Don't try to memorize everything!


Many levels of help
 whatis
 command --help
 man
 info

45
Prepared by: Eng. Anwar Fouad NTI
The whatis Command

Displays short descriptions of commands


Uses a database that is updated nightly
Often not available immediately after install
$ whatis cal
cal (1) - displays a calendar

46
Prepared by: Eng. Anwar Fouad NTI
The --help Option

Displays usage summary and argument list


Used by most, but not all, commands
$ date --help
Usage: date [OPTION]... [+FORMAT] or:
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.
...argument list omitted...

47
Prepared by: Eng. Anwar Fouad NTI
The man Command

Provides documentation for commands


Almost every command has a man "page"
Collectively referred to as the Linux Manual
man <command>

48
Prepared by: Eng. Anwar Fouad NTI
Navigating man Pages

While viewing a man page


 Navigate with arrows, PgUp, PgDn
 /text searches for text
 n/N goes to next/previous match
 q quits

49
Prepared by: Eng. Anwar Fouad NTI
The info Command

Similar to man, but often more in-depth


Run info without args to list all page
info pages are structured like a web site
 info [command]

50
Prepared by: Eng. Anwar Fouad NTI
Navigating info Pages

While viewing an info page


 Navigate with arrows, PgUp, PgDn
 Tab moves to next link
 Enter follows the selected link
 n/p /u goes to the next/previous/up-one node
 s text searches for text (default: last search)
 q quits info

51
Prepared by: Eng. Anwar Fouad NTI
Listing Directory Contents

Lists the contents of the current directory or a


specified directory
Usage:
 ls [options] [files_or_dirs]
Example:
 ls -a (include hidden files)
 ls -l (display extra information)
 ls -R (recurse through directories)
 ls –F
 ls -ld
 ls -n

52
Prepared by: Eng. Anwar Fouad NTI
Changing Directories

cd changes directories
 To an absolute or relative path:
 cd /home/joshua/work
 cd project/docs
 To a directory one level up:
 cd ..
 To your home directory:
 cd ~
 To your working directory:
 cd .

53
Prepared by: Eng. Anwar Fouad NTI
Viewing File Contents : less and cat

● cat: dump one or more files to STDOUT


 Multiple files are concatenated together
 $cat [file name] ------------------------ To see the matter of file
 $cat > [file name]---------------------- To create a file
 $cat >> [file name ]-------------------- To append the matter of file
 Use CTRL+D to save the matter of file.

● less: view file or STDIN one page at a time


 Useful commands while viewing:
 /text searches for text
 n/N jumps to the next/previous match
 v opens the file in a text editor

54
Prepared by: Eng. Anwar Fouad NTI
Basic Commands On Files

wc [-lwc] [ <nom_fic> ... ]


 Writes on stdout the number of lines, words and characters in the
text files given as arguments.

head [-<n>] [ <nom_fic> ... ]


 Writes on stdout the <n> first lines of text files given as arguments.

tail [-<n> ] [ <nom_fic> ... ]


 Writes on stdout the last lines of a text file

more file1
 Writes on stdout one page at a time

55
Prepared by: Eng. Anwar Fouad NTI
Copying Files and Directories

cp - copy files and directories


Usage:
 cp [options] file destination

More than one file may be copied at a time if the destination


is a directory:
 cp [options] file1 file2 dest

56
Prepared by: Eng. Anwar Fouad NTI
Copying Files and Directories: The Destination

If the destination is a directory, the copy is placed there


If the destination is a file, the copy overwrites the destination
If the destination does not exist, the copy is renamed

57
Prepared by: Eng. Anwar Fouad NTI
Moving and Renaming Files and Directories

mv - move and/or rename files and directories


Usage:
 mv [options] file destination

More than one file may be moved at a time if the destination


is a directory:
 mv [options] file1 file2 destination
Destination works like cp

58
Prepared by: Eng. Anwar Fouad NTI
Creating and Removing Files

touch - create empty files or update file timestamps

rm - remove files
Usage:
 rm [options] <file>...
Example:
 rm -i file (interactive)
 rm -r directory (recursive)
 rm -f file (force)

59
Prepared by: Eng. Anwar Fouad NTI
Creating and Removing Directories

mkdir creates directories


rmdir removes empty directories
rm -r recursively removes directory trees

60
Prepared by: Eng. Anwar Fouad NTI
NTI

Using the bash Shell

Linux Fundamentals
Command Line Shortcuts The Tab Key

Type Tab to complete command lines:


 For the command name, it will complete a command name
 For an argument, it will complete a file name
Examples:
$ xte<Tab>
$ xterm
$ ls myf<Tab>
$ ls myfile.txt

62
Prepared by: Eng. Anwar Fouad NTI
Command Line Shortcuts History

bash stores a history of commands you've entered, which


can be used to repeat commands
Use history command to see list of "remembered"
commands
$ history
14 cd /tmp
15 ls -l
16 cd
17 cp /etc/passwd .
18 vi passwd
... output truncated ...

63
Prepared by: Eng. Anwar Fouad NTI
More History Tricks

Use the up and down keys to scroll through previous


commands
 Type Ctrl-r to search for a command in command history.
 (reverse-i-search)`':

64
Prepared by: Eng. Anwar Fouad NTI
Command Line Expansion :The tilde

Tilde ( ~ )
May refer to your home directory
$ cat ~/.bash_profile
May refer to another user's home directory
$ ls ~julie/public_html

65
Prepared by: Eng. Anwar Fouad NTI
Commands and Braced Sets

Command Expansion: $() or ` `


 Prints output of one command as an argument to another
$ echo "This system's name is $(hostname)"
This system's name is server1.example.com
Brace Expansion: { }
 Shorthand for printing repetitive strings
$ echo file{1,3,5}
file1 file3 file5
$ rm -f file{1,3,5}

66
Prepared by: Eng. Anwar Fouad NTI
Command Editing Tricks

Ctrl-a moves to beginning of line


Ctrl-e moves to end of line
Ctrl-u deletes/cut to beginning of line
Ctrl-k deletes to end of line

67
Prepared by: Eng. Anwar Fouad NTI
Lab Exercise NO. ( 1 )

Download Lab Exercise NO. ( 1 ) from:

http://41.65.222.215/

68
Prepared by: Eng. Anwar Fouad NTI
File Permissions

Every file
 Is owned by someone
 Belongs to a group
 Has certain access permissions for owner, group, and others
 Default permissions determined by ―umask‖

69
Prepared by: Eng. Anwar Fouad NTI
File Permissions

Every user:
 Has a uid (login name), gid (login group) and membership of a
"groups" list:
 The uid is who you are (name and number)
 The gid is your initial ―login group‖ you normally belong to
 The groups list is the file groups you can access via group
permissions

70
Prepared by: Eng. Anwar Fouad NTI
File Permissions

Linux provides three kinds of permissions:


 Read - users with read permission may read the file or list the
directory
 Write - users with write permission may write to the file or new
files to the directory
 Execute - users with execute permission may execute the file or
lookup a specific file within a directory

71
Prepared by: Eng. Anwar Fouad NTI
File Permissions

The long version of a file listing (ls -l) will display the file
permissions:

-rwxrwxr-x 1 ali students 5224 Dec 30 03:22 hello


-rw-rw-r-- 1 rvdheij rvdheij 221 Dec 30 03:59 hello.c
-rw-rw-r-- 1 rvdheij rvdheij 1514 Dec 30 03:59 hello.s
drwxrwxr-x 7 ahmed sales 1024 Dec 31 14:52 posixuft

Permissions Group

Owner

72
Prepared by: Eng. Anwar Fouad NTI
Interpreting File Permissions

-rwxrwxrwx
Other permissions
Group permissions
Owner permissions
Directory flag (d=directory;
l=link)

73
Prepared by: Eng. Anwar Fouad NTI
Interpreting Permissions

-rwxr-x--- 1 ahmed Sales 2948 Oct 11 14:07 myscript

Read, Write and Execute for the owner, ahmed


Read and Execute for members of the Sales group
No access for all others

74
Prepared by: Eng. Anwar Fouad NTI
Changing Permissions – Symbolic Method

To change access modes:


 chmod [-R] mode file
Where mode is:
 u,g or o for user, group and other
 + or - for grant or deny
 r, w or x for read, write and execute
Examples:
 ugo+r: Grant read access to all
 o-wx: Deny write and execute to others

75
Prepared by: Eng. Anwar Fouad NTI
The most common file permissions.

Permission Meaning
--- No access is allowed
r-- Read-only access
r-x Read and execute access, for programs
and shell scripts
rw- Read and write access, for files
rwx All access allowed, for programs

76
Prepared by: Eng. Anwar Fouad NTI
Permissions and numeric equivalents.

Permissions Binary Decimal


String Equivalent Equivalent

--- 000 0
--x 001 1
-w- 010 2
-wx 011 3
r-- 100 4
r-x 101 5
rw- 110 6
rwx 111 7

77
Prepared by: Eng. Anwar Fouad NTI
Changing File Permissions

Use the ―chmod‖ command to change file permissions


 The permissions are encoded as an octal number

chmod 755 file # Owner=rwx Group=r-x Other=r-x


chmod 500 file2 # Owner=r-x Group=--- Other=---
chmod 644 file3 # Owner=rw- Group=r-- Other=r—

chmod +x file # Add execute permission to file for all


chmod o-r file # Remove read permission for others
chmod a+w file # Add write permission for everyone

78
Prepared by: Eng. Anwar Fouad NTI
Changing File Ownership

Only root can change a file's owner


Only root or the owner can change a file's group

Ownership is changed with chown:


 chown [-R] user_name file|directory

Group-Ownership is changed with chgrp:


 chgrp [-R] group_name file|directory

79
Prepared by: Eng. Anwar Fouad NTI
Lab Exercise NO. ( 2 )

Create user "a" without password.


#useradd a
#passwd -d a

Create a group "example" and add user "a" to in.


#groupadd example
#usermod –G example a

Download Lab Exercise NO. ( 2 ) from:

http://41.65.222.215/
80
Prepared by: Eng. Anwar Fouad NTI

You might also like