LINUX OPERATING SYSTEM
INTRODUCTION TO LINUX
OPERATING SYSTEM
💟LINUX OPERATING SYSTEM
Linux operating system consists of Kernel, Shell and File System:
The kernel
!Kernel is heart of Linux OS
!It manages resource of Linux OS !Resources means facilities available in
Linux. For e.g. Facility
!To store data,
!Print data on printer,
!Memory
!File management
!Kernel decides who will use resources, for how long and when.
!It runs your programs (or set up to execute binary files). !The kernel acts as an intermediary between the computer hardware and various programs/application/shell.
LINUX OPERATING SYSTEM
Linux operating system consists of Kernel, Shell and File System:
The Shell
!The shell is a program that acts as an interface between users and kernel
!It is a command interpreter and also has programming capability of its own. !Shell Types
!Bourne Shell (sh) (First shell by Stephen Bourne)
!C Shell(sh)
!Korn Shell (ksh)
!Bourne Again Shell(bash)
!Filename Completion or TAB completion
!History - The shell keeps a list of the commands you have typed in
File System
!Linux treats everything as a file including hardware devices. Arranged as a directory hierarchy.
!The top level directory is known as “root (/)”.
DIFFERENT SHELLS AVAILABLE IN LINUX
| Shell | Program Name | Description |
|
Bourne shell | sh | The original shell from AT&T, available on all UNIX machines | ||
|
|
|
|
|
C shell | csh | Shell developed as part of BSD UNIX | ||
Korn shell | ksh | AT&T improvement of the Bourne shell | ||
Bourne again shell | bash | Shell distributed with Linux, version of Bourne shell that includes command line editing and other nice things | ||
|
FILES AND PROCESSES
!Everything in LINUX is either a file or a process
!A process is an executing program identified by a unique PID (process identifier).
!A file is a collection of data. They are created by users using text editors, running compilers etc.
!Examples of files:
!A document (report, essay etc.)
!A program text (high-level programming language ) !Instructions:
! comprehensible directly to the machine
! incomprehensible to a casual user
! for example, a collection of binary digits (an executable or binary file);
!A directory, containing mixture of other directories and ordinary files.
DIRECTORY STRUCTURE
!All the files are grouped together in a directory structure.
!The file-system is arranged in a hierarchical structure, like an inverted tree.
!The top of the hierarchy is traditionally called root (written as a slash / )
!The full path to the file report.doc is
"/home/its/ug1/ee51vn/report.doc"
DIRECTORIES IN LINUX
Directory: /bin
/bin contains the binaries which are needed to run LINUX.
Directory: /boot
/boot has all the files required for booting LINUX on system.
Directory: /dev
/dev has the devices for all the files.
Directory: /etc
/etc contains the configuration files of the various software. Normally no one touch this directory.
Directory: /home
/home is like My Documents in Windows.
This contains the username as the sub directory.
Directory: /lib
/lib contains the shared libraries required for the system files.
DIRECTORIES IN LINUX
Directory: /lost+found
/lost+found contains the files which are damaged or which are
not linked to any directory.
These damages are due to the incorrect shutdown.
Directory: /mnt
This is the directory in which we mount the devices and other
file systems.
Directory: /opt
Here the optional softwares are installed.
Directory: /root
The directory for the user root
LINUX COMMANDS
Commands tell the operating system to perform set of operations.
The syntax form of the commands are
Command options arguments
We can divide Linux commands into following categories
!File Handling !Text Processing !System Administration !Process Management | !Archival !Network !File Systems !vi Commands |
LINUX COMMANDS
!Primary – man(manual) pages.
!man <command>
!shows all information about the command
!<command> --help
!shows the available options for that command
! Secondary – Books and Internet
mkdir:
make directories
Usage: mkdir [OPTION] DIRECTORY...
eg. mkdir LHC_School
ls:
list directory contents
Usage: ls [OPTION]... [FILE]… eg. ls, ls -l, ls LHC_School
cd:
changes directories
Usage: cd [DIRECTORY] eg. cd LHC_School
pwd:
prints the name of current working directories
Usage: pwd eg. mkdir LHC_School
vim:
Vi Improved, a programmers text editor Usage: vim [OPTION] [file]...
eg. vim file1.txt
cp:
copy files and directories
Usage: cp [OPTION]... SOURCE / DEST eg. cp sample.txt sample_copy.txt cp sample_copy.txt target_dir
mv:
move (rename) files
Usage: mv [OPTION]... SOURCE / DEST eg. mv source.txt target_dir mv old.txt new.txt
rm:
remove files or directories
Usage: rm [OPTION]… [file]...
eg. rm file1.txt , rm -rf some_dir find:
search for files in a directory hierarchy
Usage: find [OPTION] [path] [pattern] eg. find file1.txt find -name file1.txt
history:
prints recently used commands
Usage: history
PATTERN
A Pattern is an expression that describes a set of strings which is used to give a concise description of a set, without having to list all elements.
Example:
ab*cd matches anything that starts with ab and
ends with cd etc.
ls *.txt – prints all text files rm *.obj – removes all object files
TEXT PROCESSING
cat:
concatenate files and print on the standard
output…
Usage: cat [OPTION] [FILE]…
eg. cat file1.txt file2.txt cat -n file1.txt
echo:
display a line of text
Usage: echo [OPTION] [string] ...
eg. echo I love Pakistan
echo $HOME
TEXT PROCESSING
grep:
print lines matching a pattern
Usage: grep [OPTION] PATTERN [FILE]...
eg. grep -i apple sample.txt
wc:
print the number of newlines, words, and bytes in files…
Usage: wc [OPTION]... [FILE]...
eg. wc file1.txt wc -L file1.txt
TEXT PROCESSING
sort:
sort lines of text files
Usage: sort [OPTION]... [FILE]...
eg. sort file1.txt sort -r file1.txt
LINUX FILE PERMISSIONS
!3 types of file permissions – read, write, execute
!10 bit format from 'ls -l' command
1 2 3 4 5 6 7 8 9 10 file type owner group others eg. drwxrw-r-- means owner has all three permissions, group has read and write, others have only read permission
!read permission – 4, write – 2, execute -1 eg. rwxrw-r-- = 764
673 = rw-rwx-wx
SYSTEM ADMINISTRATION
chmod:
change file access permissions
Usage: chmod [OPTION] [MODE] [FILE] eg. chmod 744 calculate.sh
chown:
change file owner and group
Usage: chown [OPTION]... OWNER[:[GROUP]] FILE...
eg. chown remo myfile.txt
su:
change user ID or become super-user
Usage: su [OPTION] [LOGIN] eg. su remo, su
SYSTEM ADMINISTRATION
passwd:
update a user’s authentication tokens(s)
Usage: passwd [OPTION] eg. passwd who:
show who is logged on
Usage: who [OPTION] eg. who , who -b , who -q
PROCESS MANAGEMENT
ps:
report a snapshot of the current processes
Usage: ps [OPTION] eg. ps, ps -el
kill:
to kill a process(using signal mechanism)
Usage: kill [OPTION] pid eg. kill -9 2275
ARCHIVAL
tar:
to archive a file
Usage: tar [OPTION] DEST SOURCE tar -cvf /home/archive.tar /home/original tar -xvf /home/archive.tar
zip:
package and compress (archive) files
Usage: zip [OPTION] DEST SOURSE
eg. zip original.zip original
unzip:
list, test and extract compressed files in a ZIP archive
Usage: unzip filename eg. unzip original.zip
NETWORK
SSH:
SSH client (remote login program)
“ssh is a program for logging into a remote mach ine and forexecuting commands on a remote machine”
Usage: ssh [options] [user]@hostname eg. ssh -Y guest@10.105.11.20
scp:
secure copy (remote file copy program) “scp copies files between hosts on a network”
Usage: scp [options] [[user]@host1:file1] [[user]@host2:file2] eg. scp file1.txt guest@10.105.11.20:~/Desktop/
FILE SYSTEM
fdisk:
partition manipulator eg. sudo fdisk -l mount:
mount a file system
Usage: mount -t type device dir eg. mount /dev/sda5 /media/target umount:
unmount file systems
Usage: umount [OPTIONS] dir | device... eg. umount /media/target
FILE SYSTEM
du:
estimate file space usage
Usage: du [OPTION]... [FILE]...
eg. du
df:
report file system disk space usage Usage: df [OPTION]... [FILE]...
eg. df quota:
display disk usage and limits
Usage: quota [OPTION] eg. quota -v
EDITOR COMMANDS
vi:
Vi Improved, a programmers text editor Usage: vim [OPTION] [file]...
e.g. vi hello.c
gedit:
A text Editor. Used to create and edit files.
Usage: gedit [OPTION] [FILE]...
eg. gedit
pico:
Simple and very easy to use text editor
Usage: pico [OPTION] eg. Pico
USING ALIASES
Aliases provide command-substitution functionality. They can be used to create new commands or modify the default behaviour of existing commands
Syntax: alias <string entered by user>=<string substituted by the shell>
The alias command is used to view and create aliases
!called with no arguments, it prints out the current aliases
!alias name=value creates a new alias
!custom user aliases are stored in .bashrc or .cshrc Examples:
alias rm = 'rm -i' (change the behaviour of rm to confirm deletes) alias ll = 'ls -l | more' (create a new command for friendly file listings)
ENVIRONMENT VARIABLES
Environment variables refers to global settings that control the function of the shell and other Linux programs. They are sometimes called global shell variables or in simple words
They define the user environment and are read from initialization files each time a user logs in…
To view the value of a variable, type:
printenv VARNAME OR echo $VARNAME
To check your environment, type
printenv OR env
To Set Environment Variable setenv EDITOR “vim”
Some common environment variables:
HOME: Your home directory (often be abbreviated as “~”)
PWD: Current working directory
EDITOR: User’s preferred text editor
ENVIRONMENT VARIABLES
Some common environment variables:
EDITOR: | Sets the editor to be used by programs such as mail clients |
PATH: | Specifies directories to be searched for executables |
SHELL: | The default login shell |
USER: | Current loggedin user’s name |
TERM: | The type of terminal you are running (for example vt100,xterm, |
and ANSI)
LD_LIBRARY_PATH: It is a colon seperated set of directories where libraries should be searched for
To reload any initialization file without having to logout and login again, type source <filename>
e.g. source ~/.bashrc source ~/.tcshrc
Profile files: session startup files are hidden files, find them via command “ls –a”….
.tcshrc .cshrc .bashrc etc…
USEFUL VI
EDITOR COMMANDS
^G | show current file and line |
^F | forward screen |
^B | backward screen |
^D | scroll down half screen |
^U | scroll up half screen |
Arrow keys | Move cursor |
hjkl | Same as arrow keys |
insert / i | Insert text |
x | delete a character |
dw | delete a word |
dd | delete a line |
nG go to the beginning of the
3dd | deletes 3 lines |
u | undo previous change |
ZZ | exit vi , saving changes |
ESC | end insert or incomplete command |
DEL | (delete or rubout) interrupts |
^H | erase last character (backspace) |
^W | erase last word |
specified line (end default), where n is a line number
/pat search pat (next line matching pat)
^E scroll window down one line
^Y scroll window up one line
H top line on screen
L last line on screen
M middle line on screen
Good Luck
Comments
Post a Comment