Live data from Hacker News

Unix tricks

mmb.pcb.ub.es

151–160 of 232 posts

Re: Unix tricks

#151
post #118

* Read on 'ssh-keygen' to avoid typing passwords every time you ssh He meant ssh-agent?

No he did mean ssh-keygen which generates a public and private key pair for you. Run ssh-keygen on your local machine and copy the public key to ~/.ssh/authorized_keys and you'll be able to login to the server without a password using ssh -i /path/to/private/key user@host

That approach is insecure, however, because anyone with the private key now has access. When running ssh-keygen, you should add a passphrase to the key, then add the key to ssh-agent so you don't need a password for the account, nor do you need to type the key's passphrase constantly.

Re: Unix tricks

#152
One of my new favorites-- use ctrl-r autocompletion to grab a command close to what I want from history, tack on a character that breaks it if necessary and run that.

Then use fc to get that command back in a vi editing context, change what I want and :wq

The resulting command is immediately executed. This process can be really fast compared to manually constructing long piped commands.

Re: Unix tricks

#153
post #75
post #48

Earlier quoted context omitted.

Better than that for me is "Alt+.", much easier to type. It can be also combined with number like "Alt+2+." will insert second argument. Similarly "Alt+0+." will insert last command. http://linuxcommando.blogspot.in/2009/05/more-on-inserting-a...

If you are on OS X and use Terminal.app “Alt-.” won’t work because Alt is used for alternate characters. You have two options: enable “use option as meta” in the app settings (but you lose the extra characters) or use “Esc-.” instead. Yes, I know about iTerm. I don’t want it.

iTerm2 by chance? Carries a great deal of improvements over the original iTerm and is under active development.

Re: Unix tricks

#154
Related earlier discussions:

https://news.ycombinator.com/item?id=5022457

https://news.ycombinator.com/item?id=4481234

A pretty good thread on Reddit:

http://www.reddit.com/r/linux/comments/mi80x/give_me_that_on...

Edit: see https://news.ycombinator.com/item?id=3257393 for a discussion of the above thread.

While we're at it, consider using weborf [1] as an alternative to Python's SimpleHTTPServer for simple file sharing. I found it able to saturate a gigabit ethernet connection when hosted on a Core 2 Duo ULV laptop with an SSD.

[1] See http://galileo.dmi.unict.it/wiki/weborf/doku.php?id=start. It's available from the official repos in Debian and Ubuntu with

  sudo apt-get install weborf
Invoking it is dead simple:

  weborf -b ~/dir-to-share

Re: Unix tricks

#156
If you work with something like this

  /this/is/some/very/nested/directory/
and you need to move to almost the same structure

  /this/be/some/very/nested/directory/
then you might benefit from

  function bcd {
    cd ${PWD/$1/$2}
  }

Re: Unix tricks

#157
As an emacs user I map "C-p" "C-n" for history search in bash

In .inputrc

  "\C-p": history-search-backward
  "\C-n": history-search-forward
Also I found the following settings to be very useful:

  # List the possible completions when Tab is pressed
  set show-all-if-ambiguous on
  #tab complete without needing to get the case right
  set completion-ignore-case on

Re: Unix tricks

#158
post #101
post #55

His last trick - compressed fie transfer without intermediate state: 'tar cz folder/ | ssh server "tar xz"' Can be pulled off with two flags to scp - and you get to see progress as a benefit! scp -Cr folder server:dest/

If security isn't a big consideration (read: you control both machines and the network), you go even faster with netcat. On the receiving machine, in its destination directory: nc -l 6789 | tar xvf - And on the sending machine, from its source directory: tar cvf - . | nc receiving-machine 6789 netcat varies a bit from distro to distro, so you may need to adjust these command lines a bit to get it to work.

Add pv (available in many standard repos these days, from http://www.ivarch.com/programs/pv.shtml if not) into the mix and you get a handy progress bar too.

Re: Unix tricks

#159

Is there a command/short-cut to storing the path(s) returned from a find command? Currently I do something like: find . -name somefile.txt -print Then copy and paste the results manually into a cd command for example. I feel like there's a much better way somewhere.

xargs?

Here is an example from the man page: >For example, the following command will copy the list of >files and directories which start with > an uppercase letter in the current directory >to destdir:

                   /bin/ls -1d [A-Z]* | xargs -J % cp -rp % destdir
You can use this with find really nicely.

find . -name somefile.txt -print0 | xargs -0 -J % cp -rp % destdir

Note the -print0 and -0 flags (zero). This will use a null byte as a separator instead of spaces to avoid failing on files with spaces in their names.

Re: Unix tricks

#160

Wanted: a lint for your history that analyzes your commandline usage, suggesting these types of tips based on your historical use. history | commandlint

Where can I find commandlint?

That's a hypothetical program (note "Wanted").
Post reply on HN