Shell script to generate random files using RANDOM variable
Posted in Tempfile
#!/bin/bash # Shell script to generate random file method # 1 # # This is a free shell script under GNU GPL version 2.0 or above # # Copyright (C) 2005 nixCraft # # Feedback/comment/suggestions : http://cyberciti.biz/fb/ echo "List of temporary files : " for i in 1 2 3 4 5 do FILE="/tmp/$(basename $0).$RANDOM.txt" echo $FILE # show file name > $FILE # create files done
Download - Email this to a friend - Printable version
Is your site working? Monitor Your Web Site 24/7. Get SMS alerts on server downtime! Free 30-day trial including 20 SMS!
Related Other Helpful Shell Scripts:
- Script to update user password in batch mode using pwgen and chpasswd
- Shell Script To Delete Files In The First Directory Which Are Similarly Named In The Second Directory
- Shell Script To Count Number Of Files In Each Subdirectories
- Shell script to find the number of files present in the current directory without using WC command
- Shell Script To Provide ls -l in output in customized format
Discussion on This Shell Script:
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: bash shell script, for loop, free shell, gnu gpl version, loop method, random file, random files, shell loops, temporary files ~ Last updated on: April 10, 2008


This is bad practice. A much better way would be to use $$, which is the process ID. In the loop above I would create a filename of “/tmp/$(basename $0).$$.txt”