views:

124

answers:

3

How do I delete all files in a folder that has an apostrophe?

for example:

Baird/'s Tunnel.jpg

Bach/'s Birds.jpg

This isn//'t good.png

I would like all those files deleted but anything that doesn't have an apostrophe to remain intact, like:

this is good.jpg donotdelete.png

+2  A: 

In sh you could do

rm *\'*
disown
This won't work for the examples given, since they have spaces. Better: for fn in *\'*; do rm "$fn"; done
Charles Stewart
+1  A: 

You can use the find command:

find . -name "*'*" -delete

As @Bryan pointed in his comment, this will delete all files in the current directory and all subdirectories. If you don't want to descend the directories use:

find . -name "*'*" -maxdepth 1 -delete

which makes find stay in the current directory.

Gregory Pakosz
of course, without any other arguments this will delete all files in the current directory *and* all subdirectories.
Bryan Oakley
@Bryan: good one, thank you
Gregory Pakosz
That should be `-maxdepth 1` (`-depth` is for depth-first processing and doesn't take an argument)
Dennis Williamson
@Dennis for some reason, on my mac `-depth 1` behaves like `-maxdepth 1`
Gregory Pakosz
A: 

GNU find

find /path/ -type f -name "*[']*" -exec rm {} +;
ghostdog74