• Complain

Jason Cannon - Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners

Here you can read online Jason Cannon - Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2014, publisher: CreateSpace Independent Publishing Platform, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Jason Cannon Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners
  • Book:
    Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners
  • Author:
  • Publisher:
    CreateSpace Independent Publishing Platform
  • Genre:
  • Year:
    2014
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Become a Linux Ninja with Command Line Kung Fu! Do you think you have to lock yourself in a basement reading cryptic man pages for months on end in order to have ninja like command line skills? In reality, if you had someone share their most powerful command line tips, tricks, and patterns youd save yourself a lot of time and frustration. What if you could look over the shoulder of a good friend that just happened to be a command line guru? What if they not only showed you the commands they were using, but why they were using them and exactly how they worked? And what if that friend took the time to write all of it down so you can refer to it whenever you liked? Well, a friend did just that. Command Line Kung Fu is packed with dozens of tips and over 100 practical real-world examples. You wont find theoretical examples in this book. The examples demonstrate how to solve actual problems and accomplish worthwhile goals. The tactics are easy to find, too. Each chapter covers a specific topic and groups related tips and examples together. For example, if you need help extracting text from a file look in the Text Processing and Manipulation chapter. Also, a comprehensive index is included. If you want to find every example where a given command is used -- even if its not the main subject of the tip -- look in the index. It will list every single place in the book where that command appears. Here is just some of what you will learn by reading Command Line Kung Fu:
  • How to quickly and easily repeat commands in your shell history
  • Shortcuts for grabbing specific words from your shell history to use in your current command
  • How to save a copy of your command line session for later reference
  • How to strip out blank lines and comments from files
  • How to control colorized text when uses pipes and pagers
  • Ways to transform text: from changing case to substituting characters and more
  • How to extract specific blocks of text from files or streams of input
  • A quick tip to fix common typos
  • How to edit files over the network
  • How to compare the differences between files on your local computer and a remote one
  • How to create and use SSH tunnels
  • Ways to verify what programs are listening on what ports
  • How to kill all the processes for a given user with a single command
  • Strategies for dealing with multi-hop SSH connections
  • How to disconnect from a server in a way that will allow you to pick up where you left off
  • How to automate software installs that require user input
  • Shell scripting tips
  • How to automatically keep repeating a command until it succeeds
  • The right way to delete a file that is being written to
  • How to surf the web from the command line... and more importantly how to download anything from the web and interact with HTTP APIs
  • Ways to determine who and what is using the most disk space
  • How to secure your web browser session when using an open wifi hotspot
  • How to generate random passwords from the command line
  • Two tips for easily creating backups
  • Tips for handling tar archives
  • How to replace a string in multiple files at once with just one command
  • and much more...
What you learn in Command Line Kung Fu applies to any Linux distribution including Ubuntu, Debian, Linux Mint, RedHat, Fedora, OpenSUSE, Slackware, and more.

Jason Cannon: author's other books


Who wrote Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners? Find out the surname, the name of the author of the book and a list of all author's works by series.

Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Command Line Kung Fu
Jason Cannon
Command Line Kung Fu
Your Free Gift

As a thank you for reading Command Line Kung Fu, I would like to give you a copy of Linux Alternatives to Windows Applications. In it, you will be introduced to over 50 of the most popular applications available for Linux today. These applications will allow you to browse the web, watch movies, listen to music, connect to your favorite social networks, create presentations, and more. This gift is a perfect complement to this book and will help you along your Linux journey. Visit http://www.linuxtrainingacademy.com/linux-apps or click here to download your free gift.

Introduction

I have been working at the command line on Unix and Linux systems since the 1990's. Needless to say, I feel right at home with nothing more than a dollar sign and a flashing cursor staring at me. Over the years I've picked up several command line "tricks" that have saved me time and frustration.

Some of these tips were born out of necessity I simply had too much work to complete and too little time to do it in. Others were modeled after popular patterns found in computer programming and application development. The rest were shared with me, either directly or indirectly, by my command line heroes and mentors. It's amazing what you can learn by watching, emulating, and taking advice from a seasoned Unix and Linux professional.

Even though the title is Command Line Kung Fu, you don't have to be a Linux ninja to use the tactics presented in this book. The tips work as presented. You can start putting them to use immediately without fully understanding all the details and nuances. However, if you want or need more information, explanations and practical real-world examples follow each one.

Also, if you want an overview of the Linux command line and operating system please read my other book Linux for Beginners. It will give you a strong foundation upon which you can build your Linux skills.

Let's get started.

Shell History
Run the Last Command as Root
$ sudo !!
$ su -c "!!"

If you ever forget to run a command with root privileges, you can simply repeat it by using sudo !! or su -c "!!".

$ adduser sam
-bash: /usr/sbin/adduser: Permission denied
$ sudo !!
sudo adduser sam
$ id sam
uid=1007(sam) gid=1007(sam) groups=1007(sam)
$ userdel -r sam
-bash: /usr/sbin/userdel: Permission denied
$ sudo !!
sudo userdel -r sam
$ id sam
id: sam: No such user
$ useradd jim
-bash: /usr/sbin/useradd: Permission denied
$ su -c "!!"
su -c "useradd jim"
Password:
$ id jim
uid=1007(jim) gid=1007(jim) groups=1007(jim)

This exclamation mark syntax is called an event designator. An event designator references a command in your shell history. Bang-Bang (!!) repeats the most recent command, but one of my favorite uses of the event designator is to run the most recent command that starts with a given string. Heres an example.

$ whoami
jason
$ uptime
12:33:15 up 35 min, 1 user, load average: 0.00, 0.00, 0.00
$ df -hT /boot
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 485M 55M 406M 12% /boot
$ !u
uptime
12:33:29 up 35 min, 1 user, load average: 0.00, 0.00, 0.00
$ sudo !w
sudo whoami
root
Repeat the Last Command That Started with a given String
$ !

This is another example of an event designator. To recall the most recent command that begins with , run "!". You can simply specify the first letter, or as much of the string to make it unique. This example demonstrates that concept.

$ who
jason pts/1 2014-04-06 21:04 (192.168.1.117)
$ w
jason pts/1 192.168.1.117 21:04 0.00s 0.33s 0.00s w
$ !w
w
jason pts/1 192.168.1.117 21:04 0.00s 0.33s 0.00s w
$ !wh
who
jason pts/1 2014-04-06 21:04 (192.168.1.117)

Here is a practical example where you check to see if a process is running, kill it, and confirm that it did indeed stop.

$ ps -fu apache
UID PID PPID C STIME TTY TIME CMD
apache 1877 1879 0 21:32 ? 00:00:00 /usr/sbin/httpd
apache 1879 1 0 21:32 ? 00:00:00 /usr/sbin/httpd
$ sudo service httpd stop
Stopping httpd: [ OK ]
$ !p
ps -fu apache
UID PID PPID C STIME TTY TIME CMD
$
Reuse the Second Word (First Argument) from the Previous Command
$ !^

If you need to grab the second word from the previous command, you can use the "!^" word designator. Wherever you use "!^" it will be replaced by the second word from the previous command. You can also think of this as the first argument to the previous command.

$ host www.google.com 8.8.8.8
Using domain server:
Name: 8.8.8.8
Address: 8.8.8.8#53
Aliases:
www.google.com has address 173.194.46.83
www.google.com has address 173.194.46.81
www.google.com has address 173.194.46.84
www.google.com has address 173.194.46.82
www.google.com has address 173.194.46.80
www.google.com has IPv6 address 2607:f8b0:4009:805::1013
$ ping -c1 !^
ping -c1 www.google.com
PING www.google.com (173.194.46.80) 56(84) bytes of data.
64 bytes from ord08s11-in-f16.1e100.net (173.194.46.80): icmp_seq=1 ttl=51 time=17.0 ms
--- www.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 49ms
rtt min/avg/max/mdev = 17.071/17.071/17.071/0.000 ms
$
Reuse the Last Word (Last Argument) from the Previous Command
$ !$

Quite often I find myself needing to perform another operation on the last item on the previous command line. To access that item in your current command, use "!$".

$ unzip tpsreport.zip
Archive: tpsreport.zip
inflating: cover-sheet.doc
$ rm !$
rm tpsreport.zip
$ mv cover-sheet.doc reports/
$ du -sh !$
du -sh reports/
4.7G reports/
$
Reuse the Nth Word from a Previous Command

$ !!:N

$ :

To access a word in the previous command use "!!:N" where N is the number of the word you wish to retrieve. The first word is 0, the second word is 1, etc. You can think of 0 as being the command, 1 as being the first argument to the command, 2 as being the second argument, and so on.

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners»

Look at similar books to Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners»

Discussion, reviews of the book Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.