Slashdot Mirror


(Useful) Stupid Unix Tricks?

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?

32 of 2,362 comments (clear)

  1. session-sharing with screen -x by FooAtWFU · · Score: 5, Insightful
    (used in my company for doing the agile/extreme "pair programming" think with a remote devloper, among other things).

    screen is awesome.

    --
    The World Wide Web is dying. Soon, we shall have only the Internet.
  2. grep and awk by yakmans_dad · · Score: 4, Insightful

    So much easier for me to use than perl. I presume the modern unix user prefers perl.

  3. I never knew that command by PingXao · · 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.

    1. Re:I never knew that command by systemeng · · Score: 2, Insightful

      Compared to Javadocs, I'd say man pages are a gift from the dieties.

    2. Re:I never knew that command by PhilipPeake · · 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.

    3. Re:I never knew that command by Bromskloss · · Score: 2, 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?

      --
      Swedish plasma phys. PhD student; MSc EE; knows maths, programming, electronics; finance interest; seeks opportunities
    4. Re:I never knew that command by Undead+NDR · · 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.

    5. Re:I never knew that command by Anonymous Coward · · 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.

    6. Re:I never knew that command by RichiH · · Score: 2, Insightful

      Agreed. Any man page which does not list examples & common use cases at the end sucks.

  4. Re:X-forwarding by BigJClark · · Score: 5, Insightful


    ... or even funnier, is how long (as in decades) we've been able to do that.

    --

    Hi, I Boris. Hear fix bear, yes?
  5. Show attached block devices by duguk · · Score: 2, Insightful

    This shows all attached block devices (it also errors like crazy, hence the | more)

    blockdev --report /dev/* | more

    Useful sometimes! Also shows disk size and stuff.

    1. Re:Show attached block devices by tftp · · Score: 2, Insightful

      That line #3 with `echo` contains unbalanced round braces. Could it be that you had a bug and added echo to just make it work?

  6. Bah, subtlety: by FooAtWFU · · Score: 5, Insightful

    :(){ :|:& };:

    --
    The World Wide Web is dying. Soon, we shall have only the Internet.
  7. Re:rm -rf / by acidreverb · · Score: 5, Insightful

    Mediocre minds think alike. Great minds are unique.

  8. Re:Tab by jcam2 · · Score: 4, 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.

  9. Re:Tab by sorak · · Score: 2, Insightful

    How about this?

  10. Re:grep -R by Bandman · · Score: 2, Insightful

    GNU spoils us Linux folks. The 'date' command on any non-GNU system is like GNU date's retarded little brother

  11. Re:Job control. by Anonymous Coward · · 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)

  12. Re:rm -rf / by Omega996 · · Score: 5, Insightful

    sudo is for ubuntu wannabes - real UNIX admins don't sudo - they su - .

  13. Re:rm -rf / by j79zlr · · Score: 4, 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.

    --
    I'm not not licking toads.
  14. Re:rm -rf / by Teilo · · Score: 4, 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.

    --
    Mir tut es leid, Menschen daß Einfältigfehlersuchenbaumfolgendenaffen sind.
  15. Re:X-forwarding by jeremyp · · Score: 3, 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.

    --
    All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
  16. Re:rm -rf / by Omega996 · · Score: 5, Insightful

    if you haven't said "oh shit" while doing something as root, you haven't done UNIX administration in a busy production environment.

  17. Re:rm -rf / by Teilo · · Score: 2, 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!"

    --
    Mir tut es leid, Menschen daß Einfältigfehlersuchenbaumfolgendenaffen sind.
  18. Re:rm -rf / by LinusMartensson · · Score: 3, Insightful

    This reminds me of when I used DROP on the wrong server and database in MySQL. I love my backups and learned my lessons. Do not work on two things at once unless you are female.

  19. Re:Share mouse and keyboard by knothead99 · · Score: 2, Insightful

    Why not use synergy? It works cross platform so you can control Windows and Mac OS machines as well.

  20. Re:Useful tricks. by cowens · · Score: 4, Insightful

    Next trick, back ticks. `` Back ticks substitute the output of a command within a command.
    Ex. Name a file after the date. echo "hi" > `date +%Y%M%d`.txt

    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.

  21. Re:use command history effectively by seaturnip · · Score: 2, Insightful

    From my .bashrc:

    # 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

  22. cat /dev/random /dev/mouse by CrunkCreeper · · Score: 2, Insightful

    This is probably the most fun I've ever had. Since random is usually generated by different intervals 'from' the mouse, it'll keep on running and click on stuff all over the screen.: cat /dev/random > /dev/mouse Also this makes some pretty interesting sounds. Last time I tried it didn't work, but it may with older kernels.: cat /dev/kcore > /dev/dsp I've made the best scripts at work. I aliased a script for ls that'll print out files in the directory spelled out in dots, and it makes a dot-matrix type sound for each one with the beep command. You've got other fun things like wtf, cowsay, cowthink. Or you can watch pr0n at school over SSH with aa-xine. And don't forget the awesome cron job that plays at 1AM every morning for the night shift that blares out LEEEEROOOOOY JEEENKINS! My speakers are usually turned off when I come in the next day. I just want to make sure that no one is falling asleep on the job. :-p

  23. Re:rm -rf / by ndrw · · Score: 2, Insightful

    Clearly, the which which can be which'd is not the true which.

  24. Re:rm -rf / by Skrynkelberg · · Score: 2, Insightful

    I laughed.

  25. Re:rm -rf / by VShael · · Score: 2, 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.