Bash Command Line and Shell Scripts Pocket Primer
As part of the best-selling Pocket Primer series, this book is designed to introduce readers to an assortment of useful command-line utilities that can be combined to create simple, yet powerful shell scripts. While all examples and scripts use the “bash” command set, many of the concepts translate into other command shells (such as sh, ksh, zsh, and csh), including the concept of piping data between commands and the highly versatile sed and awk commands. Aimed at a reader relatively new to working in a bash environment, the book is comprehensive enough to be a good reference and teach a few new techniques to those who already have some experience with creating shell scripts. It contains a variety of code fragments and shell scripts for data scientists, data analysts, and other people who want shell-based solutions to “clean” various types of text files. In addition, the concepts and code samples in this book are useful for people who want to simplify routine tasks. Includes companion files with all of the source code examples (download from the publisher by writing to info@merclearning.com).

Features:
  • Takes introductory concepts and commands in bash, and then demonstrates their uses in simple, yet powerful shell scripts
  • Contains an assortment of shell scripts for data scientists, data analysts, and other people who want shell-based solutions to “clean” various types of text files
  • Includes companion files with all of the source code examples (available for download from the publisher)
1137054273
Bash Command Line and Shell Scripts Pocket Primer
As part of the best-selling Pocket Primer series, this book is designed to introduce readers to an assortment of useful command-line utilities that can be combined to create simple, yet powerful shell scripts. While all examples and scripts use the “bash” command set, many of the concepts translate into other command shells (such as sh, ksh, zsh, and csh), including the concept of piping data between commands and the highly versatile sed and awk commands. Aimed at a reader relatively new to working in a bash environment, the book is comprehensive enough to be a good reference and teach a few new techniques to those who already have some experience with creating shell scripts. It contains a variety of code fragments and shell scripts for data scientists, data analysts, and other people who want shell-based solutions to “clean” various types of text files. In addition, the concepts and code samples in this book are useful for people who want to simplify routine tasks. Includes companion files with all of the source code examples (download from the publisher by writing to info@merclearning.com).

Features:
  • Takes introductory concepts and commands in bash, and then demonstrates their uses in simple, yet powerful shell scripts
  • Contains an assortment of shell scripts for data scientists, data analysts, and other people who want shell-based solutions to “clean” various types of text files
  • Includes companion files with all of the source code examples (available for download from the publisher)
41.95 In Stock
Bash Command Line and Shell Scripts Pocket Primer

Bash Command Line and Shell Scripts Pocket Primer

by Oswald Campesato
Bash Command Line and Shell Scripts Pocket Primer

Bash Command Line and Shell Scripts Pocket Primer

by Oswald Campesato

Paperback

$41.95 
  • SHIP THIS ITEM
    In stock. Ships in 1-2 days.
  • PICK UP IN STORE

    Your local store may have stock of this item.

Related collections and offers


Overview

As part of the best-selling Pocket Primer series, this book is designed to introduce readers to an assortment of useful command-line utilities that can be combined to create simple, yet powerful shell scripts. While all examples and scripts use the “bash” command set, many of the concepts translate into other command shells (such as sh, ksh, zsh, and csh), including the concept of piping data between commands and the highly versatile sed and awk commands. Aimed at a reader relatively new to working in a bash environment, the book is comprehensive enough to be a good reference and teach a few new techniques to those who already have some experience with creating shell scripts. It contains a variety of code fragments and shell scripts for data scientists, data analysts, and other people who want shell-based solutions to “clean” various types of text files. In addition, the concepts and code samples in this book are useful for people who want to simplify routine tasks. Includes companion files with all of the source code examples (download from the publisher by writing to info@merclearning.com).

Features:
  • Takes introductory concepts and commands in bash, and then demonstrates their uses in simple, yet powerful shell scripts
  • Contains an assortment of shell scripts for data scientists, data analysts, and other people who want shell-based solutions to “clean” various types of text files
  • Includes companion files with all of the source code examples (available for download from the publisher)

Product Details

ISBN-13: 9781683925040
Publisher: Mercury Learning and Information
Publication date: 05/19/2020
Series: Pocket Primer
Pages: 266
Product dimensions: 6.00(w) x 9.00(h) x (d)

About the Author

Oswald Campesato specializes in Deep Learning, Python, Data Science, and generative AI. He is the author/co-author of over forty-five books including Google Gemini for Python, Large Language Models, and GPT-4 for Developers (all Mercury Learning).

Table of Contents

Preface xv

Chapter 1 Introduction 1

What is Unix? 2

Available Shell Types 2

What is bash? 3

Getting help for bash Commands 4

Navigating Around Directories 4

The history Command 4

Listing Filenames with the Is Command 5

Displaying Contents of Files 8

The cat Command 8

The head and tail Commands 9

The Pipe Symbol 10

The fold Command 11

File Ownership: Owner, Group, and World 11

Hidden Files 12

Handling Problematic Filenames 13

Working with Environment Variables 13

The env Command 13

Useful Environment Variables 14

Setting the PATH Environment Variable 14

Specifying Aliases and Environment Variables 15

Finding Executable Files 16

The printf Command and the echo Command 17

The cut Command 17

The echo Command and Whitespaces 18

Command Substitution ("backtick") 20

The pipe" Symbol and Multiple Commands 20

Using a Semicolon to Separate Commands 21

The paste Command 22

Inserting Blank Lines with the paste Command 22

A Simple Use Case with the paste Command 23

A Simple Use Case with cut and paste Commands 24

What about zsh? 25

Switching between bash and zsh 26

Configuring zsh 26

Summary 26

Chapter 2 Files and Directories 29

Create, Copy, Remove, and Move Files 29

Creating Text Files 29

Copying Files 30

Copy Files with Command Substitution 30

Deleting Files 31

Moving Files 32

The In Command 32

The basename, dirname, and file Commands 33

The wc Command 33

The cat Command 34

The more Command and the less Command 34

The head Command 35

The tail Command 36

Comparing File Contents 38

The Parts of a Filename 38

Working with File Permissions 39

The chmod Command 40

Changing owner, permissions, and groups 40

The umask and ulimit Commands 41

Working with Directories 41

Absolute and Relative Directories 41

Absolute/Relative Pathnames 41

Creating Directories 42

Removing Directories 43

Navigating to Directories 43

Moving Directories 44

Using Quote Characters 44

Streams and Redirection Commands 45

Working with Metacharacters 46

Working with Character Classes 47

Metacharacters and Character Classes 48

Digits and Characters 48

Working with "^" and "\" and "!" 49

Filenames and Metacharacters 49

Summary 50

Chapter 3 Useful Commands 51

The join Command 52

The fold Command 52

The split Command 53

The sort Command 53

The uniq Command 56

How to Compare Files 56

The od Command 57

The tr Command 57

A Simple Use Case 60

The find Command 61

The tee Command 62

File Compression Commands 63

The tar command 63

The cpio Command 63

The gzip and gunzip Commands 64

The bunzip2 Command 64

The zip Command 65

Commands for zip Files and bz Files 65

Internal Field Separator (IFS) 65

Data From a Range of Columns in a Dataset 66

Working with Uneven Rows in Datasets 68

Summary 68

Chapter 4 Conditional Logic and Loops 71

Quick Overview of Operators in bash 71

Arithmetic Operations and Operators 72

The expr Command 72

Arithmetic Operators 73

Boolean and Numeric Operators 73

Compound Operators and Numeric Operators 74

Working with Variables 74

Assigning Values to Variables 75

The read Command for User Input 76

Boolean Operators and String Operators 76

Compound Operators and String Operators 77

File Test Operators 78

Compound Operators and File Operators 79

Conditional Logic with if /else/fi Statements 80

The case/esac Statement 81

Working with Strings in Shell Scripts 84

Working with Loops 85

Using a for loop 85

Checking Files in a Directory 86

Working with Nested Loops 87

Using a while Loop 89

The while, case, and if/elif/else/fi Statements 91

Using an until Loop 92

User-defined Functions 92

Creating a Simple Menu from Shell Commands 94

Arrays in bash 96

Working with Arrays 98

Summary 102

Chapter 5 Filtering Data with grep 103

What is the grep Command? 104

Metacharacters and the grep Command 105

Escaping Metacharacters with the grep Command 105

Useful Options for the grep Command 106

Character Classes and the grep Command 110

Working with the -c Option in grep 111

Matching a Range of Lines 112

Using Back References in the grep Command 114

Finding Empty lines in Datasets 116

Using Keys to Search Datasets 116

The Backslash Character and the grep Command 117

Multiple Matches in the grep Command 117

The grep Command and the xargs Command 118

Searching zip Files for a String 119

Checking for a Unique Key Value 120

Redirecting Error Messages 121

The egrep Command and fgrep Command 121

Displaying "Pure" Words in a Dataset with egrep 121

The fgrep Command 123

A Simple Use Case 123

Summary 125

Chapter 6 Transforming Data with sed 127

What is the sed Command? 127

The sed Execution Cycle 128

Matching String Patterns Using sed 128

Substituting String Patterns Using sed 129

Replacing Vowels from a String or a File 130

Deleting Multiple Digits and Letters from a String 131

Search and Replace with sed 131

Datasets with Multiple Delimiters 133

Useful Switches in sed 134

Working with Datasets 135

Printing Lines 135

Character Classes and sed 136

Removing Control Characters 137

Counting Words in a Dataset 137

Back References in sed 138

Displaying Only "Pure" Words in a Dataset 139

One Line sed Commands 140

Summary 147

Chapter 7 Working with awk 149

The awk Command 150

Built-in Variables That Control awk 150

How Does the awk Command Work? 151

Aligning Text with the printf Command 152

Conditional Logic and Control Statements 152

The while Statement 153

A for loop in awk 154

A for loop with a break Statement 154

The next and continue Statements 155

Deleting Alternate Lines in Datasets 155

Merging Lines in Datasets 156

Printing File Contents as a Single Line 156

Joining Groups of Lines in a Text File 157

Joining Alternate Lines in a Text File 158

Matching with Metacharacters and Character Sets 159

Printing Lines Using Conditional Logic 160

Splitting Filenames with awk 161

Working with Postfix Arithmetic Operators 161

Numeric Functions in awk 162

One Line awk Commands 165

Useful Short awk Scripts 166

Printing the Words in a Text String in awk 167

Count Occurrences of a String in Specific Rows 167

Printing a String in a Fixed Number of Columns 169

Printing a Dataset in a Fixed Number of Columns 169

Aligning Columns in Datasets 170

Aligning Columns and Multiple Rows in Datasets 171

Removing a Column from a Text File 173

Subsets of Columns Aligned Rows in Datasets 173

Counting Word Frequency in Datasets 175

Displaying Only "Pure" Words in a Dataset 176

Working with Multiline Records in awk 178

A Simple Use Case 179

Another Use Case 181

Summary 183

Chapter 8 Intro to Shell Scripts 185

What are Shell Scripts? 186

A Simple Shell Script 186

Setting Environment Variables via Shell Scripts 187

Sourcing or "Dotting" a Shell Script 188

Working with Functions in Shell Scripts 189

Passing values to Functions in a Shell Script (1) 190

Passing values to Functions in a Shell Script (2) 191

Iterate through values passed to a Function 192

Positional Parameters in User-defined Functions 196

Shell Scripts, Functions, and User Input 198

Recursion and Shell Scripts 199

Iterative Solutions for Factorial Values 200

Calculating Fibonacci Numbers 203

Calculating the GCD of Two Positive Integers 204

Calculating the LCM of two Positive Integers 205

Calculating Prime Divisors 207

Summary 208

Chapter 9 Shell Scripts with grep and awk Command 209

The grep Command with zip Files 209

The grep Command with Multiple Files 212

Simulating Relational Data with the grep Command 216

Checking Updates in a Logfile 218

Processing Multiline Records 220

Adding the Contents of Records 221

Using the split Function in awk 221

Scanning Diagonal Elements in Datasets 222

Adding Values From Multiple Datasets (1) 225

Adding Values From Multiple Datasets (2) 226

Adding Values From Multiple Datasets (3) 228

Calculating Combinations of Field Values 229

Summary 230

Chapter 10 Miscellaneous Shell Scripts 231

Ushig rm and mv with Directories 231

Using the find Command with Directories 233

Creating a Directory of Directories 233

Cloning a set of Sub-directories 234

Executing Files in Multiple Directories 238

The case/esac Command 239

Compressing/uncompressing Files 241

The dd Command 241

The crontab Command 242

Uncompressing Files as a cron Job 243

Scheduled Commands and Background Processes 244

How to Schedule Tasks 244

The nohup Command 244

Executing Commands Remotely 244

How to Schedule Tasks in the Background 245

How to Terminate Processes 245

Terminating Multiple Processes 245

Process-Related Commands 246

How to Monitor Processes 246

Checking Execution Results 247

System Messages and Log Files 249

Disk Usage Commands 250

Trapping and Ignoring Signals 250

Arithmetic with the bc and dc Commands 251

Working with the date Command 252

Print-related Commands 255

Creating a Report with the print f () Command 255

Checking Updates hi a Logfile 256

Listing Active Users on a Machine 258

Miscellaneous Commands 259

Summary 261

Index 263

From the B&N Reads Blog

Customer Reviews