A Practical Guide to Linux Commands, Editors, and Shell Programming, Fourth Edition

A Practical Guide to Linux Commands, Editors, and Shell Programming, Fourth Edition

Read it now on the O’Reilly learning platform with a 10-day free trial.

O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.

Book description

The Most Useful Tutorial and Reference, with Hundreds of High-Quality Examples for Every Popular Linux Distribution

“First Sobell taught people how to use Linux . . . now he teaches you the power of Linux. A must-have book for anyone who wants to take Linux to the next level.”

—Jon “maddog” Hall, Executive Director, Linux International

Discover the Power of Linux–Covers macOS, too!

For use with all popular versions of Linux, including Ubuntu,™ Fedora,™ openSUSE,™ Red Hat,® Debian, Mageia, Mint, Arch, CentOS, and macOS

Linux is today’s dominant Internet server platform. System administrators and Web developers need deep Linux fluency, including expert knowledge of shells and the command line. This is the only guide with everything you need to achieve that level of Linux mastery. Renowned Linux expert Mark Sobell has brought together comprehensive, insightful guidance on the tools sysadmins, developers, and power users need most, and has created an outstanding day-to-day reference, updated with assistance from new coauthor Matthew Helmke.

This title is 100 percent distribution and release agnostic. Packed with hundreds of high-quality, realistic examples, it presents Linux from the ground up: the clearest explanations and most useful information about everything from filesystems to shells, editors to utilities, and programming tools to regular expressions.

Use a Mac? You’ll find coverage of the macOS command line, including macOS-only tools and utilities that other Linux/UNIX titles ignore.

A Practical Guide to Linux® Commands, Editors, and Shell Programming, Fourth Edition, is the only guide to deliver

Register your product at informit.com/register for convenient access to downloads, updates, and/or corrections as they become available.

Show and hide more Table of contents Product information

Table of contents

  1. Cover Page
  2. About This E-Book
  3. Title Page
  4. Copyright Page
  5. Dedication
  6. Brief Contents
  7. Contents
  8. Preface
  9. Chapter 1: Welcome to Linux and macOS
    1. The History of UNIX and GNU–Linux
      1. The Heritage of Linux: UNIX
      2. Fade to 1983
      3. Next Scene, 1991
      4. The Code Is Free
      5. Have Fun!
      1. Why Linux Is Popular with Hardware Companies and Developers
      2. Linux Is Portable
      3. The C Programming Language
      1. Linux Has a Kernel Programming Interface
      2. Linux Can Support Many Users
      3. Linux Can Run Many Tasks
      4. Linux Provides a Secure Hierarchical Filesystem
      5. The Shell: Command Interpreter and Programming Language
      6. A Large Collection of Useful Utilities
      7. Interprocess Communication
      8. System Administration
      1. GUIs: Graphical User Interfaces
      2. (Inter)Networking Utilities
      3. Software Development
      1. Chapter 2: Getting Started
        1. Conventions Used in This Book
        2. Logging In from a Terminal (Emulator)
        3. Working from the Command Line
          1. Which Shell Are You Running?
          2. Correcting Mistakes
          3. Repeating/Editing Command Lines
          1. man: Displays the System Manual
          2. apropos: Searches for a Keyword
          3. info: Displays Information About Utilities
          4. The ––help Option
          5. The bash help Command
          6. Getting Help
          1. What to Do If You Cannot Log In
          2. Logging In Remotely: Terminal Emulators, ssh, and Dial-Up Connections
          3. Using Virtual Consoles
          4. Logging Out
          5. Changing Your Password
          1. Special Characters
          2. Basic Utilities
            1. ls: Lists the Names of Files
            2. cat: Displays a Text File
            3. rm: Deletes a File
            4. less Is more: Display a Text File One Screen at a Time
            5. hostname: Displays the System Name
            1. cp: Copies a File
            2. mv: Changes the Name of a File
            3. lpr: Prints a File
            4. grep: Searches for a String
            5. head: Displays the Beginning of a File
            6. tail: Displays the End of a File
            7. sort: Displays a File in Order
            8. uniq: Removes Duplicate Lines from a File
            9. diff: Compares Two Files
            10. file: Identifies the Contents of a File
            1. echo: Displays Text
            2. date: Displays the Time and Date
            3. script: Records a Shell Session
            4. unix2dos: Converts Linux Files to Windows and macOS Format
            1. bzip2: Compresses a File
            2. bzcat and bunzip2: Decompress a File
            3. gzip: Compresses a File
            4. tar: Packs and Unpacks Archives
            1. which and whereis: Locate a Utility
            2. locate: Searches for a File
            1. who: Lists Users on the System
            2. finger: Lists Users on the System
            3. uptime: Displays System Load and Duration Information
            4. w: Lists Users on the System
            5. free: Displays Memory Usage Information
            1. write: Sends a Message
            2. mesg: Denies or Accepts Messages
            1. The Hierarchical Filesystem
            2. Directory Files and Ordinary Files
              1. Filenames
              2. The Working Directory
              3. Your Home Directory
              1. Absolute Pathnames
              2. Relative Pathnames
              1. mkdir: Creates a Directory
              2. cd: Changes to Another Working Directory
              3. rmdir: Deletes a Directory
              4. Using Pathnames
              5. mv, cp: Move or Copy Files
              6. mv: Moves a Directory
              7. Important Standard Directories and Files
              1. ls –l: Displays Permissions
              2. chmod: Changes Access Permissions
              3. Setuid and Setgid Permissions
              4. Directory Access Permissions
              1. Enabling ACLs
              2. Working with Access Rules
              3. Setting Default Rules for a Directory
              1. Hard Links
              2. Symbolic Links
              3. rm: Removes a Link
              4. Dereferencing Symbolic Links
              1. Special Characters
              2. Ordinary Files and Directory Files
                1. The Working Directory
                2. Your Home Directory
                1. A Simple Command
                2. Syntax
                3. Simple Commands
                4. Processing the Command Line
                5. Executing a Command
                6. Editing the Command Line
                1. The Screen as a File
                2. The Keyboard and Screen as Standard Input and Standard Output
                3. Redirection
                4. Pipelines
                5. Lists
                1. The ? Special Character
                2. The * Special Character
                3. The [ ] Special Characters
                1. Utilities and Builtins Introduced in This Chapter
                1. Chapter 6: The vim Editor
                  1. History
                  2. Tutorial: Using vim to Create and Edit a File
                    1. Starting vim
                    2. Command and Input Modes
                    3. Entering Text
                    4. Getting Help
                    5. Ending the Editing Session
                    6. The compatible Parameter
                    1. Online Help
                    2. Terminology
                    3. Modes of Operation
                    4. The Display
                    5. Correcting Text as You Insert It
                    6. Work Buffer
                    7. Line Length and File Size
                    8. Windows
                    9. File Locks
                    10. Abnormal Termination of an Editing Session
                    11. Recovering Text After a Crash
                    1. Moving the Cursor by Characters
                    2. Moving the Cursor to a Specific Character
                    3. Moving the Cursor by Words
                    4. Moving the Cursor by Lines
                    5. Moving the Cursor by Sentences and Paragraphs
                    6. Moving the Cursor Within the Screen
                    7. Viewing Different Parts of the Work Buffer
                    1. Inserting Text
                    2. Appending Text
                    3. Opening a Line for Text
                    4. Replacing Text
                    5. Quoting Special Characters in Input Mode
                    1. Undoing Changes
                    2. Deleting Characters
                    3. Deleting Text
                    4. Changing Text
                    5. Replacing Text
                    6. Changing Case
                    1. Searching for a Character
                    2. Searching for a String
                    3. Substituting One String for Another
                    1. Join
                    2. Status
                    3. . (Period)
                    1. The General-Purpose Buffer
                    2. Named Buffers
                    3. Numbered Buffers
                    1. Reading Files
                    2. Writing Files
                    3. Identifying the Current File
                    1. Setting Parameters from Within vim
                    2. Setting Parameters in a Startup File
                    3. The .vimrc Startup File
                    4. Parameters
                    1. Using Markers
                    2. Editing Other Files
                    3. Macros and Shortcuts
                    4. Executing Shell Commands from Within vim
                    1. Character
                    2. Word
                    3. Blank-Delimited Word
                    4. Line
                    5. Sentence
                    6. Paragraph
                    7. Screen (Window)
                    8. Repeat Factor
                    1. History
                      1. Evolution
                      2. emacs Versus vim
                      1. Starting emacs
                      2. Exiting
                      3. Inserting Text
                      4. Deleting Characters
                      5. Moving the Cursor
                      6. Editing at the Cursor Position
                      7. Saving and Retrieving the Buffer
                      1. Keys: Notation and Use
                      2. Key Sequences and Commands
                      3. META-x: Running a Command Without a Key Binding
                      4. Numeric Arguments
                      5. Point and the Cursor
                      6. Scrolling Through a Buffer
                      7. Erasing Text
                      8. Searching for Text
                      9. Using the Menubar from the Keyboard
                      1. Undoing Changes
                      2. Point, Mark, and Region
                      3. Cut and Paste: Yanking Killed Text
                      4. Inserting Special Characters
                      5. Global Buffer Commands
                      6. Visiting and Saving Files
                      7. Buffers
                      8. Windows
                      9. Foreground Shell Commands
                      10. Background Shell Commands
                      1. Selecting a Major Mode
                      2. Human-Language Modes
                      3. C Mode
                      4. Customizing Indention
                      5. Comments
                      6. Special-Purpose Modes
                      1. The .emacs Startup File
                      2. Remapping Keys
                      3. A Sample .emacs File
                      1. Access to emacs
                      1. Chapter 8: The Bourne Again Shell (bash)
                        1. Background
                        2. Startup Files
                          1. Login Shells
                          2. Interactive Nonlogin Shells
                          3. Noninteractive Shells
                          4. Setting Up Startup Files
                          5. . (Dot) or source: Runs a Startup File in the Current Shell
                          1. chmod: Makes a File Executable
                          2. #! Specifies a Shell
                          3. # Begins a Comment
                          4. Executing a Shell Script
                          1. ; and NEWLINE Separate Commands
                          2. | and & Separate Commands and Do Something Else
                          3. && and || Boolean Control Operators
                          4. ( ) Groups Commands
                          5. \ Continues a Command
                          1. jobs: Lists Jobs
                          2. fg: Brings a Job to the Foreground
                          3. Suspending a Job
                          4. bg: Sends a Job to the Background
                          1. dirs: Displays the Stack
                          2. pushd: Pushes a Directory on the Stack
                          3. popd: Pops a Directory Off the Stack
                          1. User-Created Variables
                          2. Variable Attributes
                          3. Keyword Variables
                          1. Process Structure
                          2. Process Identification
                          3. Executing a Command
                          1. Variables That Control History
                          2. Reexecuting and Editing Commands
                          3. The Readline Library
                          1. Single Versus Double Quotation Marks in Aliases
                          2. Examples of Aliases
                          1. bash Command-Line Options
                          2. Shell Features
                          1. History Expansion
                          2. Alias Substitution
                          3. Parsing and Scanning the Command Line
                          4. Command-Line Expansion
                          1. Shell Scripts
                          2. Entering and Leaving the TC Shell
                            1. Startup Files
                            1. Command-Line Expansion (Substitution)
                            2. Job Control
                            3. Filename Substitution
                            4. Manipulating the Directory Stack
                            5. Command Substitution
                            1. Word Completion
                            2. Editing the Command Line
                            3. Correcting Spelling
                            1. Variable Substitution
                            2. String Variables
                            3. Arrays of String Variables
                            4. Numeric Variables
                            5. Braces
                            6. Special Variable Forms
                            7. tcsh Variables
                            1. if
                            2. goto
                            3. Interrupt Handling
                            4. if. then. else
                            5. foreach
                            6. while
                            7. break and continue
                            8. switch
                            1. Chapter 10: Programming the Bourne Again Shell (bash)
                              1. Control Structures
                                1. if. then
                                2. if. then. else
                                3. if. then. elif
                                4. for. in
                                5. for
                                6. while
                                7. until
                                8. break and continue
                                9. case
                                10. select
                                11. Here Document
                                1. Opening a File Descriptor
                                2. Duplicating a File Descriptor
                                3. File Descriptor Examples
                                4. Determining Whether a File Descriptor Is Associated with the Terminal
                                1. Positional Parameters
                                2. Special Parameters
                                1. Shell Variables
                                2. Environment, Environment Variables, and Inheritance
                                3. Expanding Null and Unset Variables
                                4. Array Variables
                                5. Variables in Functions
                                1. type: Displays Information About a Command
                                2. read: Accepts User Input
                                3. exec: Executes a Command or Redirects File Descriptors
                                4. trap: Catches a Signal
                                5. kill: Aborts a Process
                                6. eval: Scans, Evaluates, and Executes a Command Line
                                7. getopts: Parses Options
                                8. A Partial List of Builtins
                                1. Arithmetic Evaluation
                                2. Logical Evaluation (Conditional Expressions)
                                3. String Pattern Matching
                                4. Arithmetic Operators
                                1. A Recursive Shell Script
                                2. The quiz Shell Script
                                1. Introduction to Perl
                                  1. More Information
                                  2. Help
                                  3. perldoc
                                  4. Terminology
                                  5. Running a Perl Program
                                  6. Syntax
                                  1. Scalar Variables
                                  2. Array Variables
                                  3. Hash Variables
                                  1. if/unless
                                  2. if. else
                                  3. if. elsif. else
                                  4. foreach/for
                                  5. last and next
                                  6. while/until
                                  1. Syntax and the =~ Operator
                                  1. Introduction
                                    1. Invoking Python
                                    2. More Information
                                    3. Writing to Standard Output and Reading from Standard Input
                                    4. Functions and Methods
                                    1. Scalar Variables
                                    2. Lists
                                    3. Dictionaries
                                    1. if
                                    2. if. else
                                    3. if. elif. else
                                    4. while
                                    5. for
                                    1. File Input and Output
                                    2. Exception Handling
                                    3. Pickle
                                    1. Standard Library
                                    2. Nonstandard Libraries
                                    3. SciPy and NumPy Libraries
                                    4. Namespace
                                    5. Importing a Module
                                    6. Example of Importing a Function
                                    1. History
                                    2. Notes
                                      1. Syntax and Conventions
                                      2. More Information
                                      1. Fedora/RHEL (Red Hat Enterprise Linux)
                                      2. Debian/Ubuntu/Mint
                                      3. openSUSE
                                      4. macOS
                                      1. Assigning a Password to the MariaDB User Named root
                                      2. Removing Anonymous Users
                                      3. Running the Secure Installation Script
                                      4. ~/.my.cnf: Configures a MariaDB Client
                                      5. ~/.mysql_history: Stores Your MariaDB History
                                      1. Logging In
                                      2. Creating a Table
                                      3. Adding Data
                                      4. Retrieving Data
                                      5. Backing Up a Database
                                      6. Modifying Data
                                      7. Creating a Second Table
                                      8. Joins
                                      1. Syntax
                                      2. Arguments
                                      3. Options
                                      4. Notes
                                      5. Language Basics
                                        1. Patterns
                                        2. Actions
                                        3. Comments
                                        4. Variables
                                        5. Functions
                                        6. Arithmetic Operators
                                        7. Associative Arrays
                                        8. printf
                                        9. Control Structures
                                        1. getline: Controlling Input
                                        2. Coprocess: Two-Way I/O
                                        3. Getting Input from a Network
                                        1. Syntax
                                        2. Arguments
                                        3. Options
                                        4. Editor Basics
                                          1. Addresses
                                          2. Instructions
                                          3. Control Structures
                                          4. The Hold Space
                                          1. Chapter 16: The rsync Secure Copy Utility
                                            1. Syntax
                                            2. Arguments
                                            3. Options
                                              1. Notes
                                              2. More Information
                                              1. Using a Trailing Slash ( / ) on source-file
                                              2. Removing Files
                                              3. Copying Files to and from a Remote System
                                              4. Mirroring a Directory
                                              5. Making Backups
                                              6. Restoring a File
                                              1. Introduction to OpenSSH
                                                1. Files
                                                2. More Information
                                                1. Prerequisites
                                                2. JumpStart I: Using ssh and scp to Connect to an OpenSSH Server
                                                3. Configuring OpenSSH Clients
                                                4. ssh: Logs in or Executes Commands on a Remote System
                                                5. scp: Copies Files to and from a Remote System
                                                6. sftp: A Secure FTP Client
                                                7. ~/.ssh/config and /etc/ssh/ssh_config Configuration Files
                                                1. Prerequisites
                                                2. Note
                                                3. JumpStart II: Starting an OpenSSH Server
                                                4. Authorized Keys: Automatic Login
                                                5. Randomart Image
                                                6. ssh-agent: Holds Your Private Keys
                                                7. Command-Line Options
                                                8. /etc/ssh/sshd_config Configuration File
                                                1. Forwarding X11
                                                2. Port Forwarding
                                                1. Utilities That Display and Manipulate Files
                                                2. Network Utilities
                                                3. Utilities That Display and Alter Status
                                                4. Utilities That Are Programming Tools
                                                5. Miscellaneous Utilities
                                                6. Standard Multiplicative Suffixes
                                                7. Common Options
                                                8. The sample Utility
                                                  1. sample Brief description of what the utility does
                                                  2. aspell Checks a file for spelling errors
                                                  3. at Executes commands at a specified time
                                                  4. busybox Implements many standard utilities
                                                  5. bzip2 Compresses or decompresses files
                                                  6. cal Displays a calendar
                                                  7. cat Joins and displays files
                                                  8. cd Changes to another working directory
                                                  9. chgrp Changes the group associated with a file
                                                  10. chmod Changes the access mode (permissions) of a file
                                                  11. chown Changes the owner of a file and/or the group the file is associated with
                                                  12. cmp Compares two files
                                                  13. comm Compares sorted files
                                                  14. configure Configures source code automatically
                                                  15. cp Copies files
                                                  16. cpio Creates an archive, restores files from an archive, or copies a directory hierarchy
                                                  17. crontab Maintains crontab files
                                                  18. cut Selects characters or fields from input lines
                                                  19. date Displays or sets the system time and date
                                                  20. dd Converts and copies a file
                                                  21. df Displays disk space usage
                                                  22. diff Displays the differences between two text files
                                                  23. diskutil Checks, modifies, and repairs local volumes
                                                  24. ditto Copies files and creates and unpacks archives
                                                  25. dmesg Displays kernel messages
                                                  26. dscl Displays and manages Directory Service information
                                                  27. du Displays information on disk usage by directory hierarchy and/or file
                                                  28. echo Displays a message
                                                  29. expand/unexpand Converts TABs to SPACEs and SPACEs to TABs
                                                  30. expr Evaluates an expression
                                                  31. file Displays the classification of a file
                                                  32. find Finds files based on criteria
                                                  33. finger Displays information about users
                                                  34. fmt Formats text very simply
                                                  35. fsck Checks and repairs a filesystem
                                                  36. ftp Transfers files over a network
                                                  37. gawk Searches for and processes patterns in a file
                                                  38. gcc Compiles C and C++ programs
                                                  39. GetFileInfo Displays file attributes
                                                  40. grep Searches for a pattern in files
                                                  41. gzip Compresses or decompresses files
                                                  42. head Displays the beginning of a file
                                                  43. join Joins lines from two files based on a common field
                                                  44. kill Terminates a process by PID
                                                  45. killall Terminates a process by name
                                                  46. launchctl Controls the launchd daemon
                                                  47. less Displays text files, one screen at a time
                                                  48. ln Makes a link to a file
                                                  49. lpr Sends files to printers
                                                  50. ls Displays information about one or more files
                                                  51. make Keeps a set of programs current
                                                  52. man Displays documentation for utilities
                                                  53. mc Manages files in a textual environment (aka Midnight Commander)
                                                  54. mkdir Creates a directory
                                                  55. mkfs Creates a filesystem on a device
                                                  56. mv Renames or moves a file
                                                  57. nice Changes the priority of a command
                                                  58. nl Numbers lines from a file
                                                  59. nohup Runs a command that keeps running after you log out
                                                  60. od Dumps the contents of a file
                                                  61. open Opens files, directories, and URLs
                                                  62. otool Displays object, library, and executable files
                                                  63. paste Joins corresponding lines from files
                                                  64. pax Creates an archive, restores files from an archive, or copies a directory hierarchy
                                                  65. plutil Manipulates property list files
                                                  66. pr Paginates files for printing
                                                  67. printf Formats string and numeric data
                                                  68. ps Displays process status
                                                  69. renice Changes the priority of a process
                                                  70. rm Removes a file (deletes a link)
                                                  71. rmdir Removes directories
                                                  72. rsync Securely copies files and directory hierarchies over a network
                                                  73. scp Securely copies one or more files to or from a remote system
                                                  74. screen Manages several textual windows
                                                  75. sed Edits a file noninteractively
                                                  76. SetFile Sets file attributes
                                                  77. sleep Creates a process that sleeps for a specified interval
                                                  78. sort Sorts and/or merges files
                                                  79. split Divides a file into sections
                                                  80. ssh Securely runs a program or opens a shell on a remote system
                                                  81. sshfs/curlftpfs Mounts a directory on an OpenSSH or FTP server as a local directory
                                                  82. stat Displays information about files
                                                  83. strings Displays strings of printable characters from files
                                                  84. stty Displays or sets terminal parameters
                                                  85. sysctl Displays and alters kernel variables at runtime
                                                  86. tail Displays the last part (tail) of a file
                                                  87. tar Stores or retrieves files to/from an archive file
                                                  88. tee Copies standard input to standard output and one or more files
                                                  89. telnet Connects to a remote computer over a network
                                                  90. test Evaluates an expression
                                                  91. top Dynamically displays process status
                                                  92. touch Creates a file or changes a file’s access and/or modification time
                                                  93. tr Replaces specified characters
                                                  94. tty Displays the terminal pathname
                                                  95. tune2fs Changes parameters on an ext2, ext3, or ext4 filesystem
                                                  96. umask Specifies the file-creation permissions mask
                                                  97. uniq Displays unique lines from a file
                                                  98. w Displays information about local system users
                                                  99. wc Displays the number of lines, words, and bytes in one or more files
                                                  100. which Shows where in PATH a utility is located
                                                  101. who Displays information about logged-in users
                                                  102. xargs Converts standard input to command lines
                                                  1. Appendix A Regular Expressions
                                                    1. Characters
                                                    2. Delimiters
                                                    3. Simple Strings
                                                    4. Special Characters
                                                      1. Periods
                                                      2. Brackets
                                                      3. Asterisks
                                                      4. Carets and Dollar Signs
                                                      5. Quoting Special Characters
                                                      1. Longest Match Possible
                                                      2. Empty Regular Expressions
                                                      1. Ampersand
                                                      2. Quoted Digit
                                                      1. Solving a Problem
                                                      2. Finding Linux and macOS Related Information
                                                        1. Mailing Lists
                                                        1. Using dnf
                                                          1. Using dnf to Install, Remove, and Update Packages
                                                          2. Other dnf Commands
                                                          3. dnf Groups
                                                          4. Downloading rpm Package Files Using dnf download
                                                          5. Configuring dnf
                                                          1. Using apt-get to Install, Remove, and Update Packages
                                                          2. Using apt-get to Upgrade the System
                                                          3. Other apt-get Commands
                                                          4. Using apt Commands
                                                          5. Repositories
                                                          6. sources.list: Specifies Repositories for apt-get to Search
                                                          1. Open Directory
                                                          2. Filesystems
                                                            1. Nondisk Filesystems
                                                            2. Case Sensitivity
                                                            3. /Volumes
                                                            1. File Forks
                                                            2. File Attributes
                                                            3. ACLs
                                                            Show and hide more

                                                            Product information

                                                            • Title: A Practical Guide to Linux Commands, Editors, and Shell Programming, Fourth Edition
                                                            • Author(s): Mark G. Sobell, Matthew Helmke
                                                            • Release date: November 2017
                                                            • Publisher(s): Pearson
                                                            • ISBN: 9780134774626