SlideShare a Scribd company logo
Lesson 6-Using Utilities to Accomplish Complex Tasks
Overview  Creating and executing a script to list user information. Listing directories and files separately. Identifying changes made to files in a directory. Creating a complex script.
Creating and Executing a Script to List User Information Creating a script. Executing a script.
Creating a Script  A series of commands can be executed repeatedly/automatically by placing them in a script file. Placing commands in scripts helps avoid errors and save time. The vi editor can be used to create a file. The ":wq" commands are used to write to a file and return to the shell.
Executing a Script  The commands in a file can be executed in two ways: Instructions can be given to the current shell to read the file (source) and execute all the commands. The script file can be made executable, and a child shell can be started to read the script file and execute the commands.
Executing a Script  The command used to make the shell executable is “chmod +x filename”. By default, the output of the script is redirected to the screen. The output of the script can be redirected to a file.
Listing Directories and Files  Separately  Selecting only directories / files: The “ls –F | grep /” command is used to select only lines that contain directory names. The “ls –F | grep / | column” command can be used to put the output into columns. The “ls –F | grep –v / | column” command is used to select only files.
Listing Directories and Files  Separately  Selecting Directories Using Multiple Utilities
Listing Directories and Files  Separately  Interpretation by grep Using –v option
Listing Directories and Files  Separately  Adding comments to scripts: The # (pound) sign is used to add comments to scripts. Ensure that the # sign is placed at the beginning of each line. The pound (#) sign cannot be used inside a long command line.
Identifying Changes Made to Files in a Directory  Collecting data about files in a directory: The “ls –l directory name” command can be used to provide information about the files in a particular directory. The output of the code can also be redirected to another file by the command "ls -l directoryname > filename”.  The information includes the current status of each file, such as permissions, date of modification, owner, etc.
Identifying Changes Made to Files in a Directory  Comparing file information: The “comm” command is used to identify the common aspects between two files. It requires two arguments – the names of the two the files that are to be compared. The command gives three columns of output – lines unique in the first file, lines unique in the second file, and lines in common.
Identifying Changes Made to Files in a Directory  Comparing file information: The “diff” command is used to identify the differences between two files. It requires two arguments – the names of the two files to be compared. The command gives three columns of output – lines unique in the first file, lines unique in the second file, and lines common to the two files.
Creating a Complex Script  Determining the number of unique words in a file. Removing punctuation. Converting characters to lowercase. Putting each word on a line. Removing blank lines. Sorting the lines.
Determining the Number of Unique Words in a File  The “uniq” utility is used to: Provide a list of unique words in a file. The number of times that each word is used. The number of unique words.
Determining the Number of Unique Words in a File  The uniq utility outputs both, unique lines as well as single copies of any lines that are duplicate and adjacent. The utility deletes identical lines. The uniq utility deletes only those lines that are identical and adjacent.
Determining the Number of Unique Words in a File  The following things must be ensured for the uniq utility to work properly: Punctuation and blank lines must be removed. Differences in case for the same word must be reconciled. The words must be one word to a line in a sorted order.
Removing Punctuation  Shell and Utility Interpretation
Converting Characters to Lowercase  Shell and tr Interpretation
Putting Each Word on a Line  To remove duplicate words using the uniq utility, the data must be modified to ensure that each word is on a line by itself. The new line character “\n” is used to separate lines in a file. The ASCII character code 012 can also be used to separate lines in a file.
Putting Each Word on a Line  The “man ascii” command is used to examine the ASCII characters and their associated codes. TAB characters can also be replaced with new line characters.
Putting Each Word on a Line  Using tr Utility to Replace Characters
Removing Blank Lines  A View from the Shell
Sorting the Lines  The “sort” command can be used to sort the output such that all lines containing the same word are on adjacent lines. The “uniq –c” command can be used to remove all duplicate lines. The “sort –rn” command can be used to list the most frequently used words first.
Summary  A series of commands placed in a script file can be repeatedly executed, avoiding errors and saving time. The ls utility provides a list of all the files and subdirectories in the current directory. The # sign is used to add comments to script files. The pipeline feature of UNIX is very useful and is central to manipulating data effectively with UNIX utilities.
Ad

Recommended

intro unix/linux 08
intro unix/linux 08
duquoi
 
intro unix/linux 05
intro unix/linux 05
duquoi
 
intro unix/linux 11
intro unix/linux 11
duquoi
 
intro unix/linux 02
intro unix/linux 02
duquoi
 
intro unix/linux 04
intro unix/linux 04
duquoi
 
intro unix/linux 07
intro unix/linux 07
duquoi
 
intro unix/linux 03
intro unix/linux 03
duquoi
 
intro unix/linux 10
intro unix/linux 10
duquoi
 
intro unix/linux 09
intro unix/linux 09
duquoi
 
Spsl unit1
Spsl unit1
Sasidhar Kothuru
 
Spsl by sasidhar 3 unit
Spsl by sasidhar 3 unit
Sasidhar Kothuru
 
Karkha unix shell scritping
Karkha unix shell scritping
chockit88
 
File handling in c++
File handling in c++
ProfSonaliGholveDoif
 
Windows command prompt a to z
Windows command prompt a to z
Subuh Kurniawan
 
File Pointers
File Pointers
Kulachi Hansraj Model School Ashok Vihar
 
file handling c++
file handling c++
Guddu Spy
 
Tool Development 08 - Windows Command Prompt
Tool Development 08 - Windows Command Prompt
Nick Pruehs
 
Files in c++
Files in c++
Selvin Josy Bai Somu
 
File Handling in C++
File Handling in C++
Kulachi Hansraj Model School Ashok Vihar
 
Filehadnling
Filehadnling
Khushal Mehta
 
08. handling file streams
08. handling file streams
Haresh Jaiswal
 
Files in c++
Files in c++
NivethaJeyaraman
 
File handling in C++
File handling in C++
Hitesh Kumar
 
File handling in_c
File handling in_c
sanya6900
 
File Handling In C++
File Handling In C++
Kulachi Hansraj Model School Ashok Vihar
 
Filehandlinging cp2
Filehandlinging cp2
Tanmay Baranwal
 
Shell scripting
Shell scripting
DeepakKumar4980
 
File in cpp 2016
File in cpp 2016
Dr .Ahmed Tawwab
 
Intro to linux performance analysis
Intro to linux performance analysis
Chris McEniry
 
Intro To Linux
Intro To Linux
techlug
 

More Related Content

What's hot (20)

intro unix/linux 09
intro unix/linux 09
duquoi
 
Spsl unit1
Spsl unit1
Sasidhar Kothuru
 
Spsl by sasidhar 3 unit
Spsl by sasidhar 3 unit
Sasidhar Kothuru
 
Karkha unix shell scritping
Karkha unix shell scritping
chockit88
 
File handling in c++
File handling in c++
ProfSonaliGholveDoif
 
Windows command prompt a to z
Windows command prompt a to z
Subuh Kurniawan
 
File Pointers
File Pointers
Kulachi Hansraj Model School Ashok Vihar
 
file handling c++
file handling c++
Guddu Spy
 
Tool Development 08 - Windows Command Prompt
Tool Development 08 - Windows Command Prompt
Nick Pruehs
 
Files in c++
Files in c++
Selvin Josy Bai Somu
 
File Handling in C++
File Handling in C++
Kulachi Hansraj Model School Ashok Vihar
 
Filehadnling
Filehadnling
Khushal Mehta
 
08. handling file streams
08. handling file streams
Haresh Jaiswal
 
Files in c++
Files in c++
NivethaJeyaraman
 
File handling in C++
File handling in C++
Hitesh Kumar
 
File handling in_c
File handling in_c
sanya6900
 
File Handling In C++
File Handling In C++
Kulachi Hansraj Model School Ashok Vihar
 
Filehandlinging cp2
Filehandlinging cp2
Tanmay Baranwal
 
Shell scripting
Shell scripting
DeepakKumar4980
 
File in cpp 2016
File in cpp 2016
Dr .Ahmed Tawwab
 

Viewers also liked (14)

Intro to linux performance analysis
Intro to linux performance analysis
Chris McEniry
 
Intro To Linux
Intro To Linux
techlug
 
Intro To Linux Admin
Intro To Linux Admin
Nathan Peek
 
Intro to Linux (for Ham Radio Operators)
Intro to Linux (for Ham Radio Operators)
Tanner Lovelace
 
History Of Linux
History Of Linux
anand09
 
Intro to Linux Shell Scripting
Intro to Linux Shell Scripting
vceder
 
Operating Systems: A History of Linux
Operating Systems: A History of Linux
Damian T. Gordon
 
Linux intro 2 basic terminal
Linux intro 2 basic terminal
Giovanni Marco Dall'Olio
 
Linux intro 1 definitions
Linux intro 1 definitions
Giovanni Marco Dall'Olio
 
Basic command ppt
Basic command ppt
Rohit Kumar
 
Linux introduction
Linux introduction
Md. Zahid Hossain Shoeb
 
Introduction to linux ppt
Introduction to linux ppt
Omi Vichare
 
Linux ppt
Linux ppt
lincy21
 
Linux.ppt
Linux.ppt
onu9
 
Intro to linux performance analysis
Intro to linux performance analysis
Chris McEniry
 
Intro To Linux
Intro To Linux
techlug
 
Intro To Linux Admin
Intro To Linux Admin
Nathan Peek
 
Intro to Linux (for Ham Radio Operators)
Intro to Linux (for Ham Radio Operators)
Tanner Lovelace
 
History Of Linux
History Of Linux
anand09
 
Intro to Linux Shell Scripting
Intro to Linux Shell Scripting
vceder
 
Operating Systems: A History of Linux
Operating Systems: A History of Linux
Damian T. Gordon
 
Basic command ppt
Basic command ppt
Rohit Kumar
 
Introduction to linux ppt
Introduction to linux ppt
Omi Vichare
 
Linux ppt
Linux ppt
lincy21
 
Linux.ppt
Linux.ppt
onu9
 
Ad

Similar to intro unix/linux 06 (20)

Unix training session 2
Unix training session 2
Anil Kumar Kapil,PMP®
 
Handling Files Under Unix.pptx
Handling Files Under Unix.pptx
Harsha Patil
 
Handling Files Under Unix.pptx
Handling Files Under Unix.pptx
Harsha Patil
 
Unix lab manual
Unix lab manual
Chaitanya Kn
 
Directories description
Directories description
Dr.M.Karthika parthasarathy
 
Unix environment [autosaved]
Unix environment [autosaved]
Er Mittinpreet Singh
 
File systems and inodes
File systems and inodes
Dr. Girish GS
 
UNIX Command Cheat Sheets
UNIX Command Cheat Sheets
Prashanth Kumar
 
08 text processing_tools
08 text processing_tools
Shay Cohen
 
Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling
Ahmed El-Arabawy
 
Unit 8 text processing tools
Unit 8 text processing tools
root_fibo
 
Basics of UNIX Commands
Basics of UNIX Commands
Subra Das
 
terminal command2.pptx with good explanation
terminal command2.pptx with good explanation
farsankadavandy
 
Unix Basics For Testers
Unix Basics For Testers
nitin lakhanpal
 
Os lab manual
Os lab manual
Neelamani Samal
 
Using Unix
Using Unix
Dr.Ravi
 
Unix ppt
Unix ppt
Dr Rajiv Srivastava
 
Unix command
Unix command
Atul Pant
 
Unix(introduction)
Unix(introduction)
meashi
 
Linuxnishustud
Linuxnishustud
Vicky Singh
 
Handling Files Under Unix.pptx
Handling Files Under Unix.pptx
Harsha Patil
 
Handling Files Under Unix.pptx
Handling Files Under Unix.pptx
Harsha Patil
 
File systems and inodes
File systems and inodes
Dr. Girish GS
 
UNIX Command Cheat Sheets
UNIX Command Cheat Sheets
Prashanth Kumar
 
08 text processing_tools
08 text processing_tools
Shay Cohen
 
Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling
Ahmed El-Arabawy
 
Unit 8 text processing tools
Unit 8 text processing tools
root_fibo
 
Basics of UNIX Commands
Basics of UNIX Commands
Subra Das
 
terminal command2.pptx with good explanation
terminal command2.pptx with good explanation
farsankadavandy
 
Using Unix
Using Unix
Dr.Ravi
 
Unix command
Unix command
Atul Pant
 
Unix(introduction)
Unix(introduction)
meashi
 
Ad

More from duquoi (9)

Troubleshooting CD Burning
Troubleshooting CD Burning
duquoi
 
Advanced Bash Scripting Guide 2002
Advanced Bash Scripting Guide 2002
duquoi
 
Astrolog: Switches
Astrolog: Switches
duquoi
 
Cinelerra Video Editing Manual
Cinelerra Video Editing Manual
duquoi
 
Iptables
Iptables
duquoi
 
Ffmpeg
Ffmpeg
duquoi
 
rosegarden
rosegarden
duquoi
 
intro unix/linux 12
intro unix/linux 12
duquoi
 
intro unix/linux 01
intro unix/linux 01
duquoi
 
Troubleshooting CD Burning
Troubleshooting CD Burning
duquoi
 
Advanced Bash Scripting Guide 2002
Advanced Bash Scripting Guide 2002
duquoi
 
Astrolog: Switches
Astrolog: Switches
duquoi
 
Cinelerra Video Editing Manual
Cinelerra Video Editing Manual
duquoi
 
Iptables
Iptables
duquoi
 
Ffmpeg
Ffmpeg
duquoi
 
rosegarden
rosegarden
duquoi
 
intro unix/linux 12
intro unix/linux 12
duquoi
 
intro unix/linux 01
intro unix/linux 01
duquoi
 

Recently uploaded (20)

Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 

intro unix/linux 06

  • 1. Lesson 6-Using Utilities to Accomplish Complex Tasks
  • 2. Overview Creating and executing a script to list user information. Listing directories and files separately. Identifying changes made to files in a directory. Creating a complex script.
  • 3. Creating and Executing a Script to List User Information Creating a script. Executing a script.
  • 4. Creating a Script A series of commands can be executed repeatedly/automatically by placing them in a script file. Placing commands in scripts helps avoid errors and save time. The vi editor can be used to create a file. The ":wq" commands are used to write to a file and return to the shell.
  • 5. Executing a Script The commands in a file can be executed in two ways: Instructions can be given to the current shell to read the file (source) and execute all the commands. The script file can be made executable, and a child shell can be started to read the script file and execute the commands.
  • 6. Executing a Script The command used to make the shell executable is “chmod +x filename”. By default, the output of the script is redirected to the screen. The output of the script can be redirected to a file.
  • 7. Listing Directories and Files Separately Selecting only directories / files: The “ls –F | grep /” command is used to select only lines that contain directory names. The “ls –F | grep / | column” command can be used to put the output into columns. The “ls –F | grep –v / | column” command is used to select only files.
  • 8. Listing Directories and Files Separately Selecting Directories Using Multiple Utilities
  • 9. Listing Directories and Files Separately Interpretation by grep Using –v option
  • 10. Listing Directories and Files Separately Adding comments to scripts: The # (pound) sign is used to add comments to scripts. Ensure that the # sign is placed at the beginning of each line. The pound (#) sign cannot be used inside a long command line.
  • 11. Identifying Changes Made to Files in a Directory Collecting data about files in a directory: The “ls –l directory name” command can be used to provide information about the files in a particular directory. The output of the code can also be redirected to another file by the command "ls -l directoryname > filename”. The information includes the current status of each file, such as permissions, date of modification, owner, etc.
  • 12. Identifying Changes Made to Files in a Directory Comparing file information: The “comm” command is used to identify the common aspects between two files. It requires two arguments – the names of the two the files that are to be compared. The command gives three columns of output – lines unique in the first file, lines unique in the second file, and lines in common.
  • 13. Identifying Changes Made to Files in a Directory Comparing file information: The “diff” command is used to identify the differences between two files. It requires two arguments – the names of the two files to be compared. The command gives three columns of output – lines unique in the first file, lines unique in the second file, and lines common to the two files.
  • 14. Creating a Complex Script Determining the number of unique words in a file. Removing punctuation. Converting characters to lowercase. Putting each word on a line. Removing blank lines. Sorting the lines.
  • 15. Determining the Number of Unique Words in a File The “uniq” utility is used to: Provide a list of unique words in a file. The number of times that each word is used. The number of unique words.
  • 16. Determining the Number of Unique Words in a File The uniq utility outputs both, unique lines as well as single copies of any lines that are duplicate and adjacent. The utility deletes identical lines. The uniq utility deletes only those lines that are identical and adjacent.
  • 17. Determining the Number of Unique Words in a File The following things must be ensured for the uniq utility to work properly: Punctuation and blank lines must be removed. Differences in case for the same word must be reconciled. The words must be one word to a line in a sorted order.
  • 18. Removing Punctuation Shell and Utility Interpretation
  • 19. Converting Characters to Lowercase Shell and tr Interpretation
  • 20. Putting Each Word on a Line To remove duplicate words using the uniq utility, the data must be modified to ensure that each word is on a line by itself. The new line character “\n” is used to separate lines in a file. The ASCII character code 012 can also be used to separate lines in a file.
  • 21. Putting Each Word on a Line The “man ascii” command is used to examine the ASCII characters and their associated codes. TAB characters can also be replaced with new line characters.
  • 22. Putting Each Word on a Line Using tr Utility to Replace Characters
  • 23. Removing Blank Lines A View from the Shell
  • 24. Sorting the Lines The “sort” command can be used to sort the output such that all lines containing the same word are on adjacent lines. The “uniq –c” command can be used to remove all duplicate lines. The “sort –rn” command can be used to list the most frequently used words first.
  • 25. Summary A series of commands placed in a script file can be repeatedly executed, avoiding errors and saving time. The ls utility provides a list of all the files and subdirectories in the current directory. The # sign is used to add comments to script files. The pipeline feature of UNIX is very useful and is central to manipulating data effectively with UNIX utilities.