33
L2B Linux First Course Please visit our Facebook Group S ession2

Session2

Embed Size (px)

Citation preview

Page 1: Session2

L2B Linux First Course

Please visit our Facebook Group

S ession2

Page 2: Session2

L2B Linux course

L2B First Linux Course

Session Outlines: Linux principles Bash Basics Users, Groups and Permissions Introduction to Bash Scripts

Page 3: Session2

L2B Linux course

L2B First Linux Course

Linux Principles Every thing is a file including hardware Small, single-purpose programs Ability to chain programs together to perform

complex tasks Avoid captive user interfaces Configuration data stored in text

Page 4: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Shell or bash is an interface between the user

and the kernel Accepts the commands that a user enters,

interprets these commands, and passes them to the kernel

Page 5: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Command format:

command [option] [argument] Option

• Preceded by - if single character• Preceded by - - if more than one character

Arguments are file names or other data needed by the command

Page 6: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Full Path

• Begins with a forward slash• Ends with the file location

Relative path• Begins with your location• Ends with the file location

Page 7: Session2

L2B Linux course

L2B First Linux Course

Bash Basics .. refers to the parent directory . refers to the current directory Directory names is case sensitive Names may be up to 255 character You can use all characters except the

forward-slash

Page 8: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Clear :

• Clear the terminal Cal

• Display the calendar of current year cal year

• Display calendar of this year cal month

• Display calendar of this month Date

• Display current date

Page 9: Session2

L2B Linux course

L2B First Linux Course

Bash Basics eject cdrom pwd cd

• cd ~• cd path• cd ..• cd ../..• cd .• cd -

Page 10: Session2

L2B Linux course

L2B First Linux Course

Bash Basics ls

• ls -l• ls -d• ls -h• ls -a• ls -t• ls -r• ls -R

dir tree not installed by default in Ubuntu

Page 11: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Touch

• If you touched a file which exists you changes it's modification time

cat & more nano file_name

Page 12: Session2

L2B Linux course

L2B First Linux Course

Bash Basics mkdir

• mkdir -p cp

• cp -r• cp -R• cp -i• cp -f

Page 13: Session2

L2B Linux course

L2B First Linux Course

Bash Basics rm

• rm -rrm -R

rmdir• rmdir -p

Hint:• To remove a directory which you exists in, move to

its parent directory or any other directory.

Page 14: Session2

L2B Linux course

L2B First Linux Course

Bash Basics cal Switching between users

• su• su -• sudo

Changing password• passwd [user_name]

Page 15: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Adding users

• adduser <user_name>• useradd <user_name>

Removing users• userdel <user_name>

Page 16: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Getting help

• command --help• whatis <command>• man <command>• info <command>

Page 17: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Getting help

• --help:– Most commands have the options --help– It prints a usage statement and list of options and

what they do– [ any_thing ] >>> It is optional– ...... >>> It is list of that thing– < any_thing > >>> It is not optioinal– { x,y,z } >>> At least one of the these things– Options separated by | >>> one of them can be

used “or"

Page 18: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Getting help

• whatis – Short description about the command– Update it's database daily

» makewhatis as root

Page 19: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Getting help

• man -f• man -k & apropos• man -w• manpath

Page 20: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Getting help

• man page format and how to use it• man [chapter_number] command• man sections/chapters

1- user commands2- system calls / functions provided by the kernel3- Library calls4- special files5- configuration files formats6- games7- packages8- administrative commands

Page 21: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Getting help

• info pages– More details than man– Like a web site– Divided into nodes (*)– Try >>> (info ls)

Page 22: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Type Tab to complete command lines Type Tab to command name For an argument, it will complete a file name Examples:

• $ xte<Tab>• $ xterm• $ ls myf<Tab>• $ ls myfile.txt

Page 23: Session2

L2B Linux course

L2B First Linux Course

Bash Basics echo command file command Virtual consoles

Page 24: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Exercise What man option you will use to search the

description of every manual page for a keyword.

What man option you will use to search the entire text (all of the page) of every manual page.

Page 25: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Exercise What is the option added to “ls” command to

display long list results. What is the option added to “ls” command to

display long list results with human-readable descriptions.

Page 26: Session2

L2B Linux course

L2B First Linux Course

Bash Basics Exercise Given the following:

foo -x | -y [-abcde] FILENAMEWhich one is right?

• foo -x -y -a file.txt• foo• foo -y -abc file1.txt file2.txt• foo -abc file1.txt file2.txt file3.txt

Page 27: Session2

L2B Linux course

L2B First Linux Course

Users, Groups and permissions Every user is assigned a unique User ID (UID) UID 0 identifies root Users' names and UIDs are stored in

/etc/passwd Users are assigned to groups Each group is assigned a unique Group ID

(gid) GIDs are stored in /etc/group

Page 28: Session2

L2B Linux course

L2B First Linux Course

Users, Groups and permissions Every file is owned by a UID and a GID Permission Types:

• r• w• X

To display permissions of a file usels -l file

Page 29: Session2

L2B Linux course

L2B First Linux Course

Users, Groups and permissions 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

Page 30: Session2

L2B Linux course

L2B First Linux Course

Users, Groups and permissions 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

Page 31: Session2

L2B Linux course

L2B First Linux Course

Users, Groups and permissions Uses a three-digit mode number first digit specifies owner's permissions second digit specifies group permissions third digit represents others' permissions Permissions are calculated by adding:

• 4 (for read)• 2 (for write)• 1 (for execute)

Example:• chmod 640 myfile

Page 32: Session2

L2B Linux course

L2B First Linux Course

Introduction to Bash Scripts What is a script? sc extension recommended Steps to create a script

• Step 1: Use such as vi or nano to create a text file containing commands:

– #!/bin/bash– Comments start with a #– Write your commands.

• Step 2: Make the script executable:– $ chmod u+x myscript.sh

• Step 3: To execute the new script:– Use relative path or full path

Page 33: Session2

For More info Please Visit Our Facebook Group