Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Software Developer's Guide to Linux

You're reading from   The Software Developer's Guide to Linux A practical, no-nonsense guide to using the Linux command line and utilities as a software developer

Arrow left icon
Product type Paperback
Published in Jan 2024
Publisher Packt
ISBN-13 9781804616925
Length 300 pages
Edition 1st Edition
Tools
Arrow right icon
Authors (2):
Arrow left icon
Christian Sturm Christian Sturm
Author Profile Icon Christian Sturm
Christian Sturm
David Cohen David Cohen
Author Profile Icon David Cohen
David Cohen
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. How the Command Line Works 2. Working with Processes FREE CHAPTER 3. Service Management with systemd 4. Using Shell History 5. Introducing Files 6. Editing Files on the Command Line 7. Users and Groups 8. Ownership and Permissions 9. Managing Installed Software 10. Configuring Software 11. Pipes and Redirection 12. Automating Tasks with Shell Scripts 13. Secure Remote Access with SSH 14. Version Control with Git 15. Containerizing Applications with Docker 16. Monitoring Application Logs 17. Load Balancing and HTTP 18. Other Books You May Enjoy
19. Index

Practical Pipe Patterns

As mentioned before, longer multi-pipe commands are built iteratively – one command at a time. However, there are some useful patterns that you’ll see re-used frequently.

“Top X”, with count

This pattern sorts the input by number of occurrences, descending. You saw this in the original example from this chapter, which displayed the most frequently used shell commands from Bash’s history file.

Here’s the pattern:

some_input | sort | uniq -c | sort -rn | head -n 3
  • The input is sorted alphabetically, and then run through uniq -c, which needs sorted input to work on.
  • uniq -c eliminates duplicates, but adds a count (-c) of how many duplicates it found for each entry.
  • sort is run again, this time as a reverse-numeric (-r and -n) sort which sorts the unique counts from the input and outputs the lines in reverse (highest number first) sorted order.
  • head takes that top ranking and cuts it down to three lines (-n 3), giving you...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime