Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Commands terminated with the same char

How can I fix the follow line:

for line in $(cat /root/files_to_search); do find /opt/ -iname $line -exec rm {} >> files_founded.txt ; done

The problem is that the commands of for and -exec end with a semicolon, the for command has this statement

for i in something; do command ; done (do terminate with ;)

and find statment with -exec

find /path/ -name somestring -exec command \; (-exec also finish with ;)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You don't even need to use -exec echo {} since that is default action in find. You can use this for loop:

while IFS= read -r line; do
    find /opt/ -iname "$line"
done < /root/files_to_search >> files_founded.txt

There is no need to use for line in $(cat ...) either as you can read from the input using < file

See BASH FAQ on reading a file line by line

If you must use -exec in find then use:

while IFS= read -r line; do
    find /opt/ -iname "$line" -exec rm {} \;
done < /root/files_to_search >> files_founded.txt
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!