万本电子书0元读

万本电子书0元读

顶部广告

Linux Shell Scripting Essentials电子书

售       价:¥

4人正在读 | 0人评论 9.8

作       者:Sinny Kumari

出  版  社:Packt Publishing

出版时间:2015-11-23

字       数:154.2万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Learn shell *ing to solve complex shell-related problems and to efficiently automate your day-to-day tasks About This Book Familiarize yourself with the terminal by learning about powerful shell features Automate tasks by writing shell *s for repetitive work Packed with easy-to-follow, hands-on examples to help you write any type of shell * with confidence Who This Book Is For This book is aimed at administrators and those who have a basic knowledge of shell *ing and who want to learn how to get the most out of writing shell *s. What You Will Learn Write effective shell *s easily Perform search operations and manipulate large text data with a single shell command Modularize reusable shell *s by creating shell libraries Redirect input, output, and errors of a command or * execution to other streams Debug code with different shell debugging techniques to make your *s bug-free Manage processes, along with the environment variables needed to execute them properly Execute and embed other languages in your *s Manage creation, deletion, and search operations in files In Detail Shell *ing is a quick method to prototype complex applications or problems. Shell *s are a collection of commands to automate tasks, usually those for which the user has a repeated need, when working on Linux-based systems. Using simple commands or a combination of them in a shell can solve complex problems easily. This book starts with the basics, including essential commands that can be executed on Linux systems to perform tasks within a few nanoseconds. You’ll learn to use outputs from commands and transform them to show the data you require. Discover how to write shell *s easily, execute * files, debug, and handle errors. Next, you’ll explore environment variables in shell programming and learn how to customize them and add a new environment. Finally, the book walks you through processes and how these interact with your shell *s, along with how to use *s to automate tasks and how to embed other languages and execute them. Style and approach This book is a pragmatic guide to writing efficient shell programs, complete with hands-on examples and tips.
目录展开

Linux Shell Scripting Essentials

Table of Contents

Linux Shell Scripting Essentials

Credits

About the Author

About the Reviewers

www.PacktPub.com

Support files, eBooks, discount offers, and more

Why subscribe?

Free access for Packt account holders

Preface

What this book covers

What you need for this book

Who this book is for

Conventions

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

Questions

1. The Beginning of the Scripting Journey

Hello World in shell

Interacting with shell

Let's make it scripted

Define variables of choice

Nomenclature

Assigning a value

Accessing a value

Constant variables

Reading variables from a user input

Builtin shell variables

Operators

The assignment operator

Arithmetic operators

Logical operators

Comparison operators

Shell expansions

~ (Tilde)

* (Asterisk)

? (Question mark)

[ ] (Square brackets)

{ } (Curly brackets)

Construct commands using eval

Make bash behave using set

Exit on the first failure

Enabling/disabling symbolic link's resolution path

Setting/unsetting variables

Summary

2. Getting Hands-on with I/O, Redirection Pipes, and Filters

Standard I/O and error streams

File descriptors

Redirecting the standard I/O and error streams

Redirecting standard output

Redirecting standard input

Redirecting standard errors

Multiple redirection

Pipe and pipelines – connecting commands

Pipe

Pipeline

Regular expressions

Regular expression metacharacters

Character ranges and classes

Character ranges

Matching dates in mm-dd-yyyy format

Matching a valid month

Matching a valid day

Matching the valid year in a date

Combining valid months, days, and years regex to form valid dates

Regex for a valid shell variable

Filtering an output using grep

Syntax

Looking for a pattern in a file

Looking for a pattern in multiple files

A few more grep usages

Searching in a binary file

Searching in a directory

Excluding files/directories from a search

Display a filename with a matching pattern

Matching an exact word

Editing output using sed

String substitution using s

Multiple substitutions

Duplicating a stream using tee

Writing an output to stdout and appending to a file

Sending an output to multiple commands

Sorting and finding unique text

Sorting an input text

Sorting a single file

Redirecting output to sort

Filtering unique elements

Unique elements in a file

Character-based translation using tr

Deleting input characters

Squeezing to a single occurrence

Inverting a character set to be translated

Filtering based on lines—head and tail

Printing lines using head

Printing the first few lines

Printing the first few bytes

Printing lines using tail

Checking log entries

Finding any line in a file

The Cut-based selection

Cutting across columns

Text selection in files

Summary

3. Effective Script Writing

Exiting from scripts and exit codes

Exit codes

Exit codes with a special meaning

Script with exit codes

Testing expressions with a test

File checks

Arithmetic checks

String checks

Expression checks

Using conditional statements with if and else

Simple if and else

The if, elif, and else statements

Nested if

Indexed arrays and associative arrays

Indexed arrays

Array declaration and value assignment

Operations on arrays

The associative array

The declaration and value assignment

Operations on arrays

Looping around with for

Simple iteration

Iterating over a command output

Specifying a range to the for loop

Small and sweet for loop

The select, while, and until loops

Loop using select

The while loop

The until loop

Switch to my choice

Passing stdout as a parameter using xargs

Basic operations with xargs

Using xargs to find a file with the maximum size

Archiving files with a given pattern

Using functions and positional parameters

Calling a function in bash

Passing parameters to functions

Alias

Creating alias

Listing all aliases

Removing an alias

pushd and popd

Summary

4. Modularizing and Debugging

Modularizing your scripts

Source to a script file

Syntax

Creating a shell script library

Loading a shell script library

Calling a shell library in bash

Calling shell library in another shell script

Passing command line parameters to script

Reading arguments in scripts

Shifting command line arguments

Processing command line options in a script

Debugging your scripts

Debugging using echo

Debugging an entire script using -x

Debugging sections of a script using the set options

Command completion

Managing bash completion with complete

Viewing the existing bash completion

Modifying default bash completion behavior

Removing bash completion specification

Writing bash completion for your own application

An example of bash completion

Running the created bash completion

Summary

5. Customizing the Environment

Knowing the default environment

Viewing a shell environment

printenv

env

Differences between shell and environment variables

Modifying a shell environment

Creating environment variables

Modifying environment variables

Deleting environment variables

Using bash startup files

.bashrc

.bash_profile

.bash_logout

Knowing your history

Shell variables controlling the history

The history builtin command

Modifying the default history behavior

Handy shortcuts for seeing the history

[Ctrl + r]

Up and down arrow key

!!

!(search_string)

!?(search_string)

Task management

Running tasks in the background

Sending a running task to the background

Listing background tasks

Moving tasks to the foreground

Terminating tasks

Summary

6. Working with Files

Performing basic file operations

Creating files

Directory file

Regular file

Touch command

Using the command line editors

Using the cat command

Redirecting the command's output

Modifying files

Viewing files

Viewing content using cat

more and less

Deleting files

Deleting a regular file

Deleting a directory

Moving and copying files

Moving files

Moving a directory to a new location

Renaming a file

Copying files

Copying files locally

Copying a file to another location

Copying files remotely

Copying files to a remote server

Comparing files

Files comparison using diff

Example

Finding files

Searching files according to use case

Finding and deleting a file based on inode number

Links to a file

Soft link

Hard link

Difference between hard link and soft link

Special files

The block device file

Named pipe file

Socket file

Temporary files

Creating a temporary file using mktemp

Permission and ownership

Viewing the ownership and permission of files

Changing permission

Changing the owner and group

Changing a file's owner

Changing group ownership

Getting the list of open files

Knowing the files opened by a specific application

Listing the applications that opened a file

Knowing the files opened by a user

Configuration files

Viewing and modifying configuration files

Summary

7. Welcome to the Processes

Process management

Process creation and execution

Process termination

Using the kill command

Using the killall command

Using the pkill command

Listing and monitoring processes

Listing processes

Syntax

Simple process selection

Process selection by list

Output format control

Listing all processes with details

Listing all processes run by a user

Processes running in the current terminal

Listing processes by a command name

Tree format display of processes

Monitoring processes

Process substitution

Diffing the output of two processes

Process scheduling priorities

Changing scheduling priorities

Using nice

Using renice

Signals

Available signals

Traps

Inter-process communication

Information on IPC using ipcs

Listing information provided by IPCs

Knowing processes' PID who recently did IPCs

Summary

8. Scheduling Tasks and Embedding Languages in Scripts

Running tasks at a specific time

Executing scripts using at

Scheduling commands

Scheduling a script file

Listing scheduled tasks

Removing scheduled tasks

Cron jobs

Cron daemon

Cron configuration

Crontab entries

Special strings in Crontab

Managing the crontab entry

Listing crontab entries

Editing crontab entries

Removing crontab entries

systemd

systemd units

Managing services

Status of a service

Enabling and disabling services

Start and stop a service

Viewing system logs

Viewing the latest log entries

Viewing logs of a particular time interval

Embedding languages

Embedding Python language

Embedding AWK language

Summary

Index

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部