SlideShare a Scribd company logo
Remembering the basics – Week 1
   Dan Morrill April 01 2013
 RMDIR – removes a directory only if it is empty
 RMDIR –r – removes a directory regardless if it is
  empty or not
 CHMOD 777 –r /user/dan – recursively changes the
  permissions of the directory /user/dan to
  RWXRWXRWX
 grep – pattern matching for example ps –ef |grep
  apache2 will look for all processes running under the
  name apache2
   egrep – used in regular expressions
 find – find the location of a file (or files) on a hard
  drive at the command line
 echo – writes data to the screen (standard output)
   The TTY – Screen is always standard output (STDOUT)
 more – displays the contents of a file one page at a time
  (hard for long files like syslog)
 clear – clears the screen of text and provides the
  command prompt
 chown – change the owner of a file or directory
 rm – remove a file
 mv – move a file to a new place and or new name
 chgrp – change the group ownership of a file
 mkdir – make a directory
 ls – list the files in a directory, ls –la show the long
  form (including permissions and owners) of the files
  in a directory
 cat – an alternative to showing the data in a file all at
  once
 pwd – display the current directory
 passwd – change the password of the currently logged
  in user
 >> - append data to the END of a file
 > - overwrites the file and any data in it
 | - pipe character – strings commands together
 || - logical OR – in that A || B in a loop, condition A or
  condition B
 & - executes your process in the background – so you can
  still use the command line ./script.sh & will run your
  process in the background
 && - Logical AND A && B if A succeeds, run B
 sleep – stop execution of the script for a specified number
  of seconds sleep 20 means sleep for 20 seconds
 diff – compares two files (this is great for seeing what
    changes were made in a script against the original and
    modified)
   sdiff – only works with the 132 character display, but
    compares files side by side
   lp – prints a file to the configured printer
   lpstat – shows the user what is in the printer queue
   ( ) – runs the enclosed command in a sub-shell
   (( )) – evaluates and assigns a value to a variable and
    does math in a sub-shell
 $(( )) – evaluates the enclosed expression
 [ ] – test an expression to see if it is true or false
 < > - used to compare values or strings
 $( ) – command substitution – great when doing
  logical OR’s or AND’s
 ++ - auto increment a value for I=1 ++ (takes I up by 1
  for every loop)
 -- - auto decrement a value for I=100 -- (takes I down
  by 1 for every loop)
 <= - less than or equal to
 >= - greater than or equal to
 I will expect to see this in the header of every Unix Script
    you will turn in:
   #!/bin/sh (tells the computer to use a bourne shell)
   #
   # Script: Name of script (what you named this file)
   # Author: Your Name (so I know who wrote it)
   #Date: (the date you wrote it)
   #Revision: 1.1.A(how many times it changed, and what
    state it is in(A, B, D, T or P)
     All scripts should also have A, B, D, T or P at the end of the
      revision statement so I know if it is Alpha, Beta, Dev, Test, or
      Production. All scripts turned in should be production scripts
 How to get your script to do more useful stuff
   If. Then
   if [test]
       Then
        stuff I want the computer to do
      fi
   If. Then. Else
      if [test]
        Then
           stuff I want the computer to do
        Else
           Stuff I want the computer to do if the first condition didn’t happen
        fi
 for
   for A=1
      do
           stuff I want the computer to do
         done

 While
   While A=1
     do
           stuff I want the computer to do
         done
 Until
   until A=1
      do
           stuff I want the computer to do
      done

 Case
   case A=1
      stuff I want the computer to do
   case A != 1
      stuff I want the computer to do
   easc

More Related Content

What's hot (20)

TXT
Logrotate sh
Ben Pope
 
PDF
Tomáš Čorej - OpenSSH
webelement
 
PPTX
Raspberry pi Part 4
Techvilla
 
PPT
Unix Programming with Perl 2
Kazuho Oku
 
PPT
Unix 5 en
Simonas Kareiva
 
DOC
How to send files to remote server via ssh in php
Andolasoft Inc
 
PDF
Ansible, Simplicity, and the Zen of Python
toddmowen
 
PDF
Gitosis on Mac OS X Server
Yasuhiro Asaka
 
PDF
ES6 generators
Steven Foote
 
PDF
Redis & ZeroMQ: How to scale your application
rjsmelo
 
PDF
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
SmartTools
 
PDF
Module 03 Programming on Linux
Tushar B Kute
 
PDF
Any event intro
qiang
 
PPT
Multithreading in PHP
dimitriyremerov
 
PPT
Shell and perl scripting classes in mumbai
Vibrant Technologies & Computers
 
PDF
Asynchronous PHP and Real-time Messaging
Steve Rhoades
 
PPTX
Perl: Coro asynchronous
Shmuel Fomberg
 
PDF
Shell实现的windows回收站功能的脚本
Lingfei Kong
 
ODP
Perl - laziness, impatience, hubris, and one liners
Kirk Kimmel
 
PDF
ZeroMQ Is The Answer
Ian Barber
 
Logrotate sh
Ben Pope
 
Tomáš Čorej - OpenSSH
webelement
 
Raspberry pi Part 4
Techvilla
 
Unix Programming with Perl 2
Kazuho Oku
 
Unix 5 en
Simonas Kareiva
 
How to send files to remote server via ssh in php
Andolasoft Inc
 
Ansible, Simplicity, and the Zen of Python
toddmowen
 
Gitosis on Mac OS X Server
Yasuhiro Asaka
 
ES6 generators
Steven Foote
 
Redis & ZeroMQ: How to scale your application
rjsmelo
 
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
SmartTools
 
Module 03 Programming on Linux
Tushar B Kute
 
Any event intro
qiang
 
Multithreading in PHP
dimitriyremerov
 
Shell and perl scripting classes in mumbai
Vibrant Technologies & Computers
 
Asynchronous PHP and Real-time Messaging
Steve Rhoades
 
Perl: Coro asynchronous
Shmuel Fomberg
 
Shell实现的windows回收站功能的脚本
Lingfei Kong
 
Perl - laziness, impatience, hubris, and one liners
Kirk Kimmel
 
ZeroMQ Is The Answer
Ian Barber
 

Similar to Cis 216 – shell scripting (20)

PPT
Unix
nazeer pasha
 
PDF
Unit 10 investigating and managing
root_fibo
 
PPT
Linux ppt
Sanmuga Nathan
 
PPTX
OS-Module 2 Linux Programming Important topics
JithinS34
 
PPTX
Linux System commands Essentialsand Basics.pptx
mba1130feb2024
 
PDF
Linux cheat sheet
Dimitris Kyrgiafinis
 
PPTX
Linux Basic commands and VI Editor
shanmuga rajan
 
PPT
Linux presentation
Nikhil Jain
 
PDF
Basic shell commands by Jeremy Sanders
Devanand Gehlot
 
DOCX
Linux basic commands
Teja Bheemanapally
 
PPT
workshop_1.ppt
hazhamina
 
PPTX
Learning Linux Series Administrator Commands.pptx
Shashwat Shriparv
 
DOC
58518522 study-aix
homeworkping3
 
PPT
Basic Linux day 1
Saikumar Daram
 
DOCX
50 Most Frequently Used UNIX Linux Commands -hmftj
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
PPTX
Unix training session 3
Anil Kumar Kapil,PMP®
 
PPT
Linux day 1
sumairdotcom
 
PPT
Examples -partII
Kedar Bhandari
 
PDF
Lecture1 2 intro-unix
nghoanganh
 
PDF
Linux Command Line - By Ranjan Raja
Ranjan Raja
 
Unit 10 investigating and managing
root_fibo
 
Linux ppt
Sanmuga Nathan
 
OS-Module 2 Linux Programming Important topics
JithinS34
 
Linux System commands Essentialsand Basics.pptx
mba1130feb2024
 
Linux cheat sheet
Dimitris Kyrgiafinis
 
Linux Basic commands and VI Editor
shanmuga rajan
 
Linux presentation
Nikhil Jain
 
Basic shell commands by Jeremy Sanders
Devanand Gehlot
 
Linux basic commands
Teja Bheemanapally
 
workshop_1.ppt
hazhamina
 
Learning Linux Series Administrator Commands.pptx
Shashwat Shriparv
 
58518522 study-aix
homeworkping3
 
Basic Linux day 1
Saikumar Daram
 
50 Most Frequently Used UNIX Linux Commands -hmftj
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Unix training session 3
Anil Kumar Kapil,PMP®
 
Linux day 1
sumairdotcom
 
Examples -partII
Kedar Bhandari
 
Lecture1 2 intro-unix
nghoanganh
 
Linux Command Line - By Ranjan Raja
Ranjan Raja
 
Ad

More from Dan Morrill (16)

PPTX
Windows power shell and active directory
Dan Morrill
 
PPTX
Understanding web site analytics
Dan Morrill
 
PPTX
Understanding UNIX CASE and TPUT
Dan Morrill
 
PPTX
Information security principles
Dan Morrill
 
PPTX
Using Regular Expressions in Grep
Dan Morrill
 
PPTX
Understanding the security_organization
Dan Morrill
 
PPTX
You should ask before copying that media
Dan Morrill
 
PPTX
Understanding advanced persistent threats (APT)
Dan Morrill
 
PPTX
AWS Hadoop and PIG and overview
Dan Morrill
 
PPTX
What is cloud computing
Dan Morrill
 
PPT
Social Media Plan for CityU of Seattle
Dan Morrill
 
PPT
BSIS Overview
Dan Morrill
 
PPT
Case Studies In Social Media Chinese
Dan Morrill
 
PPT
Case Studies In Social Media
Dan Morrill
 
PPT
Turn On Tune In Step Out
Dan Morrill
 
PPT
Technology And The Future Of Management
Dan Morrill
 
Windows power shell and active directory
Dan Morrill
 
Understanding web site analytics
Dan Morrill
 
Understanding UNIX CASE and TPUT
Dan Morrill
 
Information security principles
Dan Morrill
 
Using Regular Expressions in Grep
Dan Morrill
 
Understanding the security_organization
Dan Morrill
 
You should ask before copying that media
Dan Morrill
 
Understanding advanced persistent threats (APT)
Dan Morrill
 
AWS Hadoop and PIG and overview
Dan Morrill
 
What is cloud computing
Dan Morrill
 
Social Media Plan for CityU of Seattle
Dan Morrill
 
BSIS Overview
Dan Morrill
 
Case Studies In Social Media Chinese
Dan Morrill
 
Case Studies In Social Media
Dan Morrill
 
Turn On Tune In Step Out
Dan Morrill
 
Technology And The Future Of Management
Dan Morrill
 
Ad

Recently uploaded (20)

PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Horarios de distribución de agua en julio
pegazohn1978
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
infertility, types,causes, impact, and management
Ritu480198
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Controller Request and Response in Odoo18
Celine George
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Difference between write and update in odoo 18
Celine George
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 

Cis 216 – shell scripting

  • 1. Remembering the basics – Week 1 Dan Morrill April 01 2013
  • 2.  RMDIR – removes a directory only if it is empty  RMDIR –r – removes a directory regardless if it is empty or not  CHMOD 777 –r /user/dan – recursively changes the permissions of the directory /user/dan to RWXRWXRWX  grep – pattern matching for example ps –ef |grep apache2 will look for all processes running under the name apache2  egrep – used in regular expressions
  • 3.  find – find the location of a file (or files) on a hard drive at the command line  echo – writes data to the screen (standard output)  The TTY – Screen is always standard output (STDOUT)  more – displays the contents of a file one page at a time (hard for long files like syslog)  clear – clears the screen of text and provides the command prompt  chown – change the owner of a file or directory  rm – remove a file
  • 4.  mv – move a file to a new place and or new name  chgrp – change the group ownership of a file  mkdir – make a directory  ls – list the files in a directory, ls –la show the long form (including permissions and owners) of the files in a directory  cat – an alternative to showing the data in a file all at once  pwd – display the current directory  passwd – change the password of the currently logged in user
  • 5.  >> - append data to the END of a file  > - overwrites the file and any data in it  | - pipe character – strings commands together  || - logical OR – in that A || B in a loop, condition A or condition B  & - executes your process in the background – so you can still use the command line ./script.sh & will run your process in the background  && - Logical AND A && B if A succeeds, run B  sleep – stop execution of the script for a specified number of seconds sleep 20 means sleep for 20 seconds
  • 6.  diff – compares two files (this is great for seeing what changes were made in a script against the original and modified)  sdiff – only works with the 132 character display, but compares files side by side  lp – prints a file to the configured printer  lpstat – shows the user what is in the printer queue  ( ) – runs the enclosed command in a sub-shell  (( )) – evaluates and assigns a value to a variable and does math in a sub-shell
  • 7.  $(( )) – evaluates the enclosed expression  [ ] – test an expression to see if it is true or false  < > - used to compare values or strings  $( ) – command substitution – great when doing logical OR’s or AND’s
  • 8.  ++ - auto increment a value for I=1 ++ (takes I up by 1 for every loop)  -- - auto decrement a value for I=100 -- (takes I down by 1 for every loop)  <= - less than or equal to  >= - greater than or equal to
  • 9.  I will expect to see this in the header of every Unix Script you will turn in:  #!/bin/sh (tells the computer to use a bourne shell)  #  # Script: Name of script (what you named this file)  # Author: Your Name (so I know who wrote it)  #Date: (the date you wrote it)  #Revision: 1.1.A(how many times it changed, and what state it is in(A, B, D, T or P)  All scripts should also have A, B, D, T or P at the end of the revision statement so I know if it is Alpha, Beta, Dev, Test, or Production. All scripts turned in should be production scripts
  • 10.  How to get your script to do more useful stuff  If. Then  if [test]  Then  stuff I want the computer to do  fi  If. Then. Else  if [test]  Then  stuff I want the computer to do  Else  Stuff I want the computer to do if the first condition didn’t happen  fi
  • 11.  for  for A=1  do  stuff I want the computer to do  done  While  While A=1  do  stuff I want the computer to do  done
  • 12.  Until  until A=1  do  stuff I want the computer to do  done  Case  case A=1  stuff I want the computer to do  case A != 1  stuff I want the computer to do  easc