Book Image

Linux Command Line and Shell Scripting Bible - Third Edition

By : Richard Blum, Christine Bresnahan
Book Image

Linux Command Line and Shell Scripting Bible - Third Edition

By: Richard Blum, Christine Bresnahan

Overview of this book

The Linux command line enables you to type specific shell commands directly into the system to manipulate files and query system resources. Command line statements can be combined into short programs called shell scripts, a practice increasing in popularity due to its usefulness in automation. Linux is a robust system with tremendous potential, and Linux Command Line and Shell Scripting Bible opens the door to new possibilities. Linux Command Line and Shell Scripting Bible is your essential Linux guide. It contains new functional examples that are fully updated to align with the latest Linux features. Beginning with command line fundamentals, the book moves into shell scripting and shows you the practical application of commands in automating frequently performed functions. This book is a complete guide providing detailed instruction and expert advice working within this aspect of Linux. Whether used as a tutorial or as a quick reference, this book contains information that every Linux user should know.
Table of Contents (34 chapters)
Part I: The Linux Command Line
Part II: Shell Scripting Basics
Part III: Advanced Shell Scripting
Part IV: Creating Practical Scripts
End User License Agreement

Redirecting Input and Output

Sometimes, you want to save the output from a command instead of just having it displayed on the monitor. The bash shell provides a few different operators that allow you to redirect the output of a command to an alternative location (such as a file). Redirection can be used for input as well as output, redirecting a file to a command for input. This section describes what you need to do to use redirection in your shell scripts.

Output redirection

The most basic type of redirection is sending output from a command to a file. The bash shell uses the greater-than symbol (>) for this:

command > outputfile

Anything that would appear on the monitor from the command instead is stored in the output file specified:

$ date > test6
$ ls -l test6
-rw-r--r--    1 user     user           29 Feb 10 17:56 test6
$ cat test6
Thu Feb 10 17:56:58 EDT 2014

The redirect operator created the file test6 (using the default umask settings) and redirected the output from...