Re: Reverse Wildcarding

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Ed Skinner
Date:  
To: plug-discuss
Subject: Re: Reverse Wildcarding
With "rm" and other destructive commands, I usually work out a shell command
like this a little at a time so that I'm sure it's gonna do what I want, not
what it wants. In this case I'd do the "ls | grep -v .jpg" and hand-check to
be sure I wasn't left with anything good. Then, and only then, would I do the
whole thing.

     Quick story: When employed "many years ago" at a company that has since 
moved many times, I used to keep my resume in a directory named .private with 
permissions 700 so that, at least in theory I was the only one who could go 
in there, and the "." at the front of the name hid it even more so.
     One day I was doing some system maintenance (as root via "su -" instead 
of the slightly less dangerous "su"). I had just accepted another job 
elsewhere but hadn't announced my departure. Anyway, I decided I had better 
remove the ~/.private directory and its contents so, in a momentary lapse of 
good judgement, I typed "cd ; rm -rf .*" hoping to save myself the trouble of 
typing out ".private". Well, the system chugged along for about 30 seconds 
before the guy in the next cubicle said to no one in particular, "Is the 
system down?" As you may have recognized, ".*" matched ".." which means "go 
up one level" and, since I was the root user, my "cd" had taken me to "/root" 
and, in the wink of an eye, all the files on the system were gone.
     Good thing I had another job already lined up...
     Use of the little back-quote characters will put you into the same very 
powerful, and very dangerous area as my very bad use of a wildcard. They're 
handy little gadgets when used well.




On Tuesday 15 June 2004 17:37, Michael Havens wrote:
> On Tuesday 15 June 2004 17:11, Ed Skinner wrote:
> > rm `ls | grep -v .jpg`
> >
> > Note the back single quotes are on the key next to the "1" character.
> > When you put these around some commands, they are executed and their
> > stdout is captured, and that stdout is then dropped in, in place of the
> > back quoted expression and the outer "rm ..." is then executed.
>
> I don't know why but this command excited me! I even wrote it down as:
> what is in the `` is executed first and becomes the argument for the other
> command.


--
Ed Skinner, , http://www.flat5.net/

---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss