:set spell is pretty neat. Will use not when coding, but when writing blog posts.
Unix tricks
71–80 of 232 posts
Re: Unix tricks
#72Earlier quoted context omitted.
3) if all the lines of the 10+GB file are actually unique, wouldn't awk keep the whole file in RAM? For files larger than my RAM could this leave my system unresponsive because it's thrashing on swap?
The sort | uniq method literally needs to sort the file and pipe it to uniq, a far more memory-intensive operation than the single-pass awk check. You can write your own hash function in AWK if you think you may overstep memory, but of course you risk hash collisions. It's a tradeoff. I tried it on a 1U server with 24GB ram a few years ago and found that the sort was thrashing at the 10GB file size while AWK handled…
Awk may still be better for uniquification.
Re: Unix tricks
#73Re: Unix tricks
#74Perform the previous command as root. Great if you continually forget which of your scripts need to be run as root and which don't.
Re: Unix tricks
#75The special bash command I'm most often asked about by shoulder surfers is !$. It substitutes the last argument in the previous command into the current one. For example: $ ls /some/long/path/somewhere/looking/around/ $ cd !$ cd /some/long/path/somewhere/looking/around/
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...
Yes, I know about iTerm. I don’t want it.
Re: Unix tricks
#76This 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 %"…
$ 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.
Re: Unix tricks
#77'ssh -R 12345:localhost:22 server.com "sleep 1000; exit"' forwards server.com's port 12345 to your local ssh port, even if you machine is not externally visible on the net. This one blew my mind
ssh -fN -o ServerAliveInterval="240" -R 2222:localhost:22 example.com
(And on example.com ssh -p 2222 localhost)This lets you easily keep the tunnel open long-term. Why?
-f Background the ssh process (don't need nohup)
-N Don't run any command
-o... Make ssh do the work of keeping the session alive foreverRe: Unix tricks
#78The special bash command I'm most often asked about by shoulder surfers is !$. It substitutes the last argument in the previous command into the current one. For example: $ ls /some/long/path/somewhere/looking/around/ $ cd !$ cd /some/long/path/somewhere/looking/around/
Re: Unix tricks
#79His 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/
Tar can transfer more filetypes and attributes than scp can (even using -p option). `scp -p` only transfers mode, mtime and atime; you lose ownership, extended atributes, symlinks, and hardlinks. You will also get better compression with tar (or rsync), as it is compressing the files directly, and not just the ssh stream (-C is just passed on to ssh). I did the tests years ago, but a quick google found someone who tr…
Re: Unix tricks
#80The special bash command I'm most often asked about by shoulder surfers is !$. It substitutes the last argument in the previous command into the current one. For example: $ ls /some/long/path/somewhere/looking/around/ $ cd !$ cd /some/long/path/somewhere/looking/around/
An arguably better (and slightly more portable) way to accomplish this is the special variable $_ , which expands to the last argument of the previous command. Since $_ is a variable rather than a history substitution, it still works when there is no command history (e.g. in scripts) and allows all the usual variable expansion forms, for example ${_##*/} to extract the last path component.