SlideShare une entreprise Scribd logo
1  sur  23
Linux Shell
   Scripting

MOHAMED ABUBAKAR SITTIK A
         327218
Linux operating system
Linux Directory Structure

           /bin – User Binaries
           Contains binary executables.
           Common linux commands you need to use in single-
           /sbin – System Binaries
           user modes/bin,located under this directory.
           Just like are /sbin also contains binary executables.
           /etc – the linux commands located under this directory
           But, Configuration Files
           Commands used by all the users of the system are
           Contains configuration files required by all programs.
           located here.
           are used typically by system aministrator, for system
           /dev –also contains startup and shutdown shell scripts
                    Device Files
           Thisexample: ps, ls, ping, grep, cp.
              For
           maintenance purpose.
           Contains device individual programs.
                               files.
           used example: iptables, reboot, fdisk, ifconfig, swapon
           Forto start/stop Information
             /proc – Process
           These include terminal devices, usb, or any device
           For example: /etc/resolv.conf, /etc/logrotate.conf
             Contains information about system process.
           attachedVariable Files
             This to the system.
             /var – is a pseudo filesystem contains information
           For example: /dev/tty1,files.
             var stands for process./dev/usbmon0
           /tmp – running variable For example: /proc/{pid}
             about Temporary Files
             Contentcontains information about the process with
             directory of the files that are expected to grow can be
           /found under this directory.
              – Root
           Everyincludespid.system log files (/var/log); packages
             that particular
           /usr – Userthat contains temporary files createdroot
           Directory Programs
             This is a virtualand directory starts from the
                     single file
                              — filesystem with text information
                                                                   by
             This and binaries, libraries, documentation, and source-code
           Contains users.
           system
           directory.
             and database filesdirectory example: /proc/uptime
             about – Home (/var/lib); emails (/var/mail); print
           for /media – Removable Media Devices directory.
           Files system thisDirectories deleted when system is
           /homeunder resources. Forare (/var/lock); temp files
           Only root userprograms. privilege under this
                second level has write
           /boot – (/var/spool); lock root
           rebooted.note that /root is files user’s home directory,
             queues Boot Loader Files
           /usr/bin contains binary files for user programs. If you can’t
           Please across reboots (/var/tmp);
             needed
           find Temporary mount directory forstore under personal
           Homeuser same as for all users to look their devices.
                                   under /bin, removable /usr/bin. For
                
           which is not binary /.
                  a
                For directories
                    – at, examples, related files.
                       Service Data /media/cdrom
               /srvSystem Libraries
           example: boot loader scp
           Contains awk, cc, less,
           /lib –                                        for   CD-ROM;
           files.
           /usr/sbin contains floppy /home/nikita
           Kernel initrd,/home/john, drives; /media/cdrecorder for If
                /media/floppy for binary files for system administrator.
           /opt – Optional add-on grub files are located under
              For example: vmlinux, Applications
           youCD writerlibrary system binary under /sbin, look under
               srv stands for service. that supports the binaries
           /bootcan’t find a files
           Contains
           /usr/sbin. Forserver specific cron, sshd, useradd, userdel
           opt stands for Directory services related data.
               Contains
           For – Mount initrd.img-2.6.32-24-generic, vmlinuz-
           locatedexample: optional.
            /mnt under /bin and /sbin
                            example: atd,
           2.6.32-24-generic /srv/cvs contains CVS related data.
               For example,
           /usr/lib contains are applications lib*.so.* /usr/sbin
              Library filenames libraries for /usr/bin and individual
              Contains add-on either ld* or from
            For example: mount users programs sysadmins can
               Temporary ld-2.11.1.so, libncurses.so.5.7
           /usr/local contains directory where that you install from
           vendors.
           source. filesystems. when you install installedfrom source, it
           add-on applications should be apache under
            mount For example,
           goes under /usr/local/apache2
           either /opt/ or /opt/ sub-directory.
Moving around the file system

cd - Change Directory Directory
pwd - Present Working

$ pwd
/home/srahuma
$ cd test
$ cd dir1
                              $ pwd
$ cd ..
                              /home/srahuma/test
                              $ pwd
$ cd $HOME
                              $ pwd
                              /home/srahuma/test/dir1
$ cd ~rxbala2
$                             $ pwd
                              /home/srahuma/test
                              /home/srahuma
                              $ pwd
                              /home/rxbala2
                              $
                              $
Listing directory contents

 ls list a directory
 ls -l List a directory in long (detailed) format
   For example:
   drwxr-xr-x 2 srahuma qdefault     4096 Jun 5 01:03 HL4IT1019
   -rw-r--r-- 1 srahuma qdefault     4577 Aug 24 21:00 ftplog


                  owner group            size date time name
               number of links to file or directory contents
           permissions for world
       permissions for members of group
     permissions for owner of file: r = read, w = write, x = execute -=no permission
   type of file: - = normal file, d=directory, l = symbolic link, and others...
 ls -a      List the current directory including hidden files. Hidden files start with "."
 ls -ld *   List all the file and directory names in the current directory using long format.

   Without the "d" option, ls would list the contents of any sub-directory of the current. With
   the "d" option, ls just lists them like regular files.
Changing file permissions and attributes

 chmod 755 file      Changes the permissions of file to be rwx for the owner, and
  rx for the group and the world. (7 = rwx = 111 binary. 5 = r-x = 101 binary)

 chgrp user file    Makes file belong to the group user

 chown cliff file   Makes cliff the owner of file.

 chown -R cliff dir Makes cliff the owner of dir and everything in its directory
  tree.

  You must be the owner of the file/directory or be root before you can do any of
  these things.
Moving, renaming and copying files

 cp file1 file2         copy a file
   mv file1 newname         move or rename a file
   mv file1 ~/AAA/        move file1 into sub-directory AAA in your home directory.
   rm file1 [file2 ...] remove or delete a file
   rm -r dir1 [dir2...] recursively remove a directory and its contents BE
    CAREFUL!
   mkdir dir1 [dir2...] create directories
   mkdir -p dirpath       create the directory dirpath, including all implied directories
    in the path.
   rmdir dir1 [dir2...] remove an empty directory
Viewing and editing files

 cat filename
    Dump a file to the screen in ascii.
   more filename
    Progressively dump a file to the screen: ENTER = one line down SPACEBAR =
    page down q=quit
   less filename
    Like more, but you can use Page-Up too. Not on all systems.
   head -n filename
    Show the first n lines of a file.
   tail -n filename
    Show the last n lines of a file.
   vi filename
    Edit a file using the vi editor. All UNIX systems will have vi in some form.
Redirecting output

Echo “This is a sample text” > sample.txt
Echo “This is the first line” > sample.txt
Echo “Adding second line” >> sample.txt

                           Sample.txt

            This is the firsttext
                    a sample line
            Adding second line
Piping the output

cat sample.txt | head -1 | cut –d’ ‘ –f4




   This is the first line is the first line
                      This
                                   first
   Adding second line
Command Substitution

 You can use the output of one command as an input to another command in
  another way called command substitution. Command substitution is invoked
  when by enclosing the substituted command in backwards single quotes.

         for example:
         cat `find . -name aaa.txt`

  which will cat ( dump to the screen ) all the files named aaa.txt that exist in the
  current directory or in any subdirectory tree.

 You can also use this ` `(backward single quotes) to assign the result of a
  command to a variable

         for example,
         a=5
         b=4
         value=`expr $a * $b`
Searching for files

                  find search_path -name filename

 find . -name aaa.txt


   Finds all the files named aaa.txt in the current directory or any subdirectory
   tree.

 find / -name vimrc


   Find all the files named 'vimrc' anywhere on the system.

 find /usr/local/games -name "*xpilot*"


   Find all files whose names contain the string 'xpilot' which exist within the
   '/usr/local/games' directory tree.
Searching in the files

 Grep command is used to search for a specific pattern in a file. Displays the
  line with the matching pattern. It can be executed with more options.

 grep -w <pattern> <filename>
  Searches for the expression as a complete word, ignoring those matches that
  are substrings of larger words.
 grep -i <pattern> <filename>
  Searches for both uppercase and lowercase characters
 grep -v <pattern> <filename>
  Inverts the search to display lines that do not match the pattern
 grep -n <pattern> <filename>
  Precede each matching line with the line number
Searching in the files (contd.)

 grep ’^pattern’ <filename>
  Matches all lines beginning with “pattern”

 grep ’pattern$’ <filename>
  Matches all lines ending with “pattern”

 grep ’p.....n’ <filename>
  Matches lines containing a “p,” followed by Five characters, and followed by an
  “n” pattern

 grep -c <pattern> <filename>
  Prints only the total count of the matching lines
Archiving

 The tar command stands for "tape archive". It is the "standard" way to read and
  write archives (collections of files and whole directory trees).
 stuff.tar, or stuff.tar.gz
  tar examples:
 tar cvf archive.tar file1 [file2...]
   Create a tar archive as a file "archive.tar" containing file1, file2...etc.

 tar xvf archive.tar extract from the archive file

 tar cvfz archive.tar.gz dname
   Create a gzip compressed tar archive containing everything in the directory
   'dname'. This does not work with all versions of tar.

 tar xvfz archive.tar.gz
   Extract a gzip compressed tar archive. Does not work with all versions of tar.
Compressing

 The standard UNIX compression commands are compress and uncompress.
    Compressed files have a suffix .Z added to their name.

         compress part.igs Creates a compressed file part.igs.Z
         uncompress part.igs Uncompresses part.igs from the compressed file
                                 part.igs.Z.
    Note the .Z is not required.

 Another common compression utility is gzip (and gunzip). gzip usually gives
    better compression than standard compress, but may not be installed on all
    systems. The suffix for gzipped files is .gz

         gzip part.igs Creates a compressed file part.igs.gz
         gunzip part.igs Extracts the original file from part.igs.gz
Looking for help

 Most of the commands have a manual page which give sometimes useful, often
  more or less detailed, sometimes cryptic and unfathomable descriptions of their
  usage.

  man ls     Shows the manual page for the ls command

 You can search through the man pages using apropos
  Example:
  apropos build Shows a list of all the man pages whose descriptions contain
  the word "build"

 type – command will give the directory that contains the executable of a Linux
  command.

  type grep – Will give the result below
        grep is a tracked alias for /bin/grep
Basics of vi editor

 Opening a file
  vi filename

 Creating text
  Edit modes: These keys enter editing modes and type in the text of your
  document.

  i   Insert before current cursor position
  I   Insert at beginning of current line
  a   Insert (append) after current cursor position
  A   Append to end of line
  r   Replace 1 character
  R   Replace mode
  <ESC>Terminate insertion or overwrite mode
Basics of vi editor (contd.)

 Deletion of text


  x Delete single character
  dd Delete current line and put in buffer
  ndd Delete n lines (n is a number) and put them in buffer
  J Attaches the next line to the end of the current line (deletes carriage
  return).

 Oops


  u   Undo last command
Basics of vi editor (contd.)

Cut and paste
   yy    Yank current line into buffer
   nyy    Yank n lines into buffer
   p     Put the contents of the buffer after the current line
   P     Put the contents of the buffer before the current line

Cursor positioning
   ^d Page down
   ^u Page up
   :n Position cursor at line n
   :$ Position cursor at end of file
   ^g Display current line number
   h,j,k,l Left,Down,Up, and Right respectively.
Basics of vi editor (contd.)

String substitution

 :n1,n2:s/string1/string2/[g]    Substitute string2 for string1 on lines n1 to n2. If g
  is included (meaning global), all instances of string1 on each line are
  substituted. If g is not included, only the first instance per matching line is
  substituted.

 ^ matches start of line
 . matches any single character
 $ matches end of line


Examples:

:1,$:s/dog/cat/g             Substitute 'cat' for 'dog', every instance for the entire
                            file - lines 1 to $ (end of file)

:23,25:/frog/bird/          Substitute 'bird' for 'frog' on lines 23 through 25. Only
                            the first instance on each line is substituted.
Basics of vi editor (contd.)

Saving and quitting and other "ex" commands
  These commands are all prefixed by pressing colon (:) and then entered in the
  lower left corner of the window. They are called "ex" commands because they
  are commands of the ex text editor - the precursor line editor to the screen
  editor vi. You cannot enter an "ex" command when you are in an edit mode
  (typing text onto the screen)

 Press <ESC> to exit from an editing mode.

   :w                Write the current file.
   :w new.file       Write the file to the name 'new.file'.
   :w! existing.file Overwrite an existing file with the file currently being edited.
   :wq               Write the file and quit.
   :q                Quit.
   :q!               Quit with no changes.
   :e filename       Open the file 'filename' for editing.
   :set number       Turns on line numbering
   :set nonumber Turns off line numbering
In our upcoming session


Variables ($# $1 …)
External programs
Functions
Escape Characters
Loops – for loops and while loops
Test – if statements
Case
Using awk and sed
Job control and process management

Contenu connexe

Tendances

Linux shell env
Linux shell envLinux shell env
Linux shell envRahul Pola
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell ScriptingJaibeer Malik
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script Amit Ghosh
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scriptingVIKAS TIWARI
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash scriptSimon Su
 
Shell programming 1.ppt
Shell programming  1.pptShell programming  1.ppt
Shell programming 1.pptKalkey
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scriptingEasiest way to start with Shell scripting
Easiest way to start with Shell scriptingAkshay Siwal
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Module 02 Using Linux Command Shell
Module 02 Using Linux Command ShellModule 02 Using Linux Command Shell
Module 02 Using Linux Command ShellTushar B Kute
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell ScriptingMustafa Qasim
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in LinuxAnu Chaudhry
 
Unix Commands
Unix CommandsUnix Commands
Unix CommandsDr.Ravi
 

Tendances (20)

Linux shell env
Linux shell envLinux shell env
Linux shell env
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash script
 
Shell programming 1.ppt
Shell programming  1.pptShell programming  1.ppt
Shell programming 1.ppt
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scriptingEasiest way to start with Shell scripting
Easiest way to start with Shell scripting
 
Unix - Shell Scripts
Unix - Shell ScriptsUnix - Shell Scripts
Unix - Shell Scripts
 
Unix shell scripts
Unix shell scriptsUnix shell scripts
Unix shell scripts
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Module 02 Using Linux Command Shell
Module 02 Using Linux Command ShellModule 02 Using Linux Command Shell
Module 02 Using Linux Command Shell
 
Bash shell
Bash shellBash shell
Bash shell
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
 
Linux Shell Basics
Linux Shell BasicsLinux Shell Basics
Linux Shell Basics
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
 
Unix Commands
Unix CommandsUnix Commands
Unix Commands
 

En vedette

Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scriptingvceder
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Scriptstudent
 
Network configuration
Network configurationNetwork configuration
Network configurationengshemachi
 
Unix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell ScriptUnix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell Scriptsbmguys
 

En vedette (9)

Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Basics of shell programming
Basics of shell programmingBasics of shell programming
Basics of shell programming
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Producer Consumer Problem
Producer Consumer Problem  Producer Consumer Problem
Producer Consumer Problem
 
Scripting and the shell in LINUX
Scripting and the shell in LINUXScripting and the shell in LINUX
Scripting and the shell in LINUX
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Script
 
Network configuration
Network configurationNetwork configuration
Network configuration
 
Unix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell ScriptUnix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell Script
 

Similaire à Linux shell scripting

BITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS
 
Basic linux architecture
Basic linux architectureBasic linux architecture
Basic linux architectureRohit Kumar
 
Lesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemLesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemSadia Bashir
 
An Introduction to Linux
An Introduction to LinuxAn Introduction to Linux
An Introduction to LinuxDimas Prasetyo
 
Command Line Tools
Command Line ToolsCommand Line Tools
Command Line ToolsDavid Harris
 
Linux basic for CADD biologist
Linux basic for CADD biologistLinux basic for CADD biologist
Linux basic for CADD biologistAjay Murali
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unixsouthees
 
Linux file system nevigation
Linux file system nevigationLinux file system nevigation
Linux file system nevigationhetaldobariya
 
linux-file-system01.ppt
linux-file-system01.pptlinux-file-system01.ppt
linux-file-system01.pptMeesanRaza
 

Similaire à Linux shell scripting (20)

File system discovery
File system discovery File system discovery
File system discovery
 
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentation
 
Basics of Linux
Basics of LinuxBasics of Linux
Basics of Linux
 
Basic linux architecture
Basic linux architectureBasic linux architecture
Basic linux architecture
 
Linux file
Linux fileLinux file
Linux file
 
Lesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemLesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File System
 
Directories description
Directories descriptionDirectories description
Directories description
 
An Introduction to Linux
An Introduction to LinuxAn Introduction to Linux
An Introduction to Linux
 
Command Line Tools
Command Line ToolsCommand Line Tools
Command Line Tools
 
Linux Commands
Linux CommandsLinux Commands
Linux Commands
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
Unix Basics For Testers
Unix Basics For TestersUnix Basics For Testers
Unix Basics For Testers
 
Linux basic for CADD biologist
Linux basic for CADD biologistLinux basic for CADD biologist
Linux basic for CADD biologist
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unix
 
Tutorial 2
Tutorial 2Tutorial 2
Tutorial 2
 
Linux file system nevigation
Linux file system nevigationLinux file system nevigation
Linux file system nevigation
 
Ppt
PptPpt
Ppt
 
linux-file-system01.ppt
linux-file-system01.pptlinux-file-system01.ppt
linux-file-system01.ppt
 
Linux filesystemhierarchy
Linux filesystemhierarchyLinux filesystemhierarchy
Linux filesystemhierarchy
 

Dernier

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 

Dernier (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 

Linux shell scripting

  • 1. Linux Shell Scripting MOHAMED ABUBAKAR SITTIK A 327218
  • 3. Linux Directory Structure /bin – User Binaries Contains binary executables. Common linux commands you need to use in single- /sbin – System Binaries user modes/bin,located under this directory. Just like are /sbin also contains binary executables. /etc – the linux commands located under this directory But, Configuration Files Commands used by all the users of the system are Contains configuration files required by all programs. located here. are used typically by system aministrator, for system /dev –also contains startup and shutdown shell scripts Device Files Thisexample: ps, ls, ping, grep, cp. For maintenance purpose. Contains device individual programs. files. used example: iptables, reboot, fdisk, ifconfig, swapon Forto start/stop Information /proc – Process These include terminal devices, usb, or any device For example: /etc/resolv.conf, /etc/logrotate.conf Contains information about system process. attachedVariable Files This to the system. /var – is a pseudo filesystem contains information For example: /dev/tty1,files. var stands for process./dev/usbmon0 /tmp – running variable For example: /proc/{pid} about Temporary Files Contentcontains information about the process with directory of the files that are expected to grow can be /found under this directory. – Root Everyincludespid.system log files (/var/log); packages that particular /usr – Userthat contains temporary files createdroot Directory Programs This is a virtualand directory starts from the single file — filesystem with text information by This and binaries, libraries, documentation, and source-code Contains users. system directory. and database filesdirectory example: /proc/uptime about – Home (/var/lib); emails (/var/mail); print for /media – Removable Media Devices directory. Files system thisDirectories deleted when system is /homeunder resources. Forare (/var/lock); temp files Only root userprograms. privilege under this second level has write /boot – (/var/spool); lock root rebooted.note that /root is files user’s home directory, queues Boot Loader Files /usr/bin contains binary files for user programs. If you can’t Please across reboots (/var/tmp); needed find Temporary mount directory forstore under personal Homeuser same as for all users to look their devices. under /bin, removable /usr/bin. For  which is not binary /. a For directories – at, examples, related files. Service Data /media/cdrom /srvSystem Libraries example: boot loader scp Contains awk, cc, less, /lib – for CD-ROM; files. /usr/sbin contains floppy /home/nikita Kernel initrd,/home/john, drives; /media/cdrecorder for If /media/floppy for binary files for system administrator. /opt – Optional add-on grub files are located under For example: vmlinux, Applications youCD writerlibrary system binary under /sbin, look under srv stands for service. that supports the binaries /bootcan’t find a files Contains /usr/sbin. Forserver specific cron, sshd, useradd, userdel opt stands for Directory services related data. Contains For – Mount initrd.img-2.6.32-24-generic, vmlinuz- locatedexample: optional. /mnt under /bin and /sbin example: atd, 2.6.32-24-generic /srv/cvs contains CVS related data. For example, /usr/lib contains are applications lib*.so.* /usr/sbin Library filenames libraries for /usr/bin and individual Contains add-on either ld* or from For example: mount users programs sysadmins can Temporary ld-2.11.1.so, libncurses.so.5.7 /usr/local contains directory where that you install from vendors. source. filesystems. when you install installedfrom source, it add-on applications should be apache under mount For example, goes under /usr/local/apache2 either /opt/ or /opt/ sub-directory.
  • 4. Moving around the file system cd - Change Directory Directory pwd - Present Working $ pwd /home/srahuma $ cd test $ cd dir1 $ pwd $ cd .. /home/srahuma/test $ pwd $ cd $HOME $ pwd /home/srahuma/test/dir1 $ cd ~rxbala2 $ $ pwd /home/srahuma/test /home/srahuma $ pwd /home/rxbala2 $ $
  • 5. Listing directory contents  ls list a directory  ls -l List a directory in long (detailed) format For example: drwxr-xr-x 2 srahuma qdefault 4096 Jun 5 01:03 HL4IT1019 -rw-r--r-- 1 srahuma qdefault 4577 Aug 24 21:00 ftplog owner group size date time name number of links to file or directory contents permissions for world permissions for members of group permissions for owner of file: r = read, w = write, x = execute -=no permission type of file: - = normal file, d=directory, l = symbolic link, and others...  ls -a List the current directory including hidden files. Hidden files start with "."  ls -ld * List all the file and directory names in the current directory using long format. Without the "d" option, ls would list the contents of any sub-directory of the current. With the "d" option, ls just lists them like regular files.
  • 6. Changing file permissions and attributes  chmod 755 file Changes the permissions of file to be rwx for the owner, and rx for the group and the world. (7 = rwx = 111 binary. 5 = r-x = 101 binary)  chgrp user file Makes file belong to the group user  chown cliff file Makes cliff the owner of file.  chown -R cliff dir Makes cliff the owner of dir and everything in its directory tree. You must be the owner of the file/directory or be root before you can do any of these things.
  • 7. Moving, renaming and copying files  cp file1 file2 copy a file  mv file1 newname move or rename a file  mv file1 ~/AAA/ move file1 into sub-directory AAA in your home directory.  rm file1 [file2 ...] remove or delete a file  rm -r dir1 [dir2...] recursively remove a directory and its contents BE CAREFUL!  mkdir dir1 [dir2...] create directories  mkdir -p dirpath create the directory dirpath, including all implied directories in the path.  rmdir dir1 [dir2...] remove an empty directory
  • 8. Viewing and editing files  cat filename Dump a file to the screen in ascii.  more filename Progressively dump a file to the screen: ENTER = one line down SPACEBAR = page down q=quit  less filename Like more, but you can use Page-Up too. Not on all systems.  head -n filename Show the first n lines of a file.  tail -n filename Show the last n lines of a file.  vi filename Edit a file using the vi editor. All UNIX systems will have vi in some form.
  • 9. Redirecting output Echo “This is a sample text” > sample.txt Echo “This is the first line” > sample.txt Echo “Adding second line” >> sample.txt Sample.txt This is the firsttext a sample line Adding second line
  • 10. Piping the output cat sample.txt | head -1 | cut –d’ ‘ –f4 This is the first line is the first line This first Adding second line
  • 11. Command Substitution  You can use the output of one command as an input to another command in another way called command substitution. Command substitution is invoked when by enclosing the substituted command in backwards single quotes. for example: cat `find . -name aaa.txt` which will cat ( dump to the screen ) all the files named aaa.txt that exist in the current directory or in any subdirectory tree.  You can also use this ` `(backward single quotes) to assign the result of a command to a variable for example, a=5 b=4 value=`expr $a * $b`
  • 12. Searching for files find search_path -name filename  find . -name aaa.txt Finds all the files named aaa.txt in the current directory or any subdirectory tree.  find / -name vimrc Find all the files named 'vimrc' anywhere on the system.  find /usr/local/games -name "*xpilot*" Find all files whose names contain the string 'xpilot' which exist within the '/usr/local/games' directory tree.
  • 13. Searching in the files  Grep command is used to search for a specific pattern in a file. Displays the line with the matching pattern. It can be executed with more options.  grep -w <pattern> <filename> Searches for the expression as a complete word, ignoring those matches that are substrings of larger words.  grep -i <pattern> <filename> Searches for both uppercase and lowercase characters  grep -v <pattern> <filename> Inverts the search to display lines that do not match the pattern  grep -n <pattern> <filename> Precede each matching line with the line number
  • 14. Searching in the files (contd.)  grep ’^pattern’ <filename> Matches all lines beginning with “pattern”  grep ’pattern$’ <filename> Matches all lines ending with “pattern”  grep ’p.....n’ <filename> Matches lines containing a “p,” followed by Five characters, and followed by an “n” pattern  grep -c <pattern> <filename> Prints only the total count of the matching lines
  • 15. Archiving  The tar command stands for "tape archive". It is the "standard" way to read and write archives (collections of files and whole directory trees).  stuff.tar, or stuff.tar.gz tar examples:  tar cvf archive.tar file1 [file2...] Create a tar archive as a file "archive.tar" containing file1, file2...etc.  tar xvf archive.tar extract from the archive file  tar cvfz archive.tar.gz dname Create a gzip compressed tar archive containing everything in the directory 'dname'. This does not work with all versions of tar.  tar xvfz archive.tar.gz Extract a gzip compressed tar archive. Does not work with all versions of tar.
  • 16. Compressing  The standard UNIX compression commands are compress and uncompress. Compressed files have a suffix .Z added to their name.  compress part.igs Creates a compressed file part.igs.Z  uncompress part.igs Uncompresses part.igs from the compressed file part.igs.Z. Note the .Z is not required.  Another common compression utility is gzip (and gunzip). gzip usually gives better compression than standard compress, but may not be installed on all systems. The suffix for gzipped files is .gz  gzip part.igs Creates a compressed file part.igs.gz  gunzip part.igs Extracts the original file from part.igs.gz
  • 17. Looking for help  Most of the commands have a manual page which give sometimes useful, often more or less detailed, sometimes cryptic and unfathomable descriptions of their usage. man ls Shows the manual page for the ls command  You can search through the man pages using apropos Example: apropos build Shows a list of all the man pages whose descriptions contain the word "build"  type – command will give the directory that contains the executable of a Linux command. type grep – Will give the result below grep is a tracked alias for /bin/grep
  • 18. Basics of vi editor  Opening a file vi filename  Creating text Edit modes: These keys enter editing modes and type in the text of your document. i Insert before current cursor position I Insert at beginning of current line a Insert (append) after current cursor position A Append to end of line r Replace 1 character R Replace mode <ESC>Terminate insertion or overwrite mode
  • 19. Basics of vi editor (contd.)  Deletion of text x Delete single character dd Delete current line and put in buffer ndd Delete n lines (n is a number) and put them in buffer J Attaches the next line to the end of the current line (deletes carriage return).  Oops u Undo last command
  • 20. Basics of vi editor (contd.) Cut and paste  yy Yank current line into buffer  nyy Yank n lines into buffer  p Put the contents of the buffer after the current line  P Put the contents of the buffer before the current line Cursor positioning  ^d Page down  ^u Page up  :n Position cursor at line n  :$ Position cursor at end of file  ^g Display current line number  h,j,k,l Left,Down,Up, and Right respectively.
  • 21. Basics of vi editor (contd.) String substitution  :n1,n2:s/string1/string2/[g] Substitute string2 for string1 on lines n1 to n2. If g is included (meaning global), all instances of string1 on each line are substituted. If g is not included, only the first instance per matching line is substituted.  ^ matches start of line  . matches any single character  $ matches end of line Examples: :1,$:s/dog/cat/g Substitute 'cat' for 'dog', every instance for the entire file - lines 1 to $ (end of file) :23,25:/frog/bird/ Substitute 'bird' for 'frog' on lines 23 through 25. Only the first instance on each line is substituted.
  • 22. Basics of vi editor (contd.) Saving and quitting and other "ex" commands These commands are all prefixed by pressing colon (:) and then entered in the lower left corner of the window. They are called "ex" commands because they are commands of the ex text editor - the precursor line editor to the screen editor vi. You cannot enter an "ex" command when you are in an edit mode (typing text onto the screen)  Press <ESC> to exit from an editing mode.  :w Write the current file.  :w new.file Write the file to the name 'new.file'.  :w! existing.file Overwrite an existing file with the file currently being edited.  :wq Write the file and quit.  :q Quit.  :q! Quit with no changes.  :e filename Open the file 'filename' for editing.  :set number Turns on line numbering  :set nonumber Turns off line numbering
  • 23. In our upcoming session Variables ($# $1 …) External programs Functions Escape Characters Loops – for loops and while loops Test – if statements Case Using awk and sed Job control and process management