Donkeys and Elephants and Delegates,oh my!
Check out the most popular
10 Linux Shell Tricks You Don't Already Know. Really, we swear.
venturecake.com — Yeah, I ’ve read them too. Lists of shell tricks you already know - pstree (yawn) bc (feeling sleepy), and a dozen other commands you see in every Linux site, book, and training course. Here’s a bunch of damn useful commands you haven’t heard before.
- 1610 diggs
- digg it
- nailer, on 10/11/2007, -3/+28No offense to the the people writing guides to pstree & bc, but I thought I'd add something a little more useful. All of the tips above have served me well in about 10 years of professional Linux administration, training, and design.
I think at least the majority of these should be both new and quite useful for you.- timdorr, on 10/11/2007, -1/+7I like that NFS trick at the end and the parallelizing of SSH commands. I've been using mussh, but its serialized and, as a result, slow.
- nailer, on 10/11/2007, -1/+9Hagnar: cron emails you the output of programs. That's how cron works.
I could have included extra commands to pop into a charting program, but I want to keep the examples as simple as possible. - sholdowa, on 10/11/2007, -9/+0Shame you didn't mention that this is for a specific RH distro. 'cos many of these don't work elsewhere. The 'top' > crontab example possible the most errors on a single line!
1. crontab -e takes no paramaters.
2. Which $EDITOR are you using?
3. - EarlOfLade, on 10/11/2007, -7/+1New? LOL. Nothing of interest there.
Rather than use the > and >>., use tee, i.e strace program | tee file.
Using ">" esp in programs that may need input is worthless. "tee" is a much better way. - cantormath, on 10/11/2007, -2/+7Even if you have seen these commands before, its better then a MS tutorial.
- nailer, on 10/11/2007, -1/+9sholdowa: The commands aren't distro specific, but you did find a bug which I've fixed (crontab only needs - for stdin). Fixed, thanks for letting us know.
EarlOfLade: Tee would still require you redirect stderr to stdout. - akaz, on 10/11/2007, -16/+1Wow you Linux geeks are so boring. I don't give a *****. Buried as lame.
- EarlOfLade, on 10/11/2007, -2/+2@nailer :
Whatever 2>&1 | tee filename - nailer, on 10/11/2007, -2/+3EarlOfLade:
> Whatever 2>&1 | tee filename
Please read the article.
- schestowitz, on 10/11/2007, -10/+79look; gawk; talk; date; wine; unzip; strip; touch; finger; head; mount; fsck; more; yes; spray; umount; sleep; leave
- geminitojanus, on 10/11/2007, -5/+65`push .me`,
and then just `touch .me`
till I can `wget .my`
satisfaction - rudy23, on 10/11/2007, -5/+46am sure the only place you guys have done it is at the command line.
- dirtman777, on 10/11/2007, -1/+9dugg up for giving me a good laugh.
- trogdor282, on 10/11/2007, -1/+17Ah yes, that's the most common method, but I would like to point out there's also 'man mount'
- geminitojanus, on 10/11/2007, -5/+65`push .me`,
- DrColossus, on 10/11/2007, -6/+15Any one else notice that it goes from bonus trick 3 to bonus trick 5
- JonnyTrombone, on 10/11/2007, -12/+4No...?
- IamF, on 10/11/2007, -1/+5Yes a neat list, catching memory leaks with cron was nice.
- motu, on 10/11/2007, -10/+1Hmm, I hate to say this. But this list does not contain any news. Also, I prefer tcsh much more over bash...
- jenel, on 10/11/2007, -2/+7The list was new to me. And for some other guys who are also not virgins anymore.
- JonLatane, on 10/11/2007, -3/+8Seeing parallelizing "for" loops was a "duh" moment for me. I can't believe I never thought of something so simple!
- nailer, on 10/11/2007, -1/+6jonlatane: Dude it was a duh for me too - once I figured it out.
I'd been wanting to do this for ages but couldn't figure out how to get the '&' needed to background each job not to break the 'for' loop. For my job I regularly need to create masses of simultaneous SSH tunnels - having parallel loops was the reason I learnt 'eval'
- nailer, on 10/11/2007, -1/+6jonlatane: Dude it was a duh for me too - once I figured it out.
- DarkJesus, on 10/11/2007, -3/+4Yeah, it is good to see a more advanced look at shell commands.
- ps3udov3ctor, on 10/11/2007, -3/+2some of those are pretty good, but how to redirect both stdout and stderr? anyone that doesn't know already that will surely be lost on every other tip they give there.
- geminitojanus, on 10/11/2007, -2/+2command > file 2>&1
works for bash, dunno about the rest of the shells. - davidb, on 10/11/2007, -1/+0Not only that, but the syntax in the article (command &> file) is wrong. "command >& file" would work with CSH or TCSH. "command > file 2>&1" is the correct syntax for Bash or Bourne shell, which is what most Linux users use.
- geminitojanus, on 10/11/2007, -2/+2command > file 2>&1
- eridius, on 10/11/2007, -1/+3Huh, never saw the math shell trick before ($[3 * 2]). Wonder why that isn't documented in the bash manpage?
- XgwcE1Q, on 10/11/2007, -2/+8It is documented in the bash(1) man page. The section for the syntax supported is called "ARITHMETIC EVALUATION". Also $[...] is the old (deprecated) style, where $((...)) is the new style.
Bash also supports for loops using arithmetic evaluation:
for ((i = 0; i /dev/null | while read -r size filename; do
echo "${filename} is ${size} bytes in length."
done
(not so much the use of find(1), but the use of a subshell feeder coroutine)
Another example:
(
IFS=':'
getent passwd | while read user pass uid gid comment home shell; do
if [ "${uid}" -gt "1000" ]; then
echo $(id -G "${user}") "x" | while read -d ' ' secgid; do
echo "${user} ${secgid}"
done
fi
done
) | while read user gid; do
echo "${user} has gid ${gid}"
done - nailer, on 10/11/2007, -2/+4eridius: Thanks, have updated to show $(( )) as the more modern style.
- XgwcE1Q, on 10/11/2007, -2/+8It is documented in the bash(1) man page. The section for the syntax supported is called "ARITHMETIC EVALUATION". Also $[...] is the old (deprecated) style, where $((...)) is the new style.
- xspinkickx, on 10/11/2007, -3/+6/bookmarked
- IamF, on 10/11/2007, -9/+4% %blow
%blow: No such job. - AeroGuy, on 10/11/2007, -10/+3Gah. Please bury.
- mike23w, on 10/11/2007, -4/+2nice page. all this information is in the "man" pages for those new to linux.
"man bash", in particular, has a wealth of information or google "bash tutorial" to become a power user. - spiffytech, on 10/11/2007, -1/+5Dugg just for showing me how to extract RPMs without extra software (rpm2cpio isn't in the Ubuntu repos)
- AeroGuy, on 10/11/2007, -2/+3I like the one about using three angle brackets for std in from the command line. Is there a way to strip the EOL(?) from the end so that the program stays open? Like for bc, I get sick of typing scale=6 each time. But if I make an alias for bc (3 angle brackets) 'scale=6', then bc sets scale=6 and exits without my being able to use it.
Thanks in advance if anyone has a suggestion. - crossmr, on 10/11/2007, -10/+2he promised I hadn't seem them before, but I've seen at least a couple of those before. 9 is..wtf? How is it a trick to restore an old config? The fact that you've scheduled it? What purpose does that do? you make a change, it fails..okay..lets hang out for 5 minutes while we wait for it to fix?
I don't think so.
bonus trick 1? leave off a letter..wow....someone should tell him 'read' still needs all its letters ''Despite everything you rad on the internet''
Bonus trick 5? not a trick.. go take any class and they'll harp on that non-stop..- nailer, on 10/11/2007, -2/+5> he promised I hadn't seem them before, but I've seen at least a couple of those before.
Since I don't know you personally, it's hard to say exactly what you know and don't know - I'd say at least a couple out of ten's a pretty good rate of new stuff.
> 9 is..wtf? How is it a trick to restore an old config? The fact that you've scheduled it?
> What purpose does that do? you make a change, it fails..okay..lets hang out for 5 minutes while we wait for it to fix?
The fact that you've done it after you've lost access, and would normally be unable to log in and fix it. If you hadn't scheduled it, you'd be screwed.
> bonus trick 1? leave off a letter..wow....someone should tell him 'read' still needs all its letters ''Despite everything you rad on the internet''
Thanks very much for commenting on my spelling. Clearly I don't know that read has four letters, rather than having made a small typo.
> Bonus trick 5? not a trick.. go take any class and they'll harp on that non-stop..
I hope so - at mine I certainly did. But unfortunately half of them start all their for loops with 'for i in'. - crossmr, on 10/11/2007, -6/+2You swore that I haven't seen them before. That is a bold statement to make. Maybe you shouldn't resort to hyperbole to push your blogspam.
- nailer, on 10/11/2007, -2/+5> he promised I hadn't seem them before, but I've seen at least a couple of those before.
- jellygraph, on 10/11/2007, -3/+5finally, someone posting useful shell tricks for those who actually use Linux servers and know the basics already
much appreciated, nice! - diffuze, on 10/11/2007, -3/+9Nothing new here.. but a useful read for newbies. :)
- yeffetn, on 10/11/2007, -1/+2Very nice and advanced tricks. No need for the eval "" in the parallel loop (#2) just end with &; done.
- nailer, on 10/11/2007, -2/+2Thanks!
The ampersand with the eval breaks the loop. Eval and quotes is needed. - syberdave, on 10/11/2007, -1/+3Why is eval required?
It works fine if you use a & instead of a ; after the command.
for I in *; do echo $I & done - nailer, on 10/11/2007, -1/+3Cheers syberdave, I've amended the article.
- nailer, on 10/11/2007, -2/+2Thanks!
- flarn2006, on 10/11/2007, -3/+2I'm using Windows, but I can still have fun with this 'cause I've got Cygwin!
- GaryS278, on 10/11/2007, -1/+1I don't know why this was dugg down at all, do any of you linux weenies have an explanation for that. just because someone uses windows doesn't mean you have to autodigg down.
- Spr0k3t, on 10/11/2007, -1/+2This guide was quite good. Couple of them I already knew... Keep them coming though.
- maddmike1959, on 10/11/2007, -10/+3Every "tip" I already knew about, even the bonus tips.
This is lame
burried. - it5five, on 10/11/2007, -8/+3NERDS
- speedyrev, on 10/11/2007, -3/+1What's with the page dedicated to selling HP laptops(100) ? Is he getting paid for that?
- nailer, on 10/11/2007, -1/+2speedyrev: er, there's no page dedicated to selling HP laptops. The article you're mentioning is about laptops you don't have to configure to have every component working out of the box with Linux, and mentions Macbooks as another example.
Perhaps you should read it before you comment? - speedyrev, on 10/11/2007, -2/+1Yes, I read it. It is 99% text and 100% pics of HP. The Mac mention was in a footnote. Looks like an Ad to me.
- nailer, on 10/11/2007, -1/+2speedyrev: er, there's no page dedicated to selling HP laptops. The article you're mentioning is about laptops you don't have to configure to have every component working out of the box with Linux, and mentions Macbooks as another example.
- alanic, on 10/11/2007, -1/+3dpkg is not in every distro, so tip 8 needs editing. Other than that yes, there were some really useful stuff I didn't know.
- ratsg, on 10/11/2007, -1/+2@Nailer
Why is this titled linux. I didn't see anything that was proprietary to linux. This type of stuff would work just fine in BSD or real Unix. Sure, strace would need to be substituted with dtrace/truss or what ever. Same with the package manager.
Don't corner yourself in. There is a lot of neat stuff out there to work with and learn.- nailer, on 10/11/2007, -2/+2You're right, various items could be work on other Unixes, with a little tweaking.
But I'd spend half the article on that tweaking. Proprietary Unix doesn't typically have Bash or a modern grep (apart from the new versions, which aren't in widespread use), and still doesn't package most of its apps (one of the things that frustrates me about using it). iptables is specific to Linux too.
- nailer, on 10/11/2007, -2/+2You're right, various items could be work on other Unixes, with a little tweaking.
- WarcraftJunkie, on 10/11/2007, -5/+1Heres a fun one: cat /proc/kcore
or another one sudo rm -rf /
Lol, the first one is fine, but dont try the second.. unless you like deleting all your data :P - Error601, on 10/11/2007, -2/+2You mean "how to use bash". Linux has nothing to do with it as bash came first.
The Digg Toolbar for Firefox lets you Digg, submit content, and keep track of Digg even when you're not on the Digg site. Download the official