Awesome Shell Power: stupid z trick

2007-07-17

Say you want to move all the files in the current directory down into a new directory called “awesome”.

Instead of:

mkdir awesome
mv * awesome

which is likely to complain: “mv: rename awesome to awesome/awesome: Invalid argument” (though it does in fact work), you might try:

mkdir z
mv *
mv z awesome

This “works” when the newly created directory, called “z”, comes at the end of the list that “*” expands to. You weren’t in the habit of creating files beginning with z were you?

About these ads

10 Responses to “Awesome Shell Power: stupid z trick”

  1. glorkspangle Says:

    That is twisted.

  2. drj11 Says:

    In so many ways.

  3. ewx Says:

    I often do this:

    mkdir _ ; mv * _ ; rm -rf _ &

    …to reset a particular flavor of cache directory quickly. GNU mv at least moves everything but _ and prints a warning which I ignore.

  4. drj11 Says:

    _? _!? That requires pressing Shift! Are you insane!

    Nice trick I mean. I use the mv somewhere else and asyncronously rm it trick for directories containing build products sometimes.

  5. ewx Says:

    Mmm, yes, that one could be optimized a bit l-)

  6. glorkspangle Says:

    If pressing shift slows you down, practise more. Besides, we’re already pressing shift a lot in shell: “!$&*()~|><

  7. glorkspangle Says:

    In fact, sometimes I wonder if shell would be better written with shift lock on. But ;\’`

  8. neilbowers Says:

    Instead of z, you could create a directory called }
    which puts it at the end of the sort order:

    mkdir }
    mv *

    And how often have you seen or used } in a directory
    or file name?

    Ok, it does mean you have to press the shift key.

  9. glorkspangle Says:

    You’re both barking mad.

  10. drj11 Says:

    > mkdir }

    Hahahahaha! We’re clearly both barking mad. I did actually spot that } was above z on the ascii(7) chart, but I thought “that’ll never work, because it must be a shell meta-character”. Naturally I didn’t try it. Shell lexical analysis will never fail to disturb me.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: