linux basic - wordpress.com · 5.1 overview of linux linux was first developed by linus torvads ....
TRANSCRIPT
![Page 1: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/1.jpg)
UNIT:5Linux Basic1
![Page 2: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/2.jpg)
SYLLABUS
5.1 Overview of linux
5.2 Installation and upgrade
5.3 Introduction to shell and commands
5.4 Editing files with vi , vim, gedit, gcc
5.5 Linux Shell
2
![Page 3: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/3.jpg)
5.1 OVERVIEW OF LINUX
Linux was first developed by Linus torvads .
Linux is the most famous free and open source OS.
Open source Os are available in source code
format rather than as compiled binary code
Free software means not by money point of view.
But software that is free means it is distributed
along with its source code.3
![Page 4: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/4.jpg)
Anyone who receives it is free to make change andredistribute it.
There are many versions of Linux.famous versionsare,
Red hat Linux Fedora ,Centos
DebianUbuntu,Linuxmint,Linspire,PCLinux
Linux can be found on wide range of devices-frompersonal computers,mobiles,tablets and embeddedsystems to main frame computers andsupercomputers 4
![Page 5: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/5.jpg)
5.2 INSTALLATION AND UPGRADE There are four different types of linux installations.
1. Dual Boot
Computer System can have more than one
operating system.
Linux can be installed along with other operating
system such as windows.
User has to decide which operation system to
boot into during boot process.
5
![Page 6: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/6.jpg)
2. Live CD/DVD booting
Linux can be run as a completely bootable operating system from cd/dvd.
When computer system is booted from cd/dvdrequired files are loaded into main memory form cd/dvd.
Operating system runs using these files.
3. Virtual Installation
Linux can be run as a virtual machine inside another operating system.
6
![Page 7: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/7.jpg)
User has to install some virtual server application such as Vmware and then install linuxunder host software
Fresh Installation It is the most popular installation. It installs linux
as the only operating system of the computer.
Here hard disk is formatted and if there is any existing operating system in computer, it will removed.
7
![Page 8: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/8.jpg)
LINUX ARCHITECTURE
It is also known as the layered structure of Linux. Linux is a UNIX-like OS, its architecture resembles
to that of UNIX. 1. Hardware: Bottom layer is hard ware. It consist of physical devices such as CPU ,memory
,disks ,monitors ,printers etc. These devices provides various services.
8
![Page 9: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/9.jpg)
9
Figure : Linux architecture
![Page 10: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/10.jpg)
Linux operating system: Next higher layer in Linux OS It is called system kernel. Kernel manages all the underlying hardware It directly interacts with the H/W and provides
user programs required services It hides complex details of H/W It provides interface between user program and
H/W Main service of OS : process management , memory
management ,file system management,I/O management
10
![Page 11: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/11.jpg)
Standard library Contains a set of procedures, one procedure per
system call These procedures are written in assembly
language and used to invoke various systemcalls from user program.
4. Standard utility program All UNIX versions supply OS , system call ,
large no. of standard program Program include command processor (shell)
,compilers ,editors ,text processing program,file manipulation utility a variouscommands… 11
![Page 12: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/12.jpg)
Program makes user tasks simpler User interacts with program, program
interacts with OS to get services from OS
Users Top most layers User program come in this layer They interacts with system either by library
procedure to invoke system call or by using utilityprogram such as shell
12
![Page 13: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/13.jpg)
Kernel is core part of any OS. Kernel is program, which is loaded in memory
,when system is turned on and provides variousservices until system is turned off.
Kernel manages all the underlying hardware It directly interacts with the H/W , It hides complex
details of H/W When user needs to use any H/W ,it has to use
services (system call) provided by kernel. System call request kernel and kernel performs the
job behalf on user process.13
KERNEL
![Page 14: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/14.jpg)
5.3 INTRODUCTION TO SHELL ANDCOMMANDS
Pwd- Print working directory Cd – Change directory Mkdir – Make directory. Rmdir – Remove a directory or an entire directory
tree. Ls – Display the contents of a directory. Cat – To open the file, create a new file and
append the data in files.Deletes one or more files. Copy – Places a copy of file(s) in a different folder.
14
![Page 15: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/15.jpg)
DIRECTORY RELATED COMMANDS
15
Creates a directory. % mkdir newdir
Often people make an alias of md for it.
Removes a directory. % rmdir dirname
Equivalent: % rm -r dirname
![Page 16: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/16.jpg)
CD AND PWD
16
Changes your current directory to a new one. % cd /some/other/dir
Absolute path % cd subdir
Assuming subdir is in the current directory. % cd
Returns you to your home directory. Displays personal working directory, i.e. your
current directory. % pwd
![Page 17: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/17.jpg)
MAN
Manual PagesThe first command to rememberContains info about almost everything :-)
other commands system calls c/library functions other utils, applications, configuration files
To read about man itself type:% man man
NOTE: unfortunately there’s no% man woman ... 17
![Page 18: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/18.jpg)
PASSWD
Change your login password. A very good idea after you got a new one. It’s usually a paranoid program asking your
password to have at least 6 chars in the password, at least two alphabetical and one numerical characters. Some other restrictions (e.g. dictionary words or previous password similarity) may apply.
Depending on a privilege, one can change user’s
and group passwords as well as real name, login shell, etc.
% man passwd18
![Page 19: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/19.jpg)
DATE
Guess what :-) Displays dates in various formats % date
% date -u
in GMT % man date
19
![Page 20: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/20.jpg)
CAL Calendar
for month entire year
Years range: 1 - 9999 No year 0 Calendar was corrected in 1752 - removed 11 days % cal current month % cal 2 2000 Feb 2000, leap year % cal 2 2100 not a leap year % cal 2 2400 leap year % cal 9 1752 11 days skipped % cal 0 error % cal 2002 whole year
20
![Page 21: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/21.jpg)
HISTORY % cal current month % cal 2 2000 Feb 2000, leap year % cal 2 2100 not a leap year % cal 2 2400 leap year % cal 9 1752 11 days skipped % cal 0 error % cal 2002 whole year
21
![Page 22: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/22.jpg)
LS
22
List directory contents Has whole bunch of options, see man ls for details. % ls
all files except those starting with a “.”
% ls -a
all % ls -A
all without “.” and “..”
![Page 23: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/23.jpg)
CAT
23
Display and concatenate files. % cat
Will read from STDIN and print to STDOT every line you enter.
% cat file1 [file2] ...
Will concatenate all files in one and print them to STDOUT % cat > filename
Will take whatever you type from STDIN and will put it into the file filename
To exit cat or cat > filename type Ctrl+D to indicate EOF (End of File).
![Page 24: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/24.jpg)
COPY
24
Copies files / directories.% cp [options] <source>
<destination>
% cp file1 file2
% cp file1 [file2] … /directory
Useful option: -i to prevent overwriting existing files and prompt the user to confirm.
![Page 25: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/25.jpg)
MV
25
Moves or renames files/directories.% mv <source> <destination>
The <source> gets removed% mv file1 dir/
% mv file1 file2
rename% mv file1 file2 dir/
% mv dir1 dir2
![Page 26: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/26.jpg)
RM
26
Removes file(s) and/or directories.% rm file1 [file2] ...
% rm -r dir1 [dir2] ...
% rm -r file1 dir1 dir2 file4
...
![Page 27: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/27.jpg)
CHMOD
27
Changes file permissionsPossible invocations
% chmod 600 filename
-rw------- 1 user group 2785 Feb 8 14:18 filename(a bit not intuitive where 600 comes from)
% chmod u+rw filename
(the same thing, more readable) For the assignment:
% chmod u+x myshellscript
(mysshellscript is now executable) -rwx------ 1 user group 2785 Feb 8 14:18 myshellscript
![Page 28: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/28.jpg)
ECHO AND GREP
28
Searches its input for a pattern. The pattern can be a simple substring or a complex
regular expression. If a line matches, it’s directed to STDOUT;
otherwise, it’s discarded.
% echo “blah-foo” | grep blah
Will print the matching line % echo “blah-foo” | grep zee
Will not. See a separate grep tutorial.
![Page 29: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/29.jpg)
PS
Use ps to report the status of a process
/export/home/morris07>ps
Output: PID TTY TIME CMD 19834 pts/7 0:05 ksh 19954 pts/7 0:04 ps
29
![Page 30: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/30.jpg)
SORT
The sort command sorts data (using ASCIIformat).
sort [-dfnru] [infile…] [-o outfile] >sort names -o sorted_names or >sort names > sorted_names
30
![Page 31: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/31.jpg)
KILL The kill command waits for the process to
perform cleanup: write to files, close files,etc.
If the process will not end, use the ‘-9’ or ‘-KILL’ to kill the process immediately
> kill –9 19954 > kill –KILL 19954
31
![Page 32: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/32.jpg)
5.4 VI short for: visual editor
available on all UNIX systems
original vi part of BSD Unix
written by Bill Joy in 1976
many derived, improved versions available
open source vim (vi improved)
is part of GNU/Linux
vi has multiple modes of operation:
input mode, command mode, last-line mode32
![Page 33: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/33.jpg)
VIM
Syntax: vim [options] [filename]
Filename is optional
With it, it opens that file for editing
Without, it opens a default screen
Many options available, most commonly used
ones are for file recovery
33
![Page 34: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/34.jpg)
We’ll be using vim - vi improved
Written by Bram Moolenaar
In our RedHat distro, we have /bin/vim
vi is just an alias to vim
Standard in just about all Linux distros
Available from www.vim.org
34
![Page 35: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/35.jpg)
GEDIT
35
It is a GUI based text editor and can be used with
linux shell as well as other OS .
It is similar to notepad editor of windows OS but it is
more powerful than notepad.
It is free software.
It is support multi language spell checking and a
flexible plug in system.
![Page 36: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/36.jpg)
GCC
Gcc refers to GNU compiler collection.
Gcc is a compiler for c, c++,java and other
programming languages.Compile the program by following code.
Gcc test.c -o test.out Run the program by following commands. ./test.out
36
![Page 37: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/37.jpg)
DIRECTORY It is a container for other files and sub-directories. They provide a hierarchical file structure. They
organize files in well manner. Directory is a file whose data is sequence of
entries. Each entry contains a file name and a unique identification number called I-node number.
I –node number provides a location of I-node where information about a file is stored.
Any directories contains two special entries : dot (.) and dot dot (..) .
These two entries refer to the current directory itself and its parent directory respectively.
37
![Page 38: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/38.jpg)
DIRECTORY STRUCTURE
38
![Page 39: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/39.jpg)
Top of file is called root (defined by / )
The name of file is given by path name .it describes
location of a file and directory.
A path name can be either absolute and relative.
Absolute path :
C:\ prog \ CPP \ test.cpp
Relative path :
./test.cpp39
![Page 40: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/40.jpg)
5.5 LINUX SHELL
A shell is a command interpreter that allows you to type commands from the keyboard to interact with the operating system kernel.
A command is a program which interacts with thekernel to provide the environment and perform thefunctions called for by the user.
A command can be: a built-in shell command; anexecutable shell file, known as a shell script; or asource compiled, object code file.
40
![Page 41: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/41.jpg)
The shell is a command line interpreter. The user
interacts with the kernel through the shell. You can
write ASCII (text) scripts to be acted upon by a shell.
sh (Bourne Shell) The sh shell was the earliest
shell, being developed for UNIX back in the late
1970s.
bash (Bourne-Again Shell) The bash shell is
an improved version of the sh shell and is one of
the most popular shells today. It’s the default
shell used by most Linux distributions. 41
![Page 42: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/42.jpg)
csh (C Shell) The csh shell was originally
developed for BSD UNIX. It uses a syntax
that is very similar to C programming.
tsch The tsch shell is an improved version
of the C Shell. It is the default shell used on
FreeBSD systems. zsh (Z Shell) The Z Shell is an improved
version of the bash shell.
42
![Page 43: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/43.jpg)
Linux Command-Line Interface
Libraries Libraries are pre-written code “pieces”
that application programmers use in their
programs.
Utilities maintaining the file system, editing text
files, managing running processes, and
installing new software packages.
User Interface command-line interface (CLI)
and a graphical user interface (GUI).
43
![Page 44: Linux Basic - WordPress.com · 5.1 OVERVIEW OF LINUX Linux was first developed by Linus torvads . Linux is the most famous free and open source OS. Open source Os are available in](https://reader030.vdocument.in/reader030/viewer/2022040611/5ed3c62585d90c53341ac945/html5/thumbnails/44.jpg)
Thank u
44