Solved

Linux search and replace string command

Posted on 2014-12-13
2
262 Views
Last Modified: 2014-12-13
I found this Linux command on the web to search and replace a string in files.  What does + do at the end of this command?

find . -type f  -exec sed -i 's/foo/bar/' {} +
0
Comment
Question by:rudy201
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
Zsolt Pribusz earned 500 total points
ID: 40497844
Here is a part from find manual:

       -exec command {} +
            This  variant  of the -exec option runs the specified command on
            the selected files, but the command line is built       by  appending
            each  selected file name at the end; the total number of invoca-
            tions of the command will       be  much  less       than  the  number  of
            matched  files.      The command line is built in much the same way
            that xargs builds its command lines.  Only one instance of  '{}'
            is  allowed  within the command.      The command is executed in the
            starting directory.

Link to find man page:
http://unixhelp.ed.ac.uk/CGI/man-cgi?find
Link to stream editor (sed) man page:
http://unixhelp.ed.ac.uk/CGI/man-cgi?sed
0
 
LVL 23

Expert Comment

by:savone
ID: 40497852
Try this:

find . -type f  -exec sed -i 's/foo/bar/' {} /;
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question