Sls01 Lecture02 Linux In Practice

52
06/18/22

Transcript of Sls01 Lecture02 Linux In Practice

Page 1: Sls01 Lecture02 Linux In Practice

04/12/23

Page 2: Sls01 Lecture02 Linux In Practice

04/12/23

Page 3: Sls01 Lecture02 Linux In Practice

04/12/23

What is Linux?

Page 4: Sls01 Lecture02 Linux In Practice

04/12/23

Level of Abstraction

Page 5: Sls01 Lecture02 Linux In Practice

04/12/23

1. Linux is multitasking and multi-user operating system. 2. The shell is a program that interprets your commands and passes them to kernel for processing. 3. The kernel is written is C which makes it relatively easy to port from one machine to an other.4. The kernel is the mastermind program that schedules jobs and allocate resources (time, memory, disks and other peripherals) thereby shielding the user from hardware.

Page 6: Sls01 Lecture02 Linux In Practice

04/12/23

Ubuntu DistrobutionLinux for human Beings

Page 7: Sls01 Lecture02 Linux In Practice

04/12/23

Hands-on at the Commandline

ls , mv , clear , mkdir , cd , pwd

Page 8: Sls01 Lecture02 Linux In Practice

04/12/23

Page 9: Sls01 Lecture02 Linux In Practice

04/12/23

Page 10: Sls01 Lecture02 Linux In Practice

04/12/23

Page 11: Sls01 Lecture02 Linux In Practice

04/12/23

Commands

1. Commands are executable binary files supplied with Linux2. Commands have arguments/options/switches to change the default actions of the command 3. alias mine=“echo Welcome SOMS”

Page 12: Sls01 Lecture02 Linux In Practice

04/12/23

Page 13: Sls01 Lecture02 Linux In Practice

04/12/23

Page 14: Sls01 Lecture02 Linux In Practice

04/12/23

Page 15: Sls01 Lecture02 Linux In Practice

04/12/23

Page 16: Sls01 Lecture02 Linux In Practice

04/12/23

Page 17: Sls01 Lecture02 Linux In Practice

04/12/23

All about Shell

Type commands directly to Linux The commandline offers power and flexibilityThe command-line utilized in Ubuntu is known as bash—the BourneAgain ShellCommand-line programs are sometimes known as shellsbash is the default in most popular Linux distros

Page 18: Sls01 Lecture02 Linux In Practice

04/12/23

Linux NavigationRoam around in filesystem

Remove Directory

pwd cd mkdir rmdir ls

Print Working Directory

Change Directory

Make Directory

List files and directories

cp

Copy

mv

Move file/folder

ln

Link files

Page 19: Sls01 Lecture02 Linux In Practice

04/12/23

Default Directories

Page 20: Sls01 Lecture02 Linux In Practice

04/12/23

File System

Page 21: Sls01 Lecture02 Linux In Practice

04/12/23

Change and list directories You can use the following commands to change theactive directory and list the contents of a directory:1. pwdPrint Working Directory 2. lsList files and directories3. cdChange Directory

Page 22: Sls01 Lecture02 Linux In Practice

04/12/23

Page 23: Sls01 Lecture02 Linux In Practice

04/12/23

Create a user >sudoadduser “ur name without quotes”Create an other user >sudoadduser “someone else name without quotes”Navigate to “home” directory and list file/folders there >cd (enter)>pwd (enter)>ls (enter) Make directories as shown in the tree >mkdir user1/Documets/mail user1/Documets/tmp user2/Documets/mailCopy tmp from user1 to user2>cp –r user1/Documets/tmp user2/DocumetsNavigate to user2’s tmp folder >cd user2/Documents/tmpRemove user1’s mail folder >rmdir /home/user1/Documents/mail

/home

user1 user2

Documents Documents

mail mailtmp tmp

Page 24: Sls01 Lecture02 Linux In Practice

04/12/23

Relative vs Absolute pathAbsolute path: Starting with “/”Relative path: Starting with the current directory Considering the previous tree >pwd <enter>/home/user1/Documents/mailNow navigate to user2’s mail >cd/home/user2/Documents/mail <enter> (Absolute)

>cd../../../user2/Documents/mail <enter>(Relative)

/home

user1 user2

Documents Documents

mail mailtmp tmp

Page 25: Sls01 Lecture02 Linux In Practice

04/12/23

File System

Page 26: Sls01 Lecture02 Linux In Practice

04/12/23

Personal extensions

Make a directory named “myext”>mkdir ~/myextWrite plain files using any editor like: “nano” >nano memo.maths memo.english>nano score.maths score.englishList files to confirm files creation>lsmemo.maths memo.english score.maths score.english One of the advantage of personal extensions >ls –al *.mathsmemo.maths score.maths

Page 27: Sls01 Lecture02 Linux In Practice

04/12/23

Two names for the same file?

/

home etc media

user1

user2

Desktop

Desktop

Every file and folder has a unique i-node ln geeko.txt gg <enter> nano gg <enter> (geeko.txt will be displayed)

Practical application:To avoid long paths

Page 28: Sls01 Lecture02 Linux In Practice

04/12/23

Page 29: Sls01 Lecture02 Linux In Practice

04/12/23

Mount DirectoriesMount even windows drives

Page 30: Sls01 Lecture02 Linux In Practice

04/12/23

Now we are going to mount Windows drives to UbuntuMounting Drive: C mkdir ~/Desktop/DriveC mount strage_device mount_point mount /dev/sda1 / ~/Desktop/DriveCUnmounting Drive: C umount /dev/sda1 / ~/Desktop/DriveCStorage devices like CD-ROM and USB mounted automatically as soon as u plug them in. /media/cdrom/media/<name of USB>

Page 31: Sls01 Lecture02 Linux In Practice

04/12/23

Customize filesystemmanaging files and directories

Page 32: Sls01 Lecture02 Linux In Practice

04/12/23

Create files

Page 33: Sls01 Lecture02 Linux In Practice

04/12/23

Page 34: Sls01 Lecture02 Linux In Practice

04/12/23

Exercise

1. View the hidden files on your ~ directory2. Create a directory called new_dir in your ~3. Create a file called old there4. Create a hard and symbolic link for this file5. View the inode numbers of these links6. Try removing new_dir using rmdir7. Remove new_dir and all its children

Page 35: Sls01 Lecture02 Linux In Practice

04/12/23

Exercise

1. View the hidden files on your ~ directoryls -a2. Create a directory called new_dir in your ~mkdir ~/newdir3. Create a file called old theretouch old4. Create a hard link for this fileln old link2old5. View the inode numbers of these linksls -i6. Try removing new_dir using rmdirrmdir new_dir

Page 36: Sls01 Lecture02 Linux In Practice

04/12/23

Page 37: Sls01 Lecture02 Linux In Practice

04/12/23

Manage User & Groupschmod

Page 38: Sls01 Lecture02 Linux In Practice

04/12/23

Page 39: Sls01 Lecture02 Linux In Practice

04/12/23

Page 40: Sls01 Lecture02 Linux In Practice

04/12/23

Exercise From Command LineSee the /etc/passwd Make a new user “hero” with default home directoryGive it the password “zero”See the changes in /etc/passwdSwitch to user “hero” and change its password to “d!g!t@l”Delete the account of “hero”

Page 41: Sls01 Lecture02 Linux In Practice

04/12/23

File permissions and modes

Page 42: Sls01 Lecture02 Linux In Practice

04/12/23

System Diagnostics Examining system health

Page 43: Sls01 Lecture02 Linux In Practice

04/12/23

Linux Utilities ssh, ftp, scp

Page 44: Sls01 Lecture02 Linux In Practice

04/12/23

SSH

Page 45: Sls01 Lecture02 Linux In Practice

04/12/23

SSH

Open protocol for network communication Functionality of SSH: Secure Command shell Secure File transfer Data tunneling/Port forwarding

Page 46: Sls01 Lecture02 Linux In Practice

04/12/23

Packages Snatch, configure and install and customize

Page 47: Sls01 Lecture02 Linux In Practice

04/12/23

Using apt utility - Automatic >apt-get install <package name> This is automatically snatch the package from the repositories listed in /etc/apt/sources.list and install on your distro >apt-cache search <package name>To remove the package >apt-get remove <package name>To intsall the <package-name.deb> >dpkg <package name>

Page 48: Sls01 Lecture02 Linux In Practice

04/12/23

Get Source package - Manual

Download source code in compressed format Decompress the package Navigate into the package folder Apply the triangle command in sequence >./configure>make>make installTo run the software/package just type the name >package-name<enter>

Page 49: Sls01 Lecture02 Linux In Practice

04/12/23

Code compilationUsing gnu compiler

Page 50: Sls01 Lecture02 Linux In Practice

04/12/23

C source file compilation

Packages: gcc-*.*, g++Create a file >nano ~/hello.cPaste the following code lines #include<iostream.h> void main(){ cout<<“Hello Geeks”; }</code>Compile the file using gcc compiler >gcc hello –o hello <enter>This will drop a file hello in the same folder Give permission to make it executable >chmod a+x hello <enter>>./hello <enter>Hello Geeks

Page 51: Sls01 Lecture02 Linux In Practice

04/12/23

Upcoming Lectures ?

SL03 - Exploit Shell Scripting SL04 - System Administration

Page 52: Sls01 Lecture02 Linux In Practice

04/12/23

Questions ?