Convert all image links in a website directory (on

2019-09-06 17:16发布

My task is to take a directory of website files, including html, css, and non-text image files, and change all image paths from relative paths to a universal cdn path. This is on a mac.

My starting point is something like this:

sed -i '' 's/old_link/new_link/g' *

but I want it to act only on css,html files, and to recurse through any subdirectories.

thanks

1条回答
一纸荒年 Trace。
2楼-- · 2019-09-06 17:40

Try using find. Soemthing like:

find . -name *css -exec sed -i '' 's/old_link/new_link/g' {} ';'

will find all the css files in your current directory and below it and pass each one to sed. The {} stand in for the name (and location) of each file that find finds. Don't omit the quote marks around the final ;

Then repeat for html files.

As ever, for the finer points of syntax consult man, or google for the find documentation.

查看更多
登录 后发表回答