Live data from Hacker News

Know Your Tools – Terminal and Bash

spacecowboyrocketcompany.com

41–48 of 48 posts

Re: Know Your Tools – Terminal and Bash

#41
post #26
post #20

My most used bash command is probably "sudo !!", which runs the previous command with "sudo" prepended. The 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).

I really like '!$' and '!:1' in bash. '!$' holds the last argument of the last command and '!:n' holds the nth argument. $ cd /big/long/path/to/this.txt Oops $ vim !$

It should be noted for onlookers that this is the abbreviated form; !-3:4 goes back to the third-to-last command and refers to its fourth argument, and similarly !-3:$ is its last argument.

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.

Re: Know Your Tools – Terminal and Bash

#42
post #36

Earlier quoted context omitted.

Maybe they just prefer nano? 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.

Until you want to undo something! Nano is definitely more user-friendly though. Some of the engineers I work with still don't know basic vim shortcuts, like 'w' and 'b'

I use a lot of "yw", "d4w", or "dd" ..

are there others life-saving useful as these?

Re: Know Your Tools – Terminal and Bash

#43
post #42
post #36

Earlier quoted context omitted.

Until you want to undo something! Nano is definitely more user-friendly though. Some of the engineers I work with still don't know basic vim shortcuts, like 'w' and 'b'

I use a lot of "yw", "d4w", or "dd" .. are there others life-saving useful as these?

How about find and replace?

:%s/foo/bar/gc

The "gc" will apply the find and replace globally, and ask for confirmation before changing an occurrence of "foo".

Re: Know Your Tools – Terminal and Bash

#44
post #30

Very true. I have difficulties in training new recruits with UNIX. For some reason, beginners have developed an aversion to UNIX/shell scripting. I myself have started more and more of Ruby/AWK/Python, but it is always SHELL that blows me off with the sort of impact it has on the daily work. I ended up highly optimizing my work environment to replace long ssh connections with `conn prod` (will use my RSA key and conn…

Bash scripts are great if they're yours. My current project has ~20 large bash scripts that do all sorts of different things. They were all written by people who haven't worked on the project for two years. Anyone who needs to make changes there spends far too long trying to figure out what's going on. The scripts could have been written in the same language as the project, and it wouldn't take a whole day to make ch…

Bash scripts for very simple series of commands; higher level scripts for when those sets of commands need logic wrapped 'round 'em. For example: provisioning for packer|vagrant, if you don't need to go overkill with puppet|chef.

Re: Know Your Tools – Terminal and Bash

#47
Tip: I recently looked up the man page for "which" and found out about the -a flag which will list all instances of the executable found (instead of just the first one). Incredibly useful when you have multiple installations of the same software and it's causing problems. e.g.:

    $ which -a ruby
    /Users/olalonde/.rbenv/shims/ruby
    /usr/local/bin/ruby
    /usr/bin/ruby

Re: Know Your Tools – Terminal and Bash

#48

Very true. I have difficulties in training new recruits with UNIX. For some reason, beginners have developed an aversion to UNIX/shell scripting. I myself have started more and more of Ruby/AWK/Python, but it is always SHELL that blows me off with the sort of impact it has on the daily work. I ended up highly optimizing my work environment to replace long ssh connections with `conn prod` (will use my RSA key and conn…

If you didn't know you can put ssh configurations (hosts, ports, keys, etc) in ~/.ssh/config. You can use it in scp like 'scp prod:path/to/file path/to/destination'. Not sure if there's a pro/con to mapping an alias.

I decided not to use ~/.ssh/config because I wanted the program to be dynamic and record the sessions as I connect for the first time [https://raw.githubusercontent.com/guruparan18/conn/master/co...].

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.

Post reply on HN