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?"

14 of 272 comments (clear)

  1. groff by (1+-sqrt(5))*(2**-1) · · Score: 2, Interesting
    groff -ms -t -Tascii <file>.ms
    is how I code all my outgoing emails; that's GNU troff with the ms macro package and tbl preprocessor.

    Justifies nicely said paragraphs; provides lists and sigart.

  2. ls -t | head by ArmorFiend · · Score: 2, Interesting

    ls -t | head
    This is nice for listing the 10 most recently modified files. Usually the one you want is the first or second one.

  3. the one that impresses most people by elmegil · · Score: 2, Interesting
    Though I have no idea why, it's pretty basic:
    find . -type f -exec grep regexp {} /dev/null \;
    The tricky bit is that adding /dev/null means I will always see the filename in the output; otherwise grepping against one file only returns the matched strings.
    --
    7 November 2006: The day Americans realized corruption and incompetence weren't addressing 11 September 2001
  4. Re:CTRL + L by pclminion · · Score: 2, Interesting
    CTRL+L in almost any terminal application forces a terminal redraw. Comes in handy when the application doesn't explicitly detect SIGWINCH, and you want to resize the terminal window. Resize, then hit CTRL+L to inform the app that the window size changed.

    I wish the behavior was the same in bash, but for some reason they chose to make it clear the screen instead.

  5. Re:perl by davegaramond · · Score: 2, Interesting

    Second that. "Traditional" Unix tools sometimes just don't cut it (or they do, but requires significantly longer typing and multi-piping work).

    I use this all the time:

    $ perlrename -e's/.\[www.descargasweb.net\]//' *
    $ perlrename -e's/.\[www.\S+?\]//' *
    $ perlrename -e'$_=lc' *
    $ perlrename -de's/Sex And The City - S(\d+)E(\d+)/SATC - $1$2/ig' Sex*
    etc etc

    where perlrename is a 30-something perl script.

  6. unison by buffy · · Score: 2, Interesting

    Based on the rsync protocol, unison can maintain a bi-direction file sync. I use it to sync my personal data between home and co-lo'ed server, and work and co-lo'ed server. I can update files in any of the three locations and they'll be replicated across all three.

    -buf

  7. Re:ls -d without the subcontents by sootman · · Score: 2, Interesting

    try ls -F | grep /

    '-F' shows a slash after each entry that's a directory, an asterisk after each executable, and some other things. Read the man page for 'ls' sometime, it's like a whole freaking operating system.

    NAME
              ls - list directory contents

    SYNOPSIS
              ls [-ABCFGHLPRTWZabcdfghiklmnopqrstuwx1]

    By the way, my favorite script fu is `du -sh ./*` to show how much room each file takes up, and it adds up directories also--just like 'calculate folder sizes' has done in Mac OS for a decade.

    --
    Dear Slashdot: next time you want to mess with the site, add a rich-text editor for comments.
  8. Re:can't eat just one by bergeron76 · · Score: 2, Interesting

    I actually use a shell script in my .bash_logout that appends my .history file to a master "history" file. It's helped me numerous times when I've need to recall a command I ran ages ago. I just use grep succesively until I find the obscure command string.

    I don't mean that I was looking for a single command; I use bash pretty hardcore, and I've used pipes to do some pretty extensive things - that's where I think history has it's greatest use.

    (and yes, I'm using bash 3 and my HISTSIZE envvar is set to 10000)

    --
    Don't think that a small group of dedicated individuals can't change the world. It's the only thing that ever has.
  9. Re:xargs and for loops by photon317 · · Score: 2, Interesting


    Oh a couple more good simple ones popped into my head for beginners:

    Use "&&" between commands, and the second command will only execute if the first command succeeded. For example:

    make && make install

    That will only run the "make install" if the "make" succeeded (which is kinda contrived, since for most packages a simple "make install" would have done the same all on it's own).

    And also, did you know that you can group commands with parentheses, and you can pipe into parenthesized groups of commands? Piping into a group of commands will send the pipe data to the first command in the group that actually wants it. You can copy a directory over from one place to another using tar all in one line like so:

    tar -cf - . | (cd /otherdir/; tar -xvBpf -)

    The two tar commands are simply piping a tar-format file between them without using the disk, and the second tar runs with it's current directory set to /otherdir/.

    --
    11*43+456^2
  10. Midnight Commander. by Inoshiro · · Score: 2, Interesting

    'mc' is your gateway to a much more powerful shell. Combine your command line shell with quick changing to bookmarked dirs (ctrl+\); easy adding to that via alt+a; F2 menus that let you easily compress subdirs, or run other things from your actions file based on the mime-type or file pattern; two-panes at two different FS locations; undelete FS, FTPFS, and other meta-FS interfaces; good mouse support; built-in editor (Cool edit); prompts you for arguments for makefiles you hit enter on...

    The list goes on. Midnight Commander is a shell designed to speed up all your common tasks. It has sane defaults you don't really have to change much. It'll make you more productive!

    --
    --
    Internet Explorer (n): Another bug -- that is, a feature that can't be turned off -- in Windows.
  11. ZTree and UnixTree by Glonoinha · · Score: 3, Interesting

    Yea, Though I compute through the user interface of the shadow of death, I shall fear no evil, for ZTree is with me.

    No joke - ZTree is a character for character re-write of an old utility called XTree Gold v2.0 or 2.5 - and it is by far the most effective and influential interface between me and my data. The entire file system is but an extension of my mental processes, and I can slice and dice through the multi-dimensional (time, space, attributes, multi-layered directory structure, multi-drive architecture,) in effect creating a virtual directory within which I control the parameters driving what is listed, in what order - then copy, view, move, delete, diff (file compare), view in hex mode (and edit it in hex mode), search for text in lists of files, compare directory trees for like or different files (binary, time stamp, etc.)

    It is totally CUI, about like Midnight commander but a ton better. Take time to get fluent in ZTree (UnixTree for Unix / Linux, a bit older with a few quirks, but still pretty damn good) and you will be like the guys in the Matrix sitting at their green screen terminals.

    ZTree Don't leave $HOME without it.

    --
    Glonoinha the MebiByte Slayer
    1. Re:ZTree and UnixTree by Glonoinha · · Score: 2, Interesting

      Ya - there is a Unix version too (not from the same guys, but following the same exactly layout.)

      And I got excited about TC - but alas it is mouse clicky centric. ZTree was designed and implemted to be 100% character based (although I guess you could use the mouse, I haven't actually tried.)

      When you can use TC to find the files located somewhere on your hard drive, directory unknown, name unknown, extension unknown, dated somewhere around Christmas of 2003, containing the phrase 'Total Commander' but not containing the phrase 'Midnight Commander', sized between 50k and 53k, excluding .dll, .exe, .js and .html files, including files that are flagged system or hidden but excluding files that are flagged 'system and hidden and read-only', and then create a text file with a list of the full path/name.ext of all the files sorted reverse chronologically - without touching the mouse - in under 20 seconds - and then copy all of those files yet only those files (twice, one including directory structures, and again just dumping all of them into some new directory) to another hard drive ... then I will give it another look, maybe even drop ZTree / UnixTree (which run from the command line / command prompt / korn shell w/o a need for any GUI or mouse) for it. Until then, it looks cool, but I'm going to keep on recommending my CUI.

      --
      Glonoinha the MebiByte Slayer
  12. Re:assign them to a short name by newsblaze · · Score: 2, Interesting

    Hello Robert.
    My name is Alan, no reference to Tron

    in my .cshrc, I have this:
    alias lh "ls -lt !* | head -15"
    alias lt "ls -lt !* | more"
    alias hog "ps -eo pcpu,vsz,args,time | sort -rn | head -11"
    alias ff "find . -name !* -print"

    I use these and many more when I'm working on the newspaper.
    You can type these aliases on the commandline if you don't want to add them to your .cshrc and it will work for just that session.

    So then I type lh in the CLI and it shows the newest 15 files - you can change that number to whatever you like.

    --
    Daily News http://newsblaze.com
  13. I love the SELECT command... by Richard+Steiner · · Score: 2, Interesting

    ...but it's limited to JP Software shells (4DOS, 4NT, 4OS2), and the authors of Linux shells don't seem interested in implementing it.

    SELECT is a command which provides a fullscreen point-and-shoot file selection interface for other commands, allowing for the easy arbitrary selection of target files (point-and-shoot) in command aliases or batch/script files. In essence, it provides a mini filemanager interface which can be used to select the targets for *any* command on the command line, used in aliases, etc.

    Some simple examples (from my 4OS2 alias file) are as follows:

    TCOPY=select copy (*.*) %1
    TMOVE=select move (*.*) %1
    TDEL=select del (*.*)
    TRUN=select %1 (*.*)
    TEDIT=trun fte
    TLIST=trun list
    UNZ=f:\unz.cmd
    TUNZ=select unz (*.zip)

    The filespec in parenthesis limits the files which appear in the selection list, so the TUNZ command will only show .ZIP files as potential targets.

    --
    Mainframe/UNIX Bit Twiddler and long time Windows/Linux Hobbyist.
    The Theorem Theorem: If If, Then Then.