Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a lot of directory where there are hundreds of files.

In every directory there are pairs of my_file-01.jpg and my_file-€01.jpg

I want to remove every file that contains € sign in its title: how to do that?

share|improve this question
add comment

3 Answers

find does the job:

find . -iname "*€*" -delete gets rid of all files whose name matches "", be careful, find goes into subdirectories as well, if you don't want that you have to tune the find params a little

share|improve this answer
    
I'll upvote yours if you'll upvote mine ;-) –  wzzrd Oct 21 '10 at 12:30
1  
mine is better cause it's case insensitive :P –  tante Oct 21 '10 at 12:34
3  
Ok, right then, wiseguy, put up your dukes. Show me a capital '€' then. –  wzzrd Oct 21 '10 at 14:27
    
Just for information : you can use -maxdepth 1 with find to use only the current directory –  Elenaher Oct 21 '10 at 15:07
    
@Elenaher: But if it is only about the current directory, you could simply use rm *€* –  Marcel Stimberg Oct 21 '10 at 15:43
show 4 more comments

Something along the lines of

find -name '*€*' -delete

You might want to try this first, to see if the correct files would be delete:

find -name '*€*' -ls
share|improve this answer
    
That should be '*€*', right? –  Marcel Stimberg Oct 21 '10 at 15:34
    
@Marcel: yes, it should. I also used double quotes (but it doesn't really matter in this situation) –  dag729 Oct 21 '10 at 15:45
    
@Marcel: True and fixed. –  wzzrd Oct 22 '10 at 7:22
add comment

In each example, the first command lists files whose name contain a and the second command deletes them.

Using GNU find (as found on Linux):

find -name '*€*' -ls
find -name '*€*' -delete

Add -type f after -name '*€*' if you only want to match regular files and not directories as well.

Using find, relying only on POSIX features:

find . -name '*€*' -print
find . -name '*€*' -exec rm {} +

Add -type f after -name '*€*' if you only want to match regular files and not directories as well.

Using bash 4 or zsh:

echo **/*€*
rm **/*€*

Under zsh only, **/*€*(.) restricts the matching to regular files, excluding directories.


If you only want to list files that have in their names and such that an identical file without the exists, here are standard find and zsh solutions.

find . -name '*€*' -type f -exec sh -c 'cmp -s -- "$0" "$(printf "%s" "$0" | tr -d "€")"' {} \; -print
find . -name '*€*' -type f -exec bash -c 'cmp -s -- "$0" "${0//€/}")"' {} \; -print
echo **/*€*(.e\''cmp -s -- $REPLY ${REPLY//€/}'\')
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.