2
Most read
13
Most read
17
Most read
Improve Command line utility:
Shell Scripts
Shell
● CLI which allows user to interact with OS
● For example :-
○ In linux sh, bash etc. is a shell
● Use echo $0 to get your shell name
● Available shells are stored in /etc/shells
Improve Command Line Productivity - RHCSA (RH134).pdf
For knowing the current shell name
● Command: echo $0
To know the specific version of the shell being used
● Command: echo $BASH_VERSION
List all the available shells on the system
● Command: cat /etc/shells
Verify which shell is assigned to a user
● Command: cat /etc/passwd
Shell Scripts
Executable file comprising a series of shell commands executed in sequence.
Within the file, you can include:
● Shell declaration (#!/bin/bash)
● Commentary lines (# comments)
● Various commands (echo, cp, grep, etc.)
● Control statements (if, while, for, etc.)
● Ensure executable permissions (e.g., -rwx r-x r-x)
● Call script using absolute path (e.g.,-/home/userdir/script.bash)
● Calling from the current directory, use ./script.bash
Example
If-Then & loop scripts
● If-Then: Conditional execution of code.
● Syntax:
`if [ condition ]; then action; fi`
● loop: Repeated execution of code.
● Syntax for 'for' loop:
`for i in {start..end}; do action; done`
Create a shell file and open the nano editor
● Command: nano <file_name> .sh
Execution of if-then
Make the script executable
● Command: chmod +x <file_name>
Run the script
● Command: ./<file_name>
Note: Since we did not create any such file with the name example.txt
so it’s giving the output as File example.txt does not exist
For loop execution
Create a shell file and open it in nano editor
● Command: nano <file_name> .sh
Make the script executable
● Command: chmod +x <file_name>
Run the script
● Command: ./<file_name>
While loop execution
Create a shell file and open it in nano editor
● Command: nano <file_name> .sh
Make the script executable
● Command: chmod +x <file_name>
Run the script
● Command: ./<file_name>
grep
● Command-line utility used for searching text patterns within
files
● Syntax:
● [options]: Optional flags that modify the behavior of grep.
● pattern: The text pattern to search for.
● [file...]: files to search within
● To search for more than one keyword use :
egrep –i “keyword|keyword2” file
grep options
● -i: Ignore case distinctions.
● -n: Display line numbers along with matching lines.
● -l: Display only the names of files containing matches.
● -c: Display count of matching lines
● -o: Show only the matching part of the lines
● -v: Display lines that do not match the pattern
● -w: Match whole words
● -r or -R: Recursively search directories for matching files
egrep
● Stands for "Global Regular Expressions Print"
● more suitable for complex pattern matching because it
allows metacharacters like +, ?, and | without needing to
escape them
● can search for multiple patterns in a single command

More Related Content

PDF
Shell scripting
PPTX
PRACTICAL -UNIX, shell programs, shell commands
PPTX
PRACTICAL -UNIX, shell commands in unix, practice commands on shell
PPTX
PRACTICAL -UNIX, main unix commands in practice
PPT
Unix Shell Scripting Basics
PPT
Unix shell scripting basics
PDF
Shell scripting
PRACTICAL -UNIX, shell programs, shell commands
PRACTICAL -UNIX, shell commands in unix, practice commands on shell
PRACTICAL -UNIX, main unix commands in practice
Unix Shell Scripting Basics
Unix shell scripting basics

Similar to Improve Command Line Productivity - RHCSA (RH134).pdf (20)

PDF
Lets make better scripts
PDF
Scripting and the shell in LINUX
PDF
Shell tutorial
PPTX
Unix shell scripting basics
PPTX
KT on Bash Script.pptx
PPT
Unix And Shell Scripting
PPTX
Linux Shell Scripts and Shell Commands✌️
PDF
Bash Scripting Workshop
PPT
Unix Shell Scripting Basics
PPTX
First steps in C-Shell
PDF
Shell scripting _how_to_automate_command_l_-_jason_cannon
PPT
Unix day2 v1.3
PDF
Unix Shell Scripting
DOCX
What is a shell script
PPTX
Unix - Shell Scripts
PDF
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
PDF
Unleash your inner console cowboy
PPT
ShellAdvanced shell scripting programm.ppt
PPT
PPTX
Shell & Shell Script
Lets make better scripts
Scripting and the shell in LINUX
Shell tutorial
Unix shell scripting basics
KT on Bash Script.pptx
Unix And Shell Scripting
Linux Shell Scripts and Shell Commands✌️
Bash Scripting Workshop
Unix Shell Scripting Basics
First steps in C-Shell
Shell scripting _how_to_automate_command_l_-_jason_cannon
Unix day2 v1.3
Unix Shell Scripting
What is a shell script
Unix - Shell Scripts
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Unleash your inner console cowboy
ShellAdvanced shell scripting programm.ppt
Shell & Shell Script
Ad

More from RHCSA Guru (20)

PDF
Flatpak CLI Application Management & Building on RHEL.pdf
PDF
How to Set Up a RHEL 9 Virtual Lab for RHCSA Practice.pdf
PDF
CompTIA Linux (Plus) Exam Overview .pdf
PDF
Linux Professional Institute LPIC-1 Exam.pdf
PDF
LVM Management & Disaster Recovery - RHCSA+.pdf
PDF
Managing Multiple Logical Volumes - RHCSA+.pdf
PDF
Master Logical Volume Management - RHCSA+.pdf
PDF
Ansible Vault Encrypting and Protecting Secrets - RHCE.pdf
PDF
Ansible Variables in Playbook - RHCE.pdf
PDF
Comprehensive Guide to Ansible Application Roles.pdf
PDF
Using Tags in Ansible Playbooks RHCE.pdf
PDF
Comprehensive Guide to Ansible Roles - RHCE
PDF
Mastering Handlers, Conditions, and Loops in Ansible Playbooks - RHCE.pdf
PDF
Essential Ad-hoc Commands in Ansible - RHCE.pdf
PDF
RHEL in Shell Scripting Advanced - RHCSA+.pdf
PDF
Shell Scripting Intermediate - RHCSA+.pdf
PDF
Introduction to Shell Scripting - RHCSA+.pdf
PDF
Command Line Text Processing - RHCSA +.pdf
PDF
Mounting and Creating Links - RHCSA (RH124) .pdf
PDF
Basic Command Line Tools - RHCSA (RH124).pdf
Flatpak CLI Application Management & Building on RHEL.pdf
How to Set Up a RHEL 9 Virtual Lab for RHCSA Practice.pdf
CompTIA Linux (Plus) Exam Overview .pdf
Linux Professional Institute LPIC-1 Exam.pdf
LVM Management & Disaster Recovery - RHCSA+.pdf
Managing Multiple Logical Volumes - RHCSA+.pdf
Master Logical Volume Management - RHCSA+.pdf
Ansible Vault Encrypting and Protecting Secrets - RHCE.pdf
Ansible Variables in Playbook - RHCE.pdf
Comprehensive Guide to Ansible Application Roles.pdf
Using Tags in Ansible Playbooks RHCE.pdf
Comprehensive Guide to Ansible Roles - RHCE
Mastering Handlers, Conditions, and Loops in Ansible Playbooks - RHCE.pdf
Essential Ad-hoc Commands in Ansible - RHCE.pdf
RHEL in Shell Scripting Advanced - RHCSA+.pdf
Shell Scripting Intermediate - RHCSA+.pdf
Introduction to Shell Scripting - RHCSA+.pdf
Command Line Text Processing - RHCSA +.pdf
Mounting and Creating Links - RHCSA (RH124) .pdf
Basic Command Line Tools - RHCSA (RH124).pdf
Ad

Recently uploaded (20)

PDF
Unlock new opportunities with location data.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
STKI Israel Market Study 2025 version august
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Chapter 5: Probability Theory and Statistics
PDF
1 - Historical Antecedents, Social Consideration.pdf
DOCX
search engine optimization ppt fir known well about this
PDF
CloudStack 4.21: First Look Webinar slides
PPT
What is a Computer? Input Devices /output devices
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
The various Industrial Revolutions .pptx
PDF
Hybrid model detection and classification of lung cancer
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
August Patch Tuesday
PPTX
O2C Customer Invoices to Receipt V15A.pptx
Unlock new opportunities with location data.pdf
Getting Started with Data Integration: FME Form 101
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
observCloud-Native Containerability and monitoring.pptx
STKI Israel Market Study 2025 version august
Assigned Numbers - 2025 - Bluetooth® Document
Chapter 5: Probability Theory and Statistics
1 - Historical Antecedents, Social Consideration.pdf
search engine optimization ppt fir known well about this
CloudStack 4.21: First Look Webinar slides
What is a Computer? Input Devices /output devices
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Taming the Chaos: How to Turn Unstructured Data into Decisions
WOOl fibre morphology and structure.pdf for textiles
The various Industrial Revolutions .pptx
Hybrid model detection and classification of lung cancer
Developing a website for English-speaking practice to English as a foreign la...
August Patch Tuesday
O2C Customer Invoices to Receipt V15A.pptx

Improve Command Line Productivity - RHCSA (RH134).pdf

  • 1. Improve Command line utility: Shell Scripts
  • 2. Shell ● CLI which allows user to interact with OS ● For example :- ○ In linux sh, bash etc. is a shell ● Use echo $0 to get your shell name ● Available shells are stored in /etc/shells
  • 4. For knowing the current shell name ● Command: echo $0 To know the specific version of the shell being used ● Command: echo $BASH_VERSION
  • 5. List all the available shells on the system ● Command: cat /etc/shells
  • 6. Verify which shell is assigned to a user ● Command: cat /etc/passwd
  • 7. Shell Scripts Executable file comprising a series of shell commands executed in sequence. Within the file, you can include: ● Shell declaration (#!/bin/bash) ● Commentary lines (# comments) ● Various commands (echo, cp, grep, etc.) ● Control statements (if, while, for, etc.) ● Ensure executable permissions (e.g., -rwx r-x r-x) ● Call script using absolute path (e.g.,-/home/userdir/script.bash) ● Calling from the current directory, use ./script.bash
  • 9. If-Then & loop scripts ● If-Then: Conditional execution of code. ● Syntax: `if [ condition ]; then action; fi` ● loop: Repeated execution of code. ● Syntax for 'for' loop: `for i in {start..end}; do action; done`
  • 10. Create a shell file and open the nano editor ● Command: nano <file_name> .sh Execution of if-then
  • 11. Make the script executable ● Command: chmod +x <file_name> Run the script ● Command: ./<file_name> Note: Since we did not create any such file with the name example.txt so it’s giving the output as File example.txt does not exist
  • 12. For loop execution Create a shell file and open it in nano editor ● Command: nano <file_name> .sh
  • 13. Make the script executable ● Command: chmod +x <file_name> Run the script ● Command: ./<file_name>
  • 14. While loop execution Create a shell file and open it in nano editor ● Command: nano <file_name> .sh
  • 15. Make the script executable ● Command: chmod +x <file_name> Run the script ● Command: ./<file_name>
  • 16. grep ● Command-line utility used for searching text patterns within files ● Syntax: ● [options]: Optional flags that modify the behavior of grep. ● pattern: The text pattern to search for. ● [file...]: files to search within ● To search for more than one keyword use : egrep –i “keyword|keyword2” file
  • 17. grep options ● -i: Ignore case distinctions. ● -n: Display line numbers along with matching lines. ● -l: Display only the names of files containing matches. ● -c: Display count of matching lines ● -o: Show only the matching part of the lines ● -v: Display lines that do not match the pattern ● -w: Match whole words ● -r or -R: Recursively search directories for matching files
  • 18. egrep ● Stands for "Global Regular Expressions Print" ● more suitable for complex pattern matching because it allows metacharacters like +, ?, and | without needing to escape them ● can search for multiple patterns in a single command