SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-09-22 11:28:23

crunchgargoyle
#! Member
From: London
Registered: 2011-09-06
Posts: 55

Delete (or whatever) everything except ...

I have this as an executable Bash script in my bin directory and have called it `rmx':

#!/bin/bash
shopt -s extglob
rm !($@)
shopt -u extglob

The extglob bits turn on/off respectively extended globbing, which is necessary to use "!" (as in, do the command on everything except the following) and "$@" (as in, what you enter after typing, in my case, 'rmx').

Naturally you can simply have extended globbing turned on and do this every time, instead:

rm !(file_to_delete)

I just find putting the script in bin marginally easier.

Of course this script is perfectly transferable.

Last edited by crunchgargoyle (2011-09-23 14:26:07)


I am error

Offline

Help fund CrunchBang, donate to the project!

#2 2011-09-22 13:47:28

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: Delete (or whatever) everything except ...

i have no knowledge of how shopt and extglob work, so i need to check that out. but i get the gist, and it is a nice little script.

Offline

#3 2011-09-22 14:06:49

crunchgargoyle
#! Member
From: London
Registered: 2011-09-06
Posts: 55

Re: Delete (or whatever) everything except ...

rhowaldt wrote:

i have no knowledge of how shopt and extglob work, so i need to check that out. but i get the gist, and it is a nice little script.

Thank you smile.

I just think of globbing in terms of wildcards.


I am error

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo