bash-3.2$ sed -i.bakkk -e "s#/sa/#/he/#g" .*
sed: .: in-place editing only works for regular files
I try to replace every /sa/ with /he/ in every dot-file in a folder. How can I get it working?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
find -type fto find only files matching the name.*and exclude the directories.and...-maxdepth 1preventsfindfrom recursing into subdirectories. You can then use-execto execute thesedcommand, using a{}placeholder to tellfindwhere the file names should go.Using
-execis preferable over using backticks orxargsas it’ll work even on weird file names containing spaces or even newlines—yes,"foo bar\nfile"is a valid file name. An honorable mention goes tofind -print0 | xargs -0which is equally safe. It’s a little more verbose, though, and less flexible since it only works for commands where the file names go at the end (which is, admittedly, 99% of them).