Slashdot Mirror


What's Your Command Line Judo?

lousyd asks: "We all have our CLI amor. That two- or three-letter command that fiddles our heartstrings. 'mv' is pedestrian, but 'mmv' is so cool. 'cp' can lug bits around all day to no applause, but 'cpio' will excite even the most jaded of command line linguists. 'How perfect!' you exclaim. So what's your poison? What turns you on? What little known command performs just the right function for you?"

6 of 272 comments (clear)

  1. can't eat just one by yagu · · Score: 5, Informative

    Command line judo? Sheesh! Where to start?

    Okay, the tool I'm using now: vim, derivative of Bill Joy's vi, with color syntax and a bounty of enhancements. (Yes, I prepare my comments in vi, then cut and paste, don't even try to make me use some GUI text widget editor and claim it can be productive.)

    And then there's:

    • sed, or even ed. ed is great for scripting edit changes if you don't have the heart to master sed. I once used "sed" to create nroff output of document versions with delete markers (asterisks), change markers, and insertion markers from our technical documentation library.
    • awk. I couldn't have done half the work I've done in my career without this one. I watched entire teams scramble to solve some problem in Visual Studio, and would crank out a twenty line awk script that afternoon. Problem solved.
    • [ef]grep. If you're going to pipeline some shit, it's nice to filter it first (and sometimes second, then third, etc....). The grep family is second to none for this. (Funny story: I once worked at Microsoft. Was doing some stuff in DOS. Asked what command I'd use to find a string in a file or files. They showed me "FIND". Okay. I typed in:
      find mystring *.*
      and literally got back:
      mystring found in *.*, and then a listing of all the lines found. No reference to the files they were in... Shit, after all, I asked to find the lines in '*.*'.

      I complained. They showed me their (Microsoft's purchased from IBM) unix, "xenix", and their "grep" command. Ahhhhh, better. I typed: grep -i mystring *.*
      and it replied "unknown option -i". I complained about not having an "ignore case" option. They looked at me like I was crazy... "Why would you ever want to ignore case?"

    • diff. A life saver. 'Nuff said.
    • find. Freak! When I first met this command I said "go away!". Talk about an obtuse syntax and paradigm. Learn it! It's worth it.
    • xargs. Nice way to get around the line length restrictions of some of the unix shells.
    • zsh, bash, (but not csh)... Any interactive shell with a good history and command line completion mechanism. I never have to remember command syntax anymore... usually I can find a usable and editable example somewhere in the last 2000 commands I've executed.

    I could go on, and probably will in some subsequent posts. When you have so many well written, well evolved, well crafted, and well behaved tools all flying in

  2. Here's mine by Henry+V+.009 · · Score: 5, Funny
    My most important tools as a system admin:
    alias rm 'rm -rf \!*'
    alias hose kill -9 '`ps -augxww | grep \!* | awk \'{print $2}\'`'
    alias kill 'kill -9 \!* ; kill -9 \!* ; kill -9 \!*'
    alias renice 'echo Renice\? You must mean kill -9.; kill -9 \!*'
  3. perl by Turmio · · Score: 5, Insightful

    First, I must comment the article. Question goes What little known command performs just the right function for you? I hope all sane people here (haha) would answer "None". There's no command that does just the right function since there's no one The Function. It depends on the situation what the function is. And in that case, per Unix philosophy, where one tool does one simple job, but does it well, you should choose the tool accordingly.

    Enough of that. If you really must name something, then, in my opinion, there's one gizmo above others. And that is

    perl

    Perl one-liners is a damn powerful concept when you get it. Say one of your boxen switches IP address. You want to replace all references in files under /etc to this new IP address. First you might think searching all the files under /etc with find(1), then passing the list of files to grep(1) and then manually editing the places where the old IP address was found with your $EDITOR. That's fine and will get the job done and all but what if you could just edit the files in place? With perl, you can.

    perl -pne's/oldip/newip/g' -i `find /etc -type f`

    and you're done (better be extra careful with commands like that for obvious reasons!). Of course you're able to do the same thing with other tools too, but I don't think it could be much easier than that. And naturally you're not just limited to simple search and replace of text, you have the full power of Perl (and CPAN!) at your disposal.

    Besides being my number one choice for creating complex scripts and small applications, Perl has very special place in my command line toolbox just next to the old friends such as grep(1), cut(1), wc(1), etc. and a huge pile of pipes :)

  4. Re:ls -d without the subcontents by pclminion · · Score: 5, Informative
    Dude...

    ls -d */

    The final slash is key.

  5. screen by pauljlucas · · Score: 5, Informative

    Multiple multiplexed ttys that stay running even after disconnect and you can reattach to them later.

    --
    If you reply, do so only to what I explicitly wrote. If I didn't write it, don't assume or infer it.
  6. Give credit where credit is due by mister_jpeg · · Score: 5, Informative

    That's the Technical Fascist's .cshrc.

    http://www.gnu.org/fun/jokes/know.your.sysadmin.ht ml

    --
    -jpeg