Know Your Tools – Terminal and Bash
spacecowboyrocketcompany.com
spacecowboyrocketcompany.com
edit: Actually, something cool I learned recently is that if you put the line "set editing-mode vi" in your ~/.inputrc then vi-like editing keys are available in any program that uses readline. This includes bash and the python repl. Presumably, a bunch of other repls and interactive command lines too.
I ended up highly optimizing my work environment to replace long ssh connections with `conn prod` (will use my RSA key and connect). File tranfers with `go get prod filename` or `go send prod filename`. Another script that can remember directory paths (I have to go over lot of them every day, and typing long lengthy ones does not help).
To me, UNIX shell scripting is a lazy men's most effective tool, only if you know how to use that rightly.
Loved the post. And thanks much.
I'm surprised people don't like terminal, I love using it. It makes me feel old school, sort of like one of those hackers in the movies. That's probably just a personal thing.
I was familiar with most of the concepts but the links section made things click in that regard. Enjoyed the post as well.
I remember when I first started using the terminal, it was slow and confusing. You had to read the man pages for every little thing. Discovering the command you want is tough, I'd be screwed without the internet.
Now I hate when I need to take my hands of the keyboard to use the mouse. What a waste of time!
It's insanely useful.
Which is fine, not everyone has been exposed to it. Eventually, by the fifth time I have to tell them how to move one folder up (Cd ..), I realize that something is very, very wrong.
I think they wrote in Bash to avoid the interpreter startup time. But the scripts are run very infrequently and most of them start/stop long-running services.
That being said, getting a bash script to do the right thing is very satisfying!
Same case with `scp`, I have bunch of production servers and I have to send/get files from production server all the time. This means, I have to come up with my own one-line command [https://raw.githubusercontent.com/guruparan18/go/master/go]
As I said earlier, to me, UNIX scripting is highly personal. The scripting reflects one's personality. That is why there is not always the right one. There are several way of doing.
I've found the option[1], but it's not in my alias list.
Edit: Changelog says Version 1.20 (2008-04-14) introduced the --auto-compress option
[1]: http://www.gnu.org/software/tar/manual/html_node/gzip.html#a...
tar -xzf # eXtract Ze Files!
EDIT: I missed chadzawistowski's similar comment belowThe book "Unix Power Tools" showed me that higher-level programming languages (Perl, Python, Ruby, etc) are not needed to accomplish most administrative tasks. Awk is incredibly useful (but also very confusing, imo).
$ cd /big/long/path/to/this.txt Oops $ vim !$
It's also apparently not universally known that bash has csh-style (similar to sed) editing, so "s^foo^bar" will repeat the previous command with "bar" substituted at for bar. So "ls foo" becomes "ls bar".
Similarly with !-3:s^foo^bar
I freely mix these things with readline-editing, depending on what needs to be done.
Since csh gets a lot of disrespect these days, to give credit where due: these are all Bill Joy features from the original csh -- it's a good thing that bash borrowed innovations from various shells beyond Bourne shell and ksh.
Historical footnote: We donated code to him to do readline-style editing circa 1978, but he said raw mode was bogging down the pdp 11 too much. Systems were a bit slower back then.
You can use slash(/) and question mark(?) to search for text (forward and backward) in vi. It's useful to know these, because they also work with less(1).
If you are Windows user and used to press Ctrl+S to save the file and you accidentally do that in Vi, your terminal would get stuck. But you can use Ctrl+Q to unfreeze it.
Words to live by.
$ which -a ruby
/Users/olalonde/.rbenv/shims/ruby
/usr/local/bin/ruby
/usr/bin/ruby Type :quit<Enter> to exit Vimshift+z shift+z
I.e. You're in command mode, and essentially type two capital Z letters. It saves your document and quits.
Anywho, it's stuck with me ever since.
Actually, I think most people who use computers at work, be they writers, designers, whatever, not just programmers, would benefit from learning some bash (or batch). You can automate a lot of useful processes with a few simple scripts.
I think there are some pop/push mechanics for working directory too, but I can't find them right now.
2. If you want to save your command without running it... comment it out with a '#'. Bang, it's in your history.
More likely, if this is meant to be a gentle introduction to the command line, vim is a pretty scary place. Nano works much more like a "normal" text editor.
are there others life-saving useful as these?
:%s/foo/bar/gc
The "gc" will apply the find and replace globally, and ask for confirmation before changing an occurrence of "foo".