I have tried the following:
rm *.!(zip) #will not get files with no extension or with multiple dots in
them
rm *!(zip) #deletes all files, including zip files
rm *.[!zip] #appears to not get files ending with .z, more than one dot,
and no extensions
rm *[!zip] #same as above, except will get files with no extension
rm *![zip] #rm: *![zip]: No such file or directory
Am I close? Is there even a way? I think I understand the behavior of all of
the above except for the second one. Can someone explain? Thanks for your
time. System info:
uname -a
OSF1 machinename V4.0 878 alpha
(using ksh)
rm `find * -type d -prune -o -type f ! -name '*.zip'`
If you don't have any subdirectories you can leave out the '-type d -prune
-o' part of the command.
--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Since you want to do this in CURRENT directory, you can simply use grep,
something like:
rm `ls | grep -v '.zip'`
(or rm `ls | grep -v '.zip$'`)
> Is there a way with a simple rm command to delete all files in the current
> directory except those that end with zip?
ls | grep -v '\.zip$' | xargs rm
Dale.
Yes.
rm !(*.zip)
or if you want to include dotfiles,
rm !(*.zip) .!(*.zip)
John
--
John DuBois spc...@armory.com. KC6QKZ http://www.armory.com./~spcecdt/
/bin/rm -f *.[^zip]*
Eric Gorely wrote:
Is there a way with a simple rm command to delete all files in the current
directory except those that end with zip?
I have tried the following:
rm *.!(zip) #will not get files with no extension or with multiple dots in
them
rm *!(zip) #deletes all files, including zip files
rm *.[!zip] #appears to not get files ending with .z, more than one dot,
and no extensions
rm *[!zip] #same as above, except will get files with no extension
rm *![zip] #rm: *![zip]: No such file or directory
Am I close? Is there even a way? I think I understand the behavior of all of
the above except for the second one. Can someone explain? Thanks for your
time. System info:
uname -a
OSF1 machinename V4.0 878 alpha
(using ksh)
-- _____________________________________________________________________________ |___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___| |_|___|___|___|___|___|___|Greg Hunter |___|___|___|___|___|___|_| |_|___|___|___|___|___|___|jghu...@ix.netcom.com |___|___|___|___|___|___|_| |___|___|___|___|___|___|_|_______________________|_|___|___|___|___|___|___| |_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|_| |___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
ls *.[!z][!i][!p]
if it works
replace ls with rm
--
=-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
al aab, seders moderator sed u soon
it is not zat we do not see the s o l u t i o n
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
I have not tested the above, but I believe that this will not work
if there is no period or if there is a zero, one, two, or a 4+
character extension.
These filenames wouldn't get found:
myfile
myfile.
myfile.z
myfile.zi
myfile.zip1
myfile.more2
.
.
.
etc.
Others have posted good solutions using find.
Chuck Demas
Needham, Mass.
[posted and emailed]
--
Eat Healthy | _ _ | Nothing would be done at all,
Stay Fit | @ @ | If a man waited to do it so well,
Die Anyway | v | That no one could find fault with it.
de...@tiac.net | \___/ | http://www.tiac.net/users/demas
It will also leave things like *.zig, *.zap, and *.pip.
#!/bin/ksh
for each in `ls -1 | grep -v "zip file extension eg .Z"`
do echo $each
done
-----
if the above script lists all the file but your zipped files, replace the echo
with \rm -f.
Sriram
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
ls -l !(*zip)
or
rm !(*zip)
Regards,
Steve.
In article <S3TE2.83$p4.6536@burlma1-snr2>
-----------== Posted via Deja News, The Discussion Network ==----------
sriram
In article <7c2j5j$3c$1...@remarQ.com>,
-----------== Posted via Deja News, The Discussion Network ==----------
Hmm? No, this won't recurse through any directories.
John
Sriram
In article <7c5g2o$5u2$1...@remarQ.com>,
spc...@deeptht.armory.com. (John DuBois) wrote:
> In article <7c40bl$cd$1...@nnrp1.dejanews.com>, <ma...@my-dejanews.com> wrote:
> >Realize this will might recurse through directories .
>
> Hmm? No, this won't recurse through any directories.
>
> John
>
> >sriram
> >
> >
> >In article <7c2j5j$3c$1...@remarQ.com>,
> > spc...@deeptht.armory.com. (John DuBois) wrote:
> >> Again:
> >>
> >> rm !(*.zip)
> >>
> >> or if you want to include dotfiles,
> >>
> >> rm !(*.zip) .!(*.zip)
> >>
> >> John
> --
> John DuBois spc...@armory.com. KC6QKZ
http://www.armory.com./~spcecdt/
>
-----------== Posted via Deja News, The Discussion Network ==----------
Yes, you need to give ls the '-d' option to make it act on directories the same
as it does on files.
>and thanks for the help on the ksh prompt stuff.
You're welcome.
John
sri...@eng.ua.edu wrote:
> a ls command of the same syntax recursed thorugh my dir.
> and thanks for the help on the ksh prompt stuff.
>
I got into this late and didn't see the original posting, but I would
like to respond to the above code specifically, without reference to the
original stuff other than to say, I assume we want to keep *zip files
and delete ALL other regular files, from the current directory down. We
will not remove any directories, even if they are empty.
First, simplify: rm has an option, -i that makes it interactive. It
will ask, for each file it is given, whether you want to remove it. An
answer beginning with y is required, anything else skips.
Second, understand find: -name '*' will limit to all names not
beginning with a dot. But we could also limit the find to reporting
about regular files only with '-type f', since we want to skip
directories.
There are possibly a lot of files to find doing this, so 'xargs' is
added to the needed tools:
find . -name '*' -type f -print | grep '\.zip$' | xargs rm -i
Coupla other notes: directory names dot and dot_slash are the same so
go with the simpler; the grep pattern without the dollar sign would save
files like 'the.zipper'.
Cheers,
--
Bob McGowan
bob dot mcgowan at usa dot net
Even better, because the '-name' parameter takes file patterns we can
drop the grep entirely:
find . -name '*.zip' -type f -print | xargs rm -i
Or interactively delete everything except "*.zip" files:
find . \! -name '*.zip' -type f -print | xargs rm -i
Because this includes ".*" files now, to avoid these we could add:
find . -name '*' \! -name '*.zip' -type f -print | xargs rm -i
or
find . \! -name '.*' \! -name '*.zip' -type f -print | xargs rm -i
(The first works, because "*" by default skips ".*" files, but
for the sake of clarity I'd prefer the second explicit version.)
Please note, that find's '-name' parameter takes file patterns
in contrast to grep's regular expressions!
Regards,
Martin
--
Martin Ramsch <m.ra...@computer.org> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26 E4 EC 80 58 7B 31 3A D7
>On Mon, 15 Mar 1999 22:07:06 -0800, Bob McGowan <rmcg...@jps.net> wrote:
>> find . -name '*' -type f -print | grep '\.zip$' | xargs rm -i
> find . -name '*.zip' -type f -print | xargs rm -i
Has anyone bothered to try one of these suggestions that end with
"... | xargs rm -i"? They don't work! When rm prompts for confirmation
it reads the response from stdin - which is the pipe from "find". If
xargs has already read everything from the pipe, rm will get end-of-file.
If not, rm will read part of the list of filenames as if it was a y/n
response.
>Or interactively delete everything except "*.zip" files:
> find . \! -name '*.zip' -type f -print | xargs rm -i
>Because this includes ".*" files now, to avoid these we could add:
> find . -name '*' \! -name '*.zip' -type f -print | xargs rm -i
>or
> find . \! -name '.*' \! -name '*.zip' -type f -print | xargs rm -i
> (The first works, because "*" by default skips ".*" files,
Well, it does on some systems, but only if they have a broken version
of find. The POSIX.2 standard says that -name "*" matches files
beginning with dot. This is also the historical behaviour, but
unfortunately some vendors misinterpreted the POSIX.2 spec.
--
Geoff Clare g...@unisoft.com
UniSoft Limited, London, England. g...@root.co.uk
would this not be easyer?
rm -i `find .|grep -v .zip`
--
Check Out: http://www.users.zetnet.co.uk/james/
E-Mail: mis...@zetnet.co.uk
Pff, I should have thought of that - and you're right: in this case I
didn't test the commands myself, but only did cut & paste, as my focus
only was on showing some of the possibilities of "find" ...
Sorry for the confusion I might have caused!
Kind regards,
Missed the start of this thread; but there is an easier way to delete
all but a certain name of file:
$ ksh
$ rm -i !(*.zip)
dave
--
David 'I just get these headaches' Lodge, da...@muspellheim.demon.co.uk
"Dear God above (if you exist), Hope you see the funny side to this,
Now don't get cross - don't bite your nails,
Oh, Son of Man your mission's failed."
- Skyclad "The Sinful Ensemble"