Solved

Linux search and replace string command

Posted on 2014-12-13
2
247 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
2 Comments
 
LVL 4

Accepted Solution

by:
Zsolt Pribusz earned 500 total points
Comment Utility
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
Comment Utility
Try this:

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What is ISQL? 6 99
Notice: Undefined variable 5 53
Linux  Script File Attributes 5 11
Linux as a middle box 7 0
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). …
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now