Live data from Hacker News

Know Your Tools – Terminal and Bash

spacecowboyrocketcompany.com

21–30 of 48 posts

Re: Know Your Tools – Terminal and Bash

#22
1. I like tab-completion, but I can't personally stand bash's completion feature. Be aware of differences.

2. If you want to save your command without running it... comment it out with a '#'. Bang, it's in your history.

Re: Know Your Tools – Terminal and Bash

#23

Two very basic tips for vi: 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.

vi move commands works a lot of places in the UNIX world.

Re: Know Your Tools – Terminal and Bash

#25
The first thing I do on any bash terminal is `set -o vi`. This changes the default keybindings from emacs-like to vi-like. I find it to be a huge booster to my speed in navigating the command line.

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.

Re: Know Your Tools – Terminal and Bash

#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 !$

Re: Know Your Tools – Terminal and Bash

#27
post #21

This is probably misunderstanding the demographic, but why does he suggest using nano over vim?

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.

Re: Know Your Tools – Terminal and Bash

#28
post #6

To exit vim use :wq, not just :wq - most of the problem is it getting stuck in insert mode, and not knowing how to escape into normal mode.

I could never remember that darned syntax. At some point, though, I came across an alternative to it:

shift+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.

Re: Know Your Tools – Terminal and Bash

#29

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…

It's not just UNIX, hey. I come across a lot of programmers that have no idea how to browse the basic command line in windows. I.e. They have no concept of relative paths, browsing through folders, command parameters. It's all incomprehensible "mumbo jumbo" for them.

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.

Re: Know Your Tools – Terminal and Bash

#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 changes to them.

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!

Post reply on HN