LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-08-2010, 05:09 AM   #1
kuldeep.k
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Rep: Reputation: 0
Want to run a command per file from the output of "find" command


I want to scan a particular directory recursively and run a particular command with each file as input. For this I am using "find /dir/path".
I dont want to write any long script containing loop on the output of "find". I want a single command which will allow me to run a command on each file of the "find" command output.

Thank you .
 
Old 09-08-2010, 05:13 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Hi,

You can use
Code:
find / -name foo -exec /bin/rm {} \;
Kind regards

Last edited by repo; 09-08-2010 at 05:15 AM.
 
Old 09-08-2010, 05:14 AM   #3
lurker79
Member
 
Registered: Jan 2005
Location: UK
Posts: 55

Rep: Reputation: 16
find has a -exec option which allows you to run commands on the files matching the pattern you have given find e.g. to run "ls -l" on those files you could run something like

find / -name "foo*" -exec ls -l {} \;

to get it to prompt to run the command you can use -ok
 
Old 09-08-2010, 05:20 AM   #4
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
Another option is | xargs. Try to distinguish between -exec and xargs.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to send the output of a command in a file defined by a eval $"$var1" toordog Programming 3 07-07-2010 04:26 PM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
Not able to Run/find "configure" command aaryan72 Linux - Newbie 4 09-10-2005 11:16 AM
Help,I can't find my USB mouse when I run "kudzu" command in RH9. aeolus Red Hat 0 03-27-2004 09:14 PM
qmail: strange output of "file" command slowleak Linux - Security 1 08-10-2001 10:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:45 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration