文章目录
批量创建空文件
创建含内容文件
按日期创建日志文件 根据文件中的列内容,创建文件
批量创建空文件
touch命令批量创建空文件
touch file{ 1 .. 10 } .txt
循环结构创建
#!/bin/bash
for i in { 1 .. 10 } ;
do touch "file$i .txt" ;
done
创建含内容文件
echo重定向
#!/bin/bash
for i in { 1 .. 5 } ;
do echo "hello world" > "file$i .log" ;
done
多行内容写入
#!/bin/bash
for i in { 1 .. 5 } ;
do printf "第一行内容\n 第二行内容\n " $i > "file$i .txt" ;
done
按日期创建日志文件
#!/bin/bash
for day in { 1 .. 30 } ; do
touch "log$( date +%Y-%m) -$( printf "%02d" $day) .log"
done
根据文件中的列内容,创建文件
一行只有一列内容
#!/bin/bash
while read name;
do touch "$name " ;
done < list.txt
一行有多列内容
#!/bin/bash
column_index = 1
while IFS = read -r line; do
columns = ( $line )
for column_value in "${columns[ @] } " ; do
touch "$column_value .log" ;
done
column_index = 1
done < list.txt
echo "处理完成!"