[Book] The Linux Command Line (2nd Edition)

First Post:

Last Update:

Word Count:
691

Read Time:
4 min

El libro

Introduction

This article is used to keep notes and summaries of the book “The Linux Command Line (3rd Edition)”.
The content will be continuously updated as I read through the book.

Reflection

Chapter 4 - Manipulating Files and Directories

1
cp -u *.html destination

Wildcards

Wildcard Meaning
* Matches any characters
? Matches any single character
[characters] Matches any character that is a member if the set characters
[!characters] Matches any character that is not a member of the set characters
[[:class:]] Matches any character that is a member of the specified class

Commonly Used Character Classes

Character class Meaning
[:alnum:] Matches any alphanumeric character
[:alpha:] Matches any alphabetic character
[:digit:] Matches any numeral
[:lower:] Matches any lowercase letter
[:upper:] Matches any uppercase letter
Pattern Matches
* All files
g* Any file beginning with g
b*.txt Any file beginning with b followed by any characters and ending with .txt
Data??? Any file beginning with Data followed by exactly three characters
[abc]* Any file beginning with either an a, a b, or a c
BACKUP.[0-9][0-9][0-9] Any file beginning with BACKUP. followed by exactly three numerals
[[:upper:]]* Any file beginning with an uppercase letter
[![:digit:]]* Any file not beginning with a numeral
*[[:lower:]123] Any file ending with a lowercase letter or the numerals 1, 2, or 3

mkdir

1
mkdir dir1 dir2 dir3

cp

1
cp item... directory

Useful options and Examples:

Option Meaning
-a, --archive Copy the files and directories and all of their attributes, including ownerships and permissions. Normally, copies take on the default attributes of the user performing the copy.
-i, --interactive Before overwriting an existing file, prompt the user for confirmation. If this option is not specified, cp will silently overwrite files.
-r, --recursive Recursively copy directories and their contents. This option (or the -a option) is required when copying directories.
-u, --update When copying files from one directory to another, only copy files that either don’t exist or are newer than the existing corresponding files in the destination directory. Useful for skipping unnecessary copies.
-v, --verbose Display informative messages as the copy is performed.
Command Results
cp file1 file2 Copy file1 to file2. If file2 exists, it is overwritten with the contents of file1. If file2 does not exist, it is created.
cp -i file1 file2 Same as the previous command, except that if file2 exists, the user is prompted before it is overwritten.
cp file1 file2 dir1 Copy file1 and file2 into directory dir1. The directory dir1 must already exist.
cp dir1/* dir2 Using a wildcard, copy all the files in dir1 into dir2. The directory dir2 must already exist.
cp -r dir1 dir2 Copy the contents of directory dir1 to directory dir2. If dir2 does not exist, it is created and will contain the same contents as dir1. If dir2 does exist, then dir1 (and its contents) will be copied into dir2.

mv

Useful Options and Examples:

Option Meaning
-i, --interactive Before overwriting an existing file, prompt the user for confirmation. If this option is not specified, mv will silently overwrite files.
-u, --update When moving files from one directory to another, only move files that either don’t exist or are newer than the existing corresponding files in the destination directory.
-v, --verbose Display informative messages as the move is performed.
Command Results
mv file1 file2 Move file1 to file2. If file2 exists, it is overwritten with the contents of file1. If file2 does not exist, it is created. In either case, file1 ceases to exist.
mv -i file1 file2 Same as the previous command, except that if file2 exists, the user is prompted before it is overwritten.
mv file1 file2 dir1 Move file1 and file2 into directory dir1. The directory dir1 must already exist.
mv dir1 dir2 If directory dir2 does not exist, create directory dir2 and move the contents of directory dir1 into dir2, then delete directory dir1. If directory dir2 does exist, move directory dir1 (and its contents) into directory dir2.

Chapter 6 - Redirection

Standard Input, Output and Error

Pipeline

Chapter 9 - Permissions

Chapter 15 - Storage Media

Chapter 16 - Networking

Chapter 18 - Archiving and Backup

Chapter 19 - Regular Expression

Chapter 23 - Compiling Programs

Chapter 24 - Writing Your First Script

Chapter 25 - Starting a Project