Hacker News new | ask | show | jobs
by SEJeff 3276 days ago
As silly as it sounds, when I was a new Unix SysAdmin, I read the entirety of "man 1 bash", which includes all bash builtins. I found that it improved by bash-foo 100x simply by knowing about so many of the utilities. I also took some cliff notes for things that seemed generally useful.

I did it for an hour or so a night for a week or so.

That being said, a few of my personal favorites to memorize:

* Parameter expansion: https://www.gnu.org/software/bash/manual/html_node/Shell-Par...

* All of test(1) as you can use them in any if statement (/usr/bin/[ is a real command!): https://linux.die.net/man/1/test

* Knowing most of the bash internal variables: http://tldp.org/LDP/abs/html/internalvariables.html

* Keyboard shortcuts and how they are useful. A few example: CTRL-l (no need to ever use /usr/bin/clear), CTRL-k, CTRL-u, CTRL-e, CTRL-a, CTRL-w, CTRL-arrow left, CTRL-arrow right, CTRL-r (history reverse search with find as you type autocomplete)

The best way you can learn the shell is by using Linux as your primary desktop for at least a few months. You'll get very proficient very quickly by doing that.

6 comments

Also CTRL-_ which is "undo whatever you just typed"
That is a great one I didn't know (and I've been a 'nix monkey professionally since 2005). Thanks!
I was using CTRL+C to open new prompt instead of undoing. Thanks for this.
Ok, but where is the "redo" option?
pressing CTRL-w a few times feels easier to me, less awkward key combination
CTRL-w just deletes a word at a time. CTRL-_ it appears doesn't just delete the whole line you just typed, it does undo of the thing you just typed... counting backspace as "one thing you just typed" -- so it does some things you can't achieve with CTRL+w, you can even get back some text that you just erased.

I never knew this shortcut before. (I will probably never use it...)

Some good advice there.

One thing I have found that less people seem to know, is that the Unix metacharacters are expanded by the shell (bash etc.) not by individual commands. What this implies is that any command, whether built-in or written by you (in C, bash, Python or any other language), has metacharacter support automatically. That is, things like the file globbing/wildcard characters like *, ?, and [ ranges ].

This was not originally true on DOS (as a counterexample) and not sure whether it is true on Windows today (haven't checked), though I did notice that more commands seem to support wildcards in Windows nowadays.

Also, for some years now, Windows too has had redirections like:

command >file.txt 2>&1

(redirect stderr (2) to the same destination that stdout (1) is pointing to, i.e. file.txt), which Unix had from the start.

    keith@illy:~$ man bash | col -b | wc
       5738   46385  323374
A slim novella's worth on Debian Sid's man page. Never thought of just reading the whole thing, so thanks.
Yes, the man page is very good. The online gnu documentation is good, too. Some of the information will not be categorized as bash.[1] Also check out sed and awk.

[1] http://www.gnu.org/software/coreutils/manual/html_node/index...

>All of test(1) as you can use them in any if statement (/usr/bin/[ is a real command!):

Yes, and not only in an if statement. You can also use test or [ command in commands of the form:

test condition && commmand2

or

test condition || command2

which will only work if the condition is true or false, respectively (IIRC, need to check this).

That is correct, no need to check on this. I've done this for years :)
Thanks. Well, I was nearly 100% sure too (been using Unix for years too (from before Linux was created)), but "nearly" is not 100% (since I don't use that feature often), and don't like to make claims I am not sure about without a disclaimer, hence I made one :)
+1 for the shortcuts.

Also one should take a look at rlwrap after becoming comfortable with the keyboard shortcuts.