Live data from Hacker News

Unix Tricks

cfenollosa.com

41–50 of 166 posts

Re: Unix Tricks

#42
I have

for cmd in $(compgen -c); do if [[ $cmd =~ ^[0-9a-zA-Z]+$ ]]; then eval "alias $cmd?='man $cmd'"; fi; done

in my .bashrc to alias command?=man command, saves some typing to get to man pages ( which I do very often )

Re: Unix Tricks

#43

You might want to try out the more modern fish shell as well: http://fishshell.com/ It makes history searching even easier.

I love fish and have happily been using it for years. Every time it comes up here, though, someone inevitably will complain about compatibility - and I will admit that RVM, for instance, has definitely caused me problems with fish in the past. I guess it depends quite a lot on your particular usage and requirements.

I like the autocompletion of fish, isn't there a way to get this in bash?

Re: Unix Tricks

#44

Earlier quoted context omitted.

The article doesn't say, so it's worth mentioning that you can type ctrl-R multiple times to search further back into command history.

I use C-r constantly. But sometimes I need to find a command, and then edit it before running it. What is the proper way to exit "search mode" and go into the normal "edit" mode?

Any movement key will do the trick. I usually use cursor-right or the end key.

It's so ingrained I had to actually do it in a shell to know what it was I did.

Re: Unix Tricks

#45
post #7

One to add: Unfreezing terminal after pressing Ctrl+S by accident. Press Ctrl-Q.

One that I needed to use a lot in the old days, and still occasionally need: If your font is all messed up, echo C-v C-o. C-v puts you into a literal mode, and C-o gets you back into the normal character set. (You probably got there by emitting a C-p at some point.)

I always used 'reset' for that.

Re: Unix Tricks

#47
Instead of using netcat when tunneling SSH through another machine like this:

    ProxyCommand ssh -T host1 'nc %h %p'
one should use this instead:

    ProxyCommand ssh -W %h:%p host1

Re: Unix Tricks

#48
Instead of

    ssh -R 12345:localhost:22 server.com "sleep 1000; exit"
use

    ssh -R 12345:localhost:22 -n server.com
The -n flag tells ssh to only make a connection, without ever running a shell. This means it even works when you don't have shell access (say, with a command= entry in .authorized_keys).

Also, I cannot recommend envoy enough in lieu of ssh-agent, if you're not using a GUI ssh agent already (e.g OSX keychain or GNOME keyring)

Last, I guarantee you don't want "$@" in those aliases, but either "$*" or $@ (certainly the latter).

Re: Unix Tricks

#49

Earlier quoted context omitted.

The article doesn't say, so it's worth mentioning that you can type ctrl-R multiple times to search further back into command history.

I use C-r constantly. But sometimes I need to find a command, and then edit it before running it. What is the proper way to exit "search mode" and go into the normal "edit" mode?

C-g (as in quit https://www.gnu.org/software/emacs/manual/html_node/emacs/Qu...) is the 'proper' way but yeah, not the only one.

Re: Unix Tricks

#50
post #29

man hier is pretty cool. It explains the root directory structure of the system.

Nice to see something I've gradually learned about by gut feel summarized. Why do some distributions use /opt a lot while others don't seem to use it at all?

Short answer would be historical reasons.

https://en.wikipedia.org/wiki/Unix_filesystem

"Contains locally installed software. Originated in System V, which has a package manager that installs software to this directory (one subdirectory per package)."

Solaris made extensive use of /opt, that flowed into some Linux packagers. It then fell out of favor as everyone put everything in /usr

Post reply on HN