LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 01-16-2010, 03:13 PM   #1
rioguia
Member
 
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:

Code:
find / -name core -exec rm -f {} ;
I tried to adapt the command to my purpose using the following bash shell command:
Code:
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 03:14 PM. Reason: tags
 
Old 01-16-2010, 03:20 PM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

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

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

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

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

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

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

Code:
    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.
Code:
   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.
   1339
   1340
   1341        find . -type f -exec file '{}' \;
 
  


Reply

Tags
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 12:22 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
No UTMPX entry, You must EXEC "login" for the lowest "shell" ooihc Solaris / OpenSolaris 7 03-12-2007 02:09 PM
does "find -exec" not recognize built-in command? yaru22 Linux - General 1 06-30-2006 10:35 AM
Several "find -exec" and "find | xargs" questions thanhvn Programming 4 12-02-2005 01:04 PM


All times are GMT -5. The time now is 05:56 PM.

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