(Useful) Stupid Unix Tricks? 2362
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?
session-sharing with screen -x (Score:5, Insightful)
screen is awesome.
grep and awk (Score:4, Insightful)
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:X-forwarding (Score:5, Insightful)
Re:I never knew that command (Score:3, Insightful)
Show attached block devices (Score:3, Insightful)
blockdev --report
Useful sometimes! Also shows disk size and stuff.
Bah, subtlety: (Score:5, Insightful)
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.
Re:rm -rf / (Score:5, Insightful)
Re:Tab (Score:5, Insightful)
You'd be surprised how often I have seen experienced programmers manually type out long commands or directory paths, instead of using tab completion. Sometimes I have to restrain myself from ripping the keyboard from their hands and using tab to enter the path myself in a 10th of the time.
Re:Tab (Score:3, Insightful)
How about this [vim.org]?
Re:grep -R (Score:3, Insightful)
GNU spoils us Linux folks. The 'date' command on any non-GNU system is like GNU date's retarded little brother
Re:Job control. (Score:1, Insightful)
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
You forgot disown
It puts your backgrounded jobs really in background (SIGHUP not transmitted on shell's exit)
Re:I never knew that command (Score:3, Insightful)
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.
Would you produce an example of such a man page, so that we may admire it?
Re:I never knew that command (Score:2, Insightful)
Info sucks, both as a program and as a concept. I want to read my man pages in my $PAGER, not in a dumbed-down Emacs mockup where the info I need is typically buried away in some untold subnode.
If a piece of software doesn't come with its good old man page, it simply doesn't deserve to be used.
Re:rm -rf / (Score:5, Insightful)
Re:rm -rf / (Score:5, Insightful)
Fortunately, I didn't permanently lose anything between good backups and Norton Disk Doctor.
Yes, you do need good backups whenever you are running Norton products. Good idea.
Re:rm -rf / (Score:5, Insightful)
No. People who run as root all the time are either n00bs or morons.
N00bs if they have never spoken the words, "Oh sh*t!" after running a command;
Morons if they have.
Re:X-forwarding (Score:4, Insightful)
They're probably slack jawed and astonished at how primitive and slow it is compered with a remote desktop connection.
And let's be honest, the real good bit is not that you can forward X but that you can forward anything you want, for instance, I will ssh into our gateway server and forward the RDC port from our Exchange server because it's quicker and easier than our VPN connection. RDC runs much faster over ssh than X does, btw.
Re:rm -rf / (Score:5, Insightful)
Re:I never knew that command (Score:1, Insightful)
Info's great if you're already a fan of emacs maybe but I'm not and it's kludgy and difficult to navigate. If it must all be hypertext, why not HTML which I can browse with whatever browser I want? I can hit it up from the desktop with Firefox or links from the CLI, search it with whatever indexing I like best and all without having to learn a really uncomfortable control scheme I'll only use for info.
Re:Show attached block devices (Score:2, Insightful)
Re:rm -rf / (Score:3, Insightful)
It does two things:
1) It gives you a moment to think.
2) It forces you to distinguish between commands that can frack your whole system, and commands that will likely only frack a part of it.
You guys act as if using sudo is an Ubuntu thing. For frack's sake, it predates Linux.
Since when did living in root ever become a "good thing"? I've been administering Linux systems for 10 years. I was drilled into me then to work as a user, use sudo when necessary, and leave root for those cases where sudo is impractical (in other words - when you have lots of stuff to do as root).
Unless this is a hubris competition - in which case I'll just say, "Get off my lawn, you damn kids!"
Re:rm -rf / (Score:3, Insightful)
Re:Share mouse and keyboard (Score:2, Insightful)
Re:Useful tricks. (Score:5, Insightful)
Don't use backticks unless you are stuck with bourne shell. Use $() instead:
echo hi > $(date +%Y%M%d).txt
They have two benefits over backticks: you can nest them and they are easier to see.
Re:use command history effectively (Score:3, Insightful)
# Reminder: C-R to search history, alt-. to have last argument of last command
export HISTFILESIZE=1000000 # large total history limit
export HISTSIZE=1000000 # large bash instance history limit
export HISTCONTROL=ignoredups # ignore consecutive dups
shopt -s histappend # merge together history of different bash instances
PROMPT_COMMAND="history -a" # immediately save each command to history file
cat /dev/random /dev/mouse (Score:2, Insightful)
Re:rm -rf / (Score:2, Insightful)
Clearly, the which which can be which'd is not the true which.
Re:I never knew that command (Score:3, Insightful)
Re:rm -rf / (Score:2, Insightful)
Re:rm -rf / (Score:3, Insightful)
And aren't those the target audience for this trick?
Maybe. But as Wil Wheaton says "Don't be a dick."
This is the Useful/Stupid Unix Tricks thread. Not the Malicious Unix tricks thread.