简体   繁体   中英

Bash script to create and delete a file N times

一个简单的问题 - 是否有一个快速的 bash 脚本或单行脚本会重复创建一个随机名称(不需要内容)的文件,然后删除它刚刚创建的文件?

You can use mktemp that should give almost a random filename and execute it count times:

seq 10|xargs -l sh -c 'rm "$(mktemp)"'

Alternatively you could use $RANDOM :

seq 10|xargs -l sh -c 'a=$RANDOM;touch $a;rm $a'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM