我想在linux中的项目的每个文件夹中创建一个index.html
文件。
index.html
应包含一些示例代码。
如何在单个命令中创建文件?
答案 0 :(得分:24)
find . -type d -exec touch {}/index.html \;
这将在index.html
及所有子目录中创建.
。
答案 1 :(得分:4)
cd /project_dir && find . -type d -exec touch \{\}/index.htm \;
HTH
答案 2 :(得分:0)
假设您在名为“projects.txt”的文件中有项目目录列表,则可以执行此操作(对于bash和zsh)
for i in $(cat projects.txt)
do
touch $i/index.html
done.
要创建projects.txt,您可以使用find
命令。您可以直接用cat
调用替换find
,但我认为将两个操作分开会更清楚。
答案 3 :(得分:0)
我知道这是一个老问题,但目前的答案都没有允许添加一些示例代码,这是我的解决方案:
import React, {Component} from 'react';
class Slider extends Component {
render() {
const myItems = [{source_image: '1.jpg'}, {source_image: '2.jpg'}, {source_image: '3.jpg'}];
return (
<div id="test">
{myItems.map(function (a) {
<img src={"images/"+a.source_image}/>
}
)}
</div>
);
}
}
export default Slider;
答案 4 :(得分:-1)
以下命令将在当前目录
中创建一个空的index.html文件touch index.html
如有必要,您需要进行适当的循环。