SlideShare una empresa de Scribd logo
1 de 12
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

Más contenido relacionado

La actualidad más candente

Logrotate sh
Logrotate shLogrotate sh
Logrotate sh
Ben Pope
 
Tomáš Čorej - OpenSSH
Tomáš Čorej - OpenSSHTomáš Čorej - OpenSSH
Tomáš Čorej - OpenSSH
webelement
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X Server
Yasuhiro Asaka
 

La actualidad más candente (20)

Logrotate sh
Logrotate shLogrotate sh
Logrotate sh
 
Tomáš Čorej - OpenSSH
Tomáš Čorej - OpenSSHTomáš Čorej - OpenSSH
Tomáš Čorej - OpenSSH
 
Raspberry pi Part 4
Raspberry pi Part 4Raspberry pi Part 4
Raspberry pi Part 4
 
Unix Programming with Perl 2
Unix Programming with Perl 2Unix Programming with Perl 2
Unix Programming with Perl 2
 
Unix 5 en
Unix 5 enUnix 5 en
Unix 5 en
 
How to send files to remote server via ssh in php
How to send files to remote server via ssh in phpHow to send files to remote server via ssh in php
How to send files to remote server via ssh in php
 
Ansible, Simplicity, and the Zen of Python
Ansible, Simplicity, and the Zen of PythonAnsible, Simplicity, and the Zen of Python
Ansible, Simplicity, and the Zen of Python
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X Server
 
ES6 generators
ES6 generatorsES6 generators
ES6 generators
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
 
Any event intro
Any event introAny event intro
Any event intro
 
Multithreading in PHP
Multithreading in PHPMultithreading in PHP
Multithreading in PHP
 
Shell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbaiShell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbai
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 

Similar a Cis 216 – shell scripting

Unit 10 investigating and managing
Unit 10 investigating and managingUnit 10 investigating and managing
Unit 10 investigating and managing
root_fibo
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
Nikhil Jain
 
Lecture1 2 intro-unix
Lecture1 2 intro-unixLecture1 2 intro-unix
Lecture1 2 intro-unix
nghoanganh
 

Similar a Cis 216 – shell scripting (20)

Unix
UnixUnix
Unix
 
Unit 10 investigating and managing
Unit 10 investigating and managingUnit 10 investigating and managing
Unit 10 investigating and managing
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
Linux cheat sheet
Linux cheat sheetLinux cheat sheet
Linux cheat sheet
 
Linux Basic commands and VI Editor
Linux Basic commands and VI EditorLinux Basic commands and VI Editor
Linux Basic commands and VI Editor
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
 
Basic shell commands by Jeremy Sanders
Basic shell commands by Jeremy SandersBasic shell commands by Jeremy Sanders
Basic shell commands by Jeremy Sanders
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
workshop_1.ppt
workshop_1.pptworkshop_1.ppt
workshop_1.ppt
 
Learning Linux Series Administrator Commands.pptx
Learning Linux Series Administrator Commands.pptxLearning Linux Series Administrator Commands.pptx
Learning Linux Series Administrator Commands.pptx
 
58518522 study-aix
58518522 study-aix58518522 study-aix
58518522 study-aix
 
Basic Linux day 1
Basic Linux day 1Basic Linux day 1
Basic Linux day 1
 
50 Most Frequently Used UNIX Linux Commands -hmftj
50 Most Frequently Used UNIX  Linux Commands -hmftj50 Most Frequently Used UNIX  Linux Commands -hmftj
50 Most Frequently Used UNIX Linux Commands -hmftj
 
Unix training session 3
Unix training   session 3Unix training   session 3
Unix training session 3
 
Linux day 1
Linux day 1Linux day 1
Linux day 1
 
Examples -partII
Examples -partIIExamples -partII
Examples -partII
 
Lecture1 2 intro-unix
Lecture1 2 intro-unixLecture1 2 intro-unix
Lecture1 2 intro-unix
 
Linux Command Line - By Ranjan Raja
Linux Command Line - By Ranjan Raja Linux Command Line - By Ranjan Raja
Linux Command Line - By Ranjan Raja
 
Unix2
Unix2Unix2
Unix2
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 

Más de Dan Morrill

Más de Dan Morrill (16)

Windows power shell and active directory
Windows power shell and active directoryWindows power shell and active directory
Windows power shell and active directory
 
Understanding web site analytics
Understanding web site analyticsUnderstanding web site analytics
Understanding web site analytics
 
Understanding UNIX CASE and TPUT
Understanding UNIX CASE and TPUTUnderstanding UNIX CASE and TPUT
Understanding UNIX CASE and TPUT
 
Information security principles
Information security principlesInformation security principles
Information security principles
 
Using Regular Expressions in Grep
Using Regular Expressions in GrepUsing Regular Expressions in Grep
Using Regular Expressions in Grep
 
Understanding the security_organization
Understanding the security_organizationUnderstanding the security_organization
Understanding the security_organization
 
You should ask before copying that media
You should ask before copying that mediaYou should ask before copying that media
You should ask before copying that media
 
Understanding advanced persistent threats (APT)
Understanding advanced persistent threats (APT)Understanding advanced persistent threats (APT)
Understanding advanced persistent threats (APT)
 
AWS Hadoop and PIG and overview
AWS Hadoop and PIG and overviewAWS Hadoop and PIG and overview
AWS Hadoop and PIG and overview
 
What is cloud computing
What is cloud computingWhat is cloud computing
What is cloud computing
 
Social Media Plan for CityU of Seattle
Social Media Plan for CityU of SeattleSocial Media Plan for CityU of Seattle
Social Media Plan for CityU of Seattle
 
BSIS Overview
BSIS OverviewBSIS Overview
BSIS Overview
 
Case Studies In Social Media Chinese
Case Studies In Social Media ChineseCase Studies In Social Media Chinese
Case Studies In Social Media Chinese
 
Case Studies In Social Media
Case Studies In Social MediaCase Studies In Social Media
Case Studies In Social Media
 
Turn On Tune In Step Out
Turn On Tune In Step OutTurn On Tune In Step Out
Turn On Tune In Step Out
 
Technology And The Future Of Management
Technology And The Future Of ManagementTechnology And The Future Of Management
Technology And The Future Of Management
 

Último

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

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