Live data from Hacker News

Unix tricks

mmb.pcb.ub.es

81–90 of 232 posts

Re: Unix tricks

#81
post #45

This is bad juju. 'find . -type d -exec chmod g+x {} \;' If you happen to have a malicious directory named (without double quotes): ".;sudo rm -rf /" You'd be stuffed. It's better practice to use the '-print0' flag of find(1) and pipe the result into xargs(1) with the '-0' flag set. For safety, it's best to also use '-r #' for expected number of arguments, '-n' to stop xargs from running without arguments, and "-J %"…

This is simply not true: $ mkdir '; echo woops' $ find . -type d -exec echo {} ';' . ./; echo woops As you can see 'woops' is never echoed. EDIT: The reason being the shell is never involved in this process, and the shell is what is responsible for splitting commands on semicolons/newlines.

You are assuming the exact versions of the shell and find programs that you use are the only ones that exist. It may not be a problem on your exact system, but it can be a problem elsewhere.

Re: Unix tricks

#82
post #14

Earlier quoted context omitted.

Not trying to contradict you, just some explanations 1. I prefer 'psgrep' because it covers 99% of my use cases for pgrep (ps axuf | grep $NAME) 2. htop is very nice, come on! Would not let it running on the background for hours, but it's nicer than top 3. Note taken, thanks! 4. Is ssh-agent really safer than using passwordless keys? Just asking, I'm curious

1. `man pgrep` is your friend (you save two greps, and TBH the `grep -v grep` should be a hint that there's a better way) 2. In my experience on Debian (granted this was in 2010), there is a noticeable performance difference between `htop` and `top`. 4. ssh-agent stores the password in memory and is erased on reboot. OTOH If you use a passwordless key file, anyone can use it if they have the key.

Using ssh-agent also means you can practically put a very large pass phrase on your SSH key, because you'll only type it infrequently. Good luck brute forcing my passphrase.

Re: Unix tricks

#83
post #44

Instead of find . -type d -exec chmod g+x {} \;' you can usually use chmod -R g+X . which gives additionally the group execute permission to files which have already user/everyone execute permission.

His example changes permissions for directories only, which I believe your example does not.

Re: Unix tricks

#84
post #14

Earlier quoted context omitted.

Not trying to contradict you, just some explanations 1. I prefer 'psgrep' because it covers 99% of my use cases for pgrep (ps axuf | grep $NAME) 2. htop is very nice, come on! Would not let it running on the background for hours, but it's nicer than top 3. Note taken, thanks! 4. Is ssh-agent really safer than using passwordless keys? Just asking, I'm curious

1. `man pgrep` is your friend (you save two greps, and TBH the `grep -v grep` should be a hint that there's a better way) 2. In my experience on Debian (granted this was in 2010), there is a noticeable performance difference between `htop` and `top`. 4. ssh-agent stores the password in memory and is erased on reboot. OTOH If you use a passwordless key file, anyone can use it if they have the key.

I'm pretty sure ssh-agent doesn't store the password, but the private key. Also, the fact that it supports timed expire (and can be setup to drop keys upon events such as screen lock) make it a wiser choice than passwordless keys.

Re: Unix tricks

#85
I freaked out when I found out about the "screen" command several years back. "screen" starts a virtual screen that you can detach from with "ctrl-a d" and you can log out, login from a different machine/session and reattach with "screen -r". it has history so you can run long running commands and reattach 3 days later to continue from where you left off as if you had been logged in the whole time.

Re: Unix tricks

#86
post #46

tar czf - . | ssh destination "tar xz" To pipe all the contents of your current directory (including dotfiles) to the destination machine. Greetings from LSI-UPC!

I would change this to: tar czf - . | ssh destination "cd /remote/dir; tar xz"

There is also tar -C /local/dir -czf - . | ssh dest "tar -C /remote/dir -xz"

Re: Unix tricks

#87

Earlier quoted context omitted.

Not trying to contradict you, just some explanations 1. I prefer 'psgrep' because it covers 99% of my use cases for pgrep (ps axuf | grep $NAME) 2. htop is very nice, come on! Would not let it running on the background for hours, but it's nicer than top 3. Note taken, thanks! 4. Is ssh-agent really safer than using passwordless keys? Just asking, I'm curious

re: 4: not only is an ssh agent by far safer, but most agents now allow you to set a timeout on a key, so it's not indefinitely saved in memory. A passwordless key gives anyone with acces to that file, access to the login associated with it. If that file is inadvertently exposed (oops, checked it into github...), any machine you have a login on must be considered compromised.

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

Re: Unix tricks

#88

find . -name "file-wildcard" -exec "string" {} ";" -print is something I use a lot - plus xargs sometimes

I use variations on "find" so often that I've created several little commands "fij" (find in any java source), "fit" (find in any text / org file), "fix" (find in any XML file) etc. which I use all the time

Re: Unix tricks

#90
post #85

I freaked out when I found out about the "screen" command several years back. "screen" starts a virtual screen that you can detach from with "ctrl-a d" and you can log out, login from a different machine/session and reattach with "screen -r". it has history so you can run long running commands and reattach 3 days later to continue from where you left off as if you had been logged in the whole time.

and you can do things like

  "screen -X -S minecraftserver -p 0 -X stuff "say test $(printf '\r')"
Post reply on HN