售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
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
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜