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.

More Related Content

What's hot (20)

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

Viewers also liked (14)

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

Similar to intro unix/linux 06 (20)

PDF
2023comp90024_linux.pdf
LevLafayette1
 
PPT
Using Unix
Dr.Ravi
 
PPTX
Shell Scripting and Programming.pptx
Harsha Patil
 
PPTX
Shell Scripting and Programming.pptx
Harsha Patil
 
PDF
Shell-Scripting-1.pdf
aznabi
 
PDF
Shell scripting1232232312312312312312312
adnansalam11
 
PPT
Unix And Shell Scripting
Jaibeer Malik
 
ODP
Nithi
sharmibalu
 
DOCX
Unix operating system
midhunjose4u
 
PPTX
SHELL PROGRAMMING
jinal thakrar
 
PPTX
Linux System commands Essentialsand Basics.pptx
mba1130feb2024
 
PDF
Linux file commands and shell scripts
PrashantTechment
 
DOCX
The Korn Shell is the UNIX shell (command execution program, often c.docx
SUBHI7
 
ODP
Linuxppt
poornima sugumaran
 
ODP
Linuxppt
Reka
 
ODP
Linuxs1
rajikaa
 
ODP
Linuxppt
poornima sugumaran
 
PPT
Linux
nazeer pasha
 
PPT
commands and_ in _shell presentation.ppt
Serah48
 
2023comp90024_linux.pdf
LevLafayette1
 
Using Unix
Dr.Ravi
 
Shell Scripting and Programming.pptx
Harsha Patil
 
Shell Scripting and Programming.pptx
Harsha Patil
 
Shell-Scripting-1.pdf
aznabi
 
Shell scripting1232232312312312312312312
adnansalam11
 
Unix And Shell Scripting
Jaibeer Malik
 
Nithi
sharmibalu
 
Unix operating system
midhunjose4u
 
SHELL PROGRAMMING
jinal thakrar
 
Linux System commands Essentialsand Basics.pptx
mba1130feb2024
 
Linux file commands and shell scripts
PrashantTechment
 
The Korn Shell is the UNIX shell (command execution program, often c.docx
SUBHI7
 
Linuxppt
Reka
 
Linuxs1
rajikaa
 
commands and_ in _shell presentation.ppt
Serah48
 
Ad

More from duquoi (9)

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

Recently uploaded (20)

PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
July Patch Tuesday
Ivanti
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
July Patch Tuesday
Ivanti
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Python basic programing language for automation
DanialHabibi2
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 

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.