LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-06-2020, 01:48 AM   #1
BudiKusasi
Member
 
Registered: Apr 2017
Distribution: Artix
Posts: 345

Rep: Reputation: 15
speed consideration or evaluation on find -exec bash -c....


How slower find -exec repetitively calling bash -c '' for invoking a function
inside, compare to pipe repeatedly

such this
https://stackoverflow.com/questions/...g-find-and-sed
all work correctly, so this ask all just on speed evaluation or comparison

(1st answer suggest function inside script to be invoked by -exec
2nd answer suggest solution by some core utils pipings )
 
Old 09-06-2020, 03:12 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Doesn't find have an -exec option where you can collect all find results, then pass them to a command all at once?
Pipes and other sub-shells do have some overhead. If you cannot avoid this, consider using dash (or some other lightweight shell) instead of bash.
In the end, you will have to test which is faster.
 
Old 09-06-2020, 04:31 AM   #3
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,836

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
The fork-intensive=slow
Code:
find . -name '*_test.rb' -exec bash -c 'echo mv "$0" "${0/test.rb/spec.rb}"' {} \;
can be made faster if you terminate the -exec with a +
The execed command must be able to process multiple arguments; a bash script must cycle through the args by means of a loop; a for loop takes the arg list by default.
The following multi-liner demonstrates it
Code:
find . -name '*_test.rb' -exec /bin/sh -c '
for arg
do
  echo mv "$arg" "${arg/test.rb/spec.rb}"
done
' mv_script {} +
Note that "mv_script" is passed to $0; so the file names are passed to the default arg list "${@}" i.e. "$1" "$2" ...
 
2 members found this post helpful.
Old 09-07-2020, 09:03 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
Have a look at 'find ...-exec ...+' vs 'find .... xargs' eg https://unix.stackexchange.com/quest...-one-to-choose

Some xargs examples https://javarevisited.blogspot.com/2...inux-unix.html
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is PATH statement a security consideration? ksclps Linux - Security 2 10-16-2007 12:08 PM
LXer: ISO won't fast-track MS OOXML consideration LXer Syndicated Linux News 0 02-10-2007 07:21 PM
Add/remove function idea<serious consideration> Digital Surgeon Linux - General 1 11-24-2006 07:38 PM
Taking brands into consideration when buying a graphics card Michael_aust Linux - Hardware 1 12-28-2005 08:21 AM
The fastest reaction in auto-updates taking into consideration network security bugs? immer Linux - Distributions 1 10-23-2004 03:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:26 AM.

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