Live data from Hacker News

Unix Tricks

cfenollosa.com

61–70 of 166 posts

Re: Unix Tricks

#62
post #49

Earlier quoted context omitted.

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.

That just wipes out the whole line (on my test box).

Re: Unix Tricks

#63
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 think you meant -N, not -n. From the man page[1]:

     -N      Do not execute a remote command.  This is useful for just for‐
             warding ports (protocol version 2 only).

     -n      Redirects stdin from /dev/null (actually, prevents reading from
             stdin).  This must be used when ssh is run in the background.
[1]: http://www.openbsd.org/cgi-bin/man.cgi?query=ssh&sektion=1

Re: Unix Tricks

#64
Missing trick:

In bash, "ESC" then "." fetches the last parameter of the previous command. It's invaluable (same as typing "!$" but you get to see and edit it)

Re: Unix Tricks

#65
post #44

Earlier quoted context omitted.

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.

ISTR pressing one of those keys would obliterate the part of my line where I was writing, putting in ^B characters.

I can't replicate it now on my test box; it works exactly the way you say it should. It may be a terminal issue; I'm currently on Windows using cygwin to ssh to Linux.

Re: Unix Tricks

#66
post #29

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

TIL. As a long-time DOS user that often gets a bit lost on Unix systems I cannot stress how awesome it is to have found out about this!

Wow, DOS users still exist? Which one? FreeDOS?

Back in the late 90s when I first moved to Debian from Windows, growing up with a DOS CLI made the transition far easier to me (and having some FTP exposure didn't hurt either).

Re: Unix Tricks

#68
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 )

Speaking of man pages, in earlier versions of Unix and Linux, I used to want to redirect the output of many man commands to files for later reading, e.g. if working on C, say I wanted to read 'man ioctl', 'man stdio', 'man signal', etc. But the man output had {n|t}roff formatting characters in it, for print output, which used to mess up vi. So I used to use this script I wrote, called m:

# Put this script in a directory in your PATH.

# m: pipe man output through col and save to file(s).

mkdir -p ~/man # Only creates the dir first time, including all dirs in the path.

for name: # in $* is implied

    man $name | col -bx > ~/man/$name.m
done

Do a "chmod u+x m" to be able to run it.

Then run it like this:

m ioctl stdio signal # or any other commands

Then:

pushd ~/man; view ioctl.m stdio.m signal.m; popd

to read those pages, now stripped of formatting characters.

Re: Unix Tricks

#69
post #55
post #28

Earlier quoted context omitted.

> 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, typ…

Yes, that is also a solution. However, you cannot use vim so if you're used to vim, it might feel limited without certain commands. You're also missing eventual plugins.

It's better than nothing though.

Re: Unix Tricks

#70
post #64

Missing trick: In bash, "ESC" then "." fetches the last parameter of the previous command. It's invaluable (same as typing "!$" but you get to see and edit it)

You can get any parameter of the previous command by using "Esc, , Esc, .". If you repeat pressing "Esc, ." you get the n-th parameter from the command before the previous one, etc.

More details in this Stackoverflow answer: http://stackoverflow.com/a/4010170/578588

Post reply on HN