Live data from Hacker News

Unix tricks

mmb.pcb.ub.es

161–170 of 232 posts

Re: Unix tricks

#161
post #128
post #125

Earlier quoted context omitted.

Alt + . – use the last word of the previous command. $ cp file.txt /some/annoyingly/deep/target/directory/other.txt $ cd then press Alt + . $ pwd # => /some/annoyingly/deep/target/directory

No, that gives the last word, as you say, we want the dirname of the last word. $ echo foo/bar foo/bar $ echo !$ !$:h foo/bar foo

Good point. I usually don't supply the file name of the second argument. Then it would be equivalent.

Re: Unix tricks

#163
post #92
post #54

If I may add a trick: ctrl-z - stops a program bg - sends the stopped program to the background fg - gets the program back to the foreground (interactive mode) very useful in editor sessions or when you want to get rid of the endless download/scp that is blocking your terminal

Another nice job management tool is disown, which lets you log out of your session without killing the job (similar to starting the command with nohup)

And also, you can pass the -h flag to disown to leave the job in the job control table (i.e. you can still bring it to the foreground/suspend it/etc.), but still skip sending the SIGHUP on logout.

Re: Unix tricks

#165
When creating excessively long oneliners (you know, the kind that should actually be a script, because you know you're going to find a use for it in a few weeks), the following key combo is golden:

    ^x ^e
It opens up the exported EDITOR with a tmp file containing whatever is on the command line.

Using SSH, especially on campus/in a train/other places where a wifi connection doesn't long, mosh is really a godsend. In places where mosh isn't practical or available, the following combos are really good to know:

     ~ .    # end ssh connection
     ~ ?    # show available commands
Paired with autossh which will reconnect by itself, it really takes the pain out of traveling while doing remote work.

Oh, and when you need to know what the decimal value of 0x65433 is, it's good to know that bash can do stuff like that:

    $ echo $((16#65433))
    414771
Reading the bash man page is not a bad idea in itself...

Re: Unix tricks

#167

Earlier quoted context omitted.

ssh-agent and 'ssh -A' is also useful if you have to login to one machine to access another, without having to copy your private key to the first machine. For example if you login remotely to a machine, and want to access a git repository on another: $ eval `ssh-agent -s` $ ssh-add ~/.ssh/id_ $ ssh -A you@firstserver$ git clone git+ssh:// /path/to/repository

I use agent forwarding often, but you still need to be careful, especially if you forward your agent to a machine not under your control. From the ssh man page: Agent forwarding should be enabled with caution. Users with the ability to bypass file permissions on the remote host (for the agent's UNIX-domain socket) can access the local agent through the forwarded connection. An attacker cannot obtain key material from…

The ssh_config HashKnownHosts option hashes the contents of the known_hosts file, making it intractable to get a list of hosts. But of course your shell history will still provide it.

Re: Unix tricks

#168

> Compile your own version of 'screen' from the git sources. Most versions have a slow scrolling on a vertical split or even no vertical split at all or just use tmux

Just to note, splits in tmux and screen behave differently. iirc, in screen you have a set of splits and fill them in with different ports (kind of how vim thinks of viewports). so technically you can have the same viewport open twice on your monitor and the other will mirror the workings of the one that your are working in right now. in tmux each 'tab'/window is a set of splits, which act more like sub-windows, and don't really share across multiple spaces.

Re: Unix tricks

#169

Feels very outdated. 1. Use zsh, not bash. AUTO_PUSHD, CORRECT_ALL and tons of other options make some tricks redundant. Also, the zle M-n and M-p are more useful than C-r imo. 2. Use tmux, not screen. 3. Use z ( https://github.com/rupa/z ), not j.py. 4. Use cron, not at. Or even systemd timer units, if you're so inclined. 5. Use public-key authentication and keychain, not password-based SSH. 6. Don't send emails fro…

Isn't at just a cron helper for one-off jobs?
Post reply on HN