Live data from Hacker News

Unix Tricks

cfenollosa.com

51–60 of 166 posts

Re: Unix Tricks

#51
post #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 )

Wow. I never knew about the `compgen -c` command to show bash command completions. Also from this reference [1] I found these:

    % compgen -b # built-ins
    % compgen -k # keywords
    % compgen -A function # functions
    % compgen -abckA function # everything
[1] http://www.cyberciti.biz/open-source/command-line-hacks/comp...

Re: Unix Tricks

#54
Its implied on the list but not mentioned specifically.

     !! 
will be substituted with the last command you typed. So if your somebody like me who frequently types

     $ apt-get update
     Could not lock yada yada are you root?
     $ sudo apt-get update
instead you can type

     $ apt-get update
     $ sudo !!

Re: Unix Tricks

#55
post #28

You know what I hate? My history isn't aggregated in real time across all my Mac OS X terminal windows. You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Especially when I hit the up arrow to go back in my terminal history.

> You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Yeah, keeping ctrl pressed in and pressing x followed by e (CTRL + x e) will open up the current line in $EDITOR and when you edit and save, replaces the current line with what you entered in your editor. Really a killer feature.

In Linux with bash (and probably other shells that are bash-compatible), you can use vi to edit any of the commands in your command history, and then execute the edited version.

Do this at the command prompt, or once in your ~/.bash_profile to make it permanent:

set -o vi

After that, you can search for any of the commands in your history, edit it, and then execute the edited command, by doing this:

At the prompt, type Esc once to get into vi command mode. Then you can press the k key repeatedly to scroll up through the command history, or (often easier) use the ? (search backward) vi command to search for a pattern to find a specific command. Once found, press v to edit it in a temp file. Then when you save and quit, the edited command gets executed.

The same technique works with emacs as the editor instead of vi, if you don't give the 'set -o vi' command, because the default editor for command line history is emacs. Also, if you have run 'set -o vi', you can switch the editor for commands back to emacs with 'set -o emacs'.

Re: Unix Tricks

#58
post #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 keychai…

I usually visit these threads knowing that I will pick up something useful to add to the toolbox... thank you for 'envoy' - I think it will streamline my ssh key management.

Re: Unix Tricks

#59
post #17

You know what I hate? My history isn't aggregated in real time across all my Mac OS X terminal windows. You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Especially when I hit the up arrow to go back in my terminal history.

Here you go, just throw it in your .bashrc: shopt -s histappend export HISTSIZE=100000 export HISTFILESIZE=100000 export HISTCONTROL=ignoredups:erasedups export PROMPT_COMMAND="history -a;history -c;history -r;$PROMPT_COMMAND" I wish I could give credit to where I originally found this but it was ages ago.

Don't you want HISTCONTROL=ignoreboth ?

Re: Unix Tricks

#60

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

The only problem with -W is that it is not available everywhere yet: RHEL6 defaults to OpenSSH 5.3, while -W was introduced in 5.4. Thankfully EL7 comes with OpenSSH 6.4 (and a kernel newer than 2.6.32!).
Post reply on HN