Solved

Linux search and replace string command

Posted on 2014-12-13
2
254 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
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

Suggested Solutions

Title # Comments Views Activity
wifi not working on Raspberry Pi 3? 2 53
add some character at the end of line in vi 7 78
Help on running oracle SQL script in linux 3 48
linux redhat 7.2 10 70
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

776 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