Skip to Content
Efficient Linux at the Command Line
book

Efficient Linux at the Command Line

by Daniel J. Barrett
February 2022
Intermediate to advanced
248 pages
5h 46m
English
O'Reilly Media, Inc.
Book available
Content preview from Efficient Linux at the Command Line
... 192.168.1.8 - - [01/Dec/2021:00:04:30 -0500] "GET /stuff.html HTTP/1.1" ... ⋮

The lines are in chronological order with timestamps, but they aren’t in alphabetical or numeric order, so the sort -r command isn’t helpful. The tac command can reverse these lines without needing to consider the timestamps.

The paste Command

The paste command combines files side by side in columns separated by a single tab character. It’s a partner to the cut command, which extracts columns from a tab-separated file:

$ cat title-words1
EFFICIENT
AT
COMMAND
$ cat title-words2
linux
the
line
$ paste title-words1 title-words2
EFFICIENT	linux
AT	the
COMMAND line
$ paste title-words1 title-words2 | cut -f2        cut & paste are complementary
linux
the
line

Change the separator to another character, such as a comma, with the option -d (meaning “delimiter”):

$ paste -d, title-words1 title-words2
EFFICIENT,linux
AT,the
COMMAND,line

Transpose the output, producing pasted rows instead of pasted columns, with the -s option:

$ paste -d, -s title-words1 title-words2
EFFICIENT,AT,COMMAND
linux,the,line

paste also interleaves data from two or more files if you change the separator to a newline character (\n):

$ paste -d "\n" title-words1 title-words2
EFFICIENT
linux
AT
the
COMMAND
line

The diff Command

diff compares two files line by line and prints a terse report about their differences:

$ cat file1
Linux is all about efficiency.
I hope you will enjoy this book.
$ cat file2 MacOS is all about efficiency. I hope you will ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Linux Command Line, 2nd Edition

The Linux Command Line, 2nd Edition

William E. Shotts
Learning Modern Linux

Learning Modern Linux

Michael Hausenblas

Publisher Resources

ISBN: 9781098113391Errata PageSupplemental Content