Slashdot Log In
(Useful) Stupid Unix Tricks?
Journal written by *no comment* (239368) and posted by
timothy
on Wed Nov 05, 2008 04:48 PM
from the sed-is-underrated dept.
from the sed-is-underrated dept.
So the other day I messaged another admin from the console using the regular old 'write' command (as I've been doing for over 10 years). To my surprise he didn't know how to respond back to me (he had to call me on the phone) and had never even known you could do that. That got me thinking that there's probably lots of things like that, and likely things I've never heard of. What sorts of things do you take for granted as a natural part of Unix that other people are surprised at?
Related Stories
[+]
(Useful) Stupid Vim Tricks? 702 comments
haroldag writes "I thoroughly enjoyed the recent post about Unix tricks, so I ask Slashdot vim users, what's out there? :Sex, :b#, marks, ctags. Any tricks worth sharing?"
[+]
News: (Stupid) Useful Emacs Tricks? 412 comments
Count Fenring writes "Since the Vi version of this question was both interesting and popular, let's hear from the other end of the spectrum. What are your favorite tricks, macros, extensions, and techniques for any of the various Emacs? Myself, I like 'M-x dunnet' ;-)"
[+]
(Useful) Stupid Regex Tricks? 516 comments
careysb writes to mention that in the same vein as '*nix tricks' and 'VIM tricks', it would be nice to see one on regular expressions and the programs that use them. What amazingly cool tricks have people discovered with respect to regular expressions in everyday life as a developer or power user?"
[+]
(Useful) Stupid BlackBerry Tricks? 238 comments
This discussion has been archived.
No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Full
Abbreviated
Hidden
Loading... please wait.
rm -rf / (Score:5, Funny)
rm -rf /
Bah, subtlety: (Score:5, Insightful)
Parent
Re:rm -rf / (Score:5, Insightful)
Parent
Re:rm -rf / (Score:5, Funny)
Parent
Well (Score:5, Funny)
Well.
dd if=/dev/zero of=/dev/sda1
Re:Well (Score:5, Interesting)
Sometimes a quick white-noise machine is relaxing. Heck, I used that command in combination with 'at' to act as a makeshift alarm clock when I was just moving into my first apartment and had forgotten my only other electronic device with an alarm (my cell phone) at the office.
Parent
session-sharing with screen -x (Score:5, Insightful)
screen is awesome.
There is this part ... (Score:5, Funny)
Tab (Score:5, Informative)
Re:Tab (Score:5, Funny)
Woah! Got any more?
(yes, I'm being sarcastic)
Parent
Re:Tab (Score:5, Informative)
With bash, you can even get tab completion for hostnames. Try this:
ssh user@l[tab]
Everything after the @ is filled in from /etc/hosts.
Parent
I never knew that command (Score:5, Insightful)
And I've been administering Linux systems for awhile now. Step back for a moment and you'll find that "man pages" and "info" are actually a pretty awful way to distribute documentation. As a supplement they'd be fine, but as the main source of information on how to use many commands... not so much.
Re:I never knew that command (Score:5, Insightful)
This is only true because people write such terrible and incomplete manual pages.
The original Bell Labs man pages completely described the system from the point of view of an administrator or user. The only better documentation was the source.
The current blight of wimpy, inaccurate and incomplete man pages seems to originate from the GNU developers who insist on using the terrible "info" crap, writing huge volumes of text with no real content, and the tradition is continued by Linux developers who generally provide little or no man page documentation -- presumably in the hope that users of their software will be tempted to ask questions on various mailing lists where they can be ritually disemboweled for displaying such a lack of understanding and disturbing the peace of the cognoscenti who have much more important things to do than answer questions of mere users of their software.
Parent
X-forwarding (Score:5, Informative)
I've seen Windows people go slack-jawed in astonishment as I ssh to the other side of the world and run X programs over forwarding.
Some refuse to believe it, others shake their heads and walk away.
Re:X-forwarding (Score:5, Insightful)
Parent
Talk / DD / Mount (Score:5, Informative)
On the older systems, talk was a great utility.
dd, device duplicator / disk destroyer
mount, what I can't have a desktop icon?
also managing disk volumes and the old conventions of /opt, /u, /usr, /usr/local
This new fangled Linux craze with all of the UI tools is feeding it. Redhat is training admins that are dependent on a given release of their enterprise software (which I am a huge fan of) but not teaching them how it works under the hood.
How about slirp? scp?
The one ray of hope seems to be a new generation hacking their bsd and linux based (iPhone/Android) phones and having fun in a somewhat embedded (but full blown) *nix environment.
cd - (Score:5, Informative)
In terms of navigation directories efficiently, I find that "cd -" is often forgotten (changes directory to your previous directory). I personally find it very useful, and couldn't live without it!
One word: (Score:5, Funny)
Showers
Job control. (Score:5, Informative)
fg, bg, kill, Ctrl-Z, &. Learn it. Know it. Live it.
Even if they do know about job control, I've seen people look for a background job with ps, and then kill it using the PID. In most shells you can just do kill %, e.g. kill %1
Re:rev (Score:5, Funny)
The rev command has got to be one of the most useless Unix commands I've ever come across. It's almost as if someone's first c program somehow got taken up as a part of standard Unix! Maybe in the days before sed and awk and perl it had some function in pipes that I can't grok, but nowadays other than making hints for video game websites I can't imagine what it's for.
Unhackable encryption of course.
Parent
Re:Listing directory contents without the ls comma (Score:5, Informative)
You're not giving echo an asterisk as a paratemer. You're giving the shell an asterisk, which it dutifully expands. echo (which in this case is a shell builtin, but it doesn't have to be then just echoes them back.
This isn't some echo peculiarity. It works for anything, even commands that don't normally take files, or even with files that look like switches (conversely, if you want to treat all subsequent arguments as files, not switches, most programs have a '--' switch):
$ ls
a -l b c
$ ls *
-rw-r--r-- 1 marcansoft users 0 2008-11-05 21:58 a
-rw-r--r-- 1 marcansoft users 0 2008-11-05 21:58 b
-rw-r--r-- 1 marcansoft users 0 2008-11-05 21:58 c
$ ls -- *
a -l b c
In the second example, ls sees "ls a -l b c" and takes -l as a switch instead of a filename.
Parent
Re:This one always surprises people for some reaso (Score:5, Informative)
Parent
Re:grep -R (Score:5, Interesting)
Hell, I think it's probably a GNU extension, because it's still not in Solaris.
I think rgrep appeared around BSD 4.4, though.
Oh well. I still surprise people with backticks. *sigh*
Parent
-exec as a test (Score:5, Informative)
One great feature of find that many people are unaware of is that you can use -exec as a test, not just as an action. For example, this is equivalent to your command above:
find . -exec grep -q {} \; -print
The "-print" action is only executed if the -exec command returns success.
You can do a lot of handy things with this. Here's a real-world example from earlier today. I wanted to change the mime-type of all the xml files in my svn repository from "application/xml" to "text/xml":
find . -name \*.xml -exec sh -c "svn propget svn:mime-type {} | grep -q application/xml" \; -exec svn propset svn:mime-type text/xml {} \;
Parent
Re:Find / Grep (Score:5, Funny)
Parent