linux,unix essentiaks and shell scripting by santosh .pptx

Download Linux,Unix Essentiaks and Shell Scripting by Santosh .pptx

Post on 07-Dec-2015

4 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

Shell Scripting

Linux Basics and Shell ScriptingPresentation by V.SANTOSH

1AgendaLinux, Unix EssentialsVi editorUnix, Linux ArchitectureFile, ProcessDirectory StructureBasic commandsPermissions for files, dirsShell Scripting2Linux History1984: The GNU Project and the Free Software FoundationCreates open source version of UNIX utilitiesCovered by General Public License (GPL) ( Copy Left)Software license enforcing open source principles1991: Linus TrovaldsCreates open source, UNIX-like kernel, released under the GPLPorts some GNU utilities, solicits assistance onlineToday:Linux kernel + GNU utilities = complete, open source, UNIX-like operating systemPackaged for targeted audiences asdistributions

Introduction to LinuxUnix was one of the earliest OS It was a proprietary OSRichard Stallman and others started theFSF(Free Software Foundation)GNU (GNU Not Unix) = A project of FSF provided the shell and applications for the new OSLinux Trovalds in 1991 provided the kernelAnd the new OS was called Linux.4Introduction to Linux Contd.Linux is an Open Source OS meaning the source code is free.Open Source means freedom of Speech5Different Linux Distributions ( Distros)1) Fedora = Test bed for new applications etc. For testing , Free no support

2) Redhat ,SUSE = Stable used in production environment Not free we need to subscribe, we Get support.

3) Debian = Free, no support Used for testing, used in production Environment to some extent

4) Mandrinova = Free, no support Used for testing, used in production Environment to some extent

5) Ubuntu = Free, no support Used for testing, used in production Environment to some extent Good for client machines

6Features of LinuxOpen Source OSMultiuserMultitaskingStable and robust OSLess prone to virus attacks7

Linux principles

Everything is a file (including hardware)Small, single-purpose programsAbility to chain programs together to perform complex tasksAvoid captive user interfacesConfiguration data stored in text

8

Production Environment Features

Recent Kernel Developments Filesystems: Mundane and Advanced Disk Striping and RAID Parallel Processing and Clustering Enterprise Networking Features9Unix, Linux ArchitectureTypical computer system consists of:HardwareOperating systemApplications and utilitiesTypical OS includes a user interface or command interpreterUnix is somewhat unique in that the command interpreter is not integrated with the OS but is a separate program

10Layered Architecture of Linux and Unix11Kernel= Performs core functions of the OS Interacts with HardwareShell= Interface between the user and the Kernel . Performs the command interpretationUtilities, Applications

Directory Structure12All the files are grouped together in the 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 / ) File and processEverything in UNIX 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.) the text of a program written in some high-level programming language instructions comprehensible directly to the machine and incomprehensible to a casual user, for example, a collection of binary digits (an executable or binary file); a directory, containing information about its contents, which may be a mixture of other directories (subdirectories) and ordinary files.

13Linux Directory StructureDirectory Purpose/bootContains kernel, bootloader and initrd /binEssential command binaries/dev Device files/etcsystem configuration files.server config files/homeHome dir for regular users/libEssential shared libraries and kernel modules./procPseudo filesystem used by kernel for itsProcesses/rootHome dir for root user/sbinEssential command binaries generally used by super user/tmpFolder for temporary files all users haveFull permission here with sticky bit set/usrThe base directory for most shareable, read-only data (programs, libraries,documentation, and much more)./varmail and printer spools, log files, lock files, etc./media,/mntMount points for removable media14Logging into a Linux SystemTwo types of login screens: virtual consoles (text-based) and graphical logins (called display managers) Login using login name and password Each user has a home directory for personal file storage

15Virtual ConsolesBy default, we have :6 CUI virtual consoles ctrl + alt +f1 upto f61 Graphical console16Changing PasswordPasswords control access to the system To change your password using GNOME, navigate to System->Preferences->About Me and then click Password. To change your password from a terminal: passwd

17Basic Command Syntaxcommand options arguments Options are switches for additional infoArguments are file or dirnames or anyOther data required by the commandEx : ls l /root ls = command-l = long listing (option)/root =Argument18Command HelpDifferent levels of help whatis Single line info about the commandcommand help Short help with switches man complete help (manual pages) info Information regarding the command/usr/share/doc/ folder has files containing documentation regarding the command Red Hat documentation =www.redhat.com/docs for guides,howtos etc

19Basic commandsCommand What it doespwd present working directory ls content of pwdll similar as ls, but provides additional info on files and directories ll a includes hidden files (.name) as well ll R lists subdirectories recursively ll t lists files in chronological orderstat provides all attributes of a file whoami shows as who you are logged in hostname shows on which machine you are20File , Directory Naming RulesNames may be up to 255 characters All characters are valid, except the forward-slashIt may be unwise to use certain special characters in file or directory names Some characters and space should be protected with quotes when referencing them File, Dir Names are case-sensitive

21Path = Absolute path ,relative pathAbsolute pathnamesBegin with a forward slashComplete "road map" to file location Can be used anytime you wish to specify a file name Relative pathnamesDo not begin with a slashSpecify location relative to your current working directoryCan be used as a shorter way to specify a file name

22Creating dir , filesCommand Purposemkdir < dirname>To create a dir touch < filename>Creates a zero byte file or empty file cat > Creates a file with content save and exitWith ctrl +dcat Displays the contents of the file tac Displays the contents of the file inreverse23Changing directoriesCommand Purposecd change to that directorycd .. change to a directory one level upcd change to your home directory cd - change to your previous working dir

24How to list directory contents ?ls command Lists the contents of the current directory or a specified directorySyntax: ls [options] [files_or_dirs]

ls -a (include hidden files)ls -l (display extra information)ls -R (recurse through directories)ls -ld (directory and symlink information)

25Copy files and dirscp command to copy files and directories Syntax : cp [options] More than one file may be copied at a time if the destination is a directory: Ex : cp [options] filea fileb dest Note : the last argument should be a dir

26Renaming files and dirsmv command to move and/or rename files and directoriesSyntax : mv [options] More than one file may be moved at a time if the destination is a directory:mv [options] file1 file2 destinationNote : Last argument must be a dir in case of moving mutiple filesIf the destination does not exist, the file will beRenamed.

27Deleting filesrm command to remove filesSyntax : rm [options] ...Example:rm -i file (interactive)= Prompts the user before deletionrm -r directory (recursive)rm -f file (force)=Does not prompt the user, deletes the file forcefully

28Deleting directoriesrmdir removes empty directoriesrm -r recursively removes directory trees Note : use rm r with caution always check with ls R before deletionOr combine with i i.e. rm ri =Prompts before deleting each file and the dir29Check file typeFiles can contain many types of data We need to check file type with file before opening to determine appropriate command or application to use file [options]

30Seven fundamental file types- regular filed directoryl symbolic link or soft linkb block special file Ex: hdd /dev/hda or /dev/sdac character special file Ex: serial port /dev/ttyS0, parallel port /dev/lp0 p named pipe used to pass data bw processess socket End point for communication 3131Important commands for system infoSl NoCommandDescription1.2.3.4.5.6.7.

8.9.

10.

11,pswiddfdu du -s top

freecat /proc/cpuinfocat /proc/meminfouname aLists currently running process (programs).Show who is logged on and what they are doing.Print your user-id and group id'sReport filesystem disk space usage (Disk Free is how I remember it)Disk Usage in a pa

Recommended

View more >