Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-16-2010, 04:13 PM   #1
Registered: Jun 2002
Posts: 411

Rep: Reputation: 30
please help with bash find / -name "*.sized.jpg" -exec rm -f {} ;

Thanks in advance for your help. Could someone correct my bash shell command?

I am trying to delete some unneeded files that contain ".sized.jpg" in their name. The files are stored in a number of directories in my home directory. I searched the web and found a promising approach that suggests:

find / -name core -exec rm -f {} ;
I tried to adapt the command to my purpose using the following bash shell command:
find /home/user/web_photos/ -name "*.sized.jpg" -exec rm -f {} ;
I get the error message: find: missing argument to `-exec'

Last edited by rioguia; 01-16-2010 at 04:14 PM. Reason: tags
Old 01-16-2010, 04:20 PM   #2
LQ Guru
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
You need a backslash "\" just before the final semicolon, so that the find command realizes that that is the end of the arguments:

find /home/user/web_photos/ -name "*.sized.jpg" -exec rm -f {} \;
Old 01-16-2010, 04:21 PM   #3
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,874

Rep: Reputation: 554Reputation: 554Reputation: 554Reputation: 554Reputation: 554Reputation: 554
find /home/user/web_photos/ -name "*.sized.jpg" -exec rm -f {} \;
Notice the '\'.
Old 01-16-2010, 04:28 PM   #4
Registered: Jun 2002
Posts: 411

Original Poster
Rep: Reputation: 30
Thanks that solved it!

Thank you both. That was perfect!
Old 01-16-2010, 04:48 PM   #5
Sergei Steshenko
Senior Member
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Originally Posted by rioguia View Post
Thank you both. That was perfect!
Here are two excerpts from 'man find' with line numbers:

    705        -exec command ;
    706               Execute command; true if 0 status is  returned.   All  following
    707               arguments to find are taken to be arguments to the command until
    708               an argument consisting of `;' is encountered.  The  string  `{}'
    709               is  replaced by the current file name being processed everywhere
    710               it occurs in the arguments to the command, not just in arguments
    711               where  it  is alone, as in some versions of find.  Both of these
    712               constructions might need to be escaped (with a `\') or quoted to
    713               protect them from expansion by the shell.  See the EXAMPLES sec-
    714               tion for examples of the use of the -exec option.  The specified
    715               command  is run once for each matched file.  The command is exe-
    716               cuted in the starting directory.   There are  unavoidable  secu-
    717               rity  problems  surrounding  use of the -exec action; you should
    718               use the -execdir option instead.
   1334        Find files named core in or below the directory /tmp and  delete  them,
   1335        processing  filenames  in  such a way that file or directory names con-
   1336        taining single or double quotes, spaces or newlines are correctly  han-
   1337        dled.   The  -name  test  comes before the -type test in order to avoid
   1338        having to call stat(2) on every file.
   1341        find . -type f -exec file '{}' \;


bash, delete, files, find, multiple

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
fail to start xterm: "could not exec /usr/OSE/bash: No such file or directory" freeindy Linux - General 3 11-28-2008 01:22 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
No UTMPX entry, You must EXEC "login" for the lowest "shell" ooihc Solaris / OpenSolaris 7 03-12-2007 03:09 PM
does "find -exec" not recognize built-in command? yaru22 Linux - General 1 06-30-2006 11:35 AM
Several "find -exec" and "find | xargs" questions thanhvn Programming 4 12-02-2005 02:04 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:50 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration