I recently needed to create a number of files to test uploading. Copying and pasting multiple times seemed like to much work, so I wrote the following script to do the hard work for me.
create a file called create_files.sh and make is executable
$ touch create_files.sh
$ chmod 774 create_files.sh
Then open create_files.sh and paste the following script
The script takes two arguments, the number to start at, and the number to finish. This is useful for cases when you create files then discover you want more.
$ ls -la
drwxrwxr-x ./
drwxrwxr-x ../
-rwxrwxr-- create_files.sh*
-rw-rw-r-- file5.txt
-rw-rw-r-- file6.txt
-rw-rw-r-- file7.txt
-rw-rw-r-- file8.txt
-rw-rw-r-- file9.txt
I also created a script to copy files, as I also wanted to test uploading images and other file types
create a file called copy_files.sh and make is executable
$ touch copy_files.sh
$ chmod 774 copy_files.sh
Then open copy_files.sh and paste the following script
This script also takes two arguments, the file name to copy and the number of copies to make.
$ ls -la
drwxrwxr-x ./
drwxrwxr-x ../
-rwxrwxr-- copy_files.sh*
-rw-r--r-- test-image-1.jpg
-rw-r--r-- test-image-2.jpg
-rw-r--r-- test-image-3.jpg
-rw-r--r-- test-image.jpg
create a file called create_files.sh and make is executable
$ touch create_files.sh
$ chmod 774 create_files.sh
Then open create_files.sh and paste the following script
for i in $(eval echo {$1..$2})
do
echo "Test file $i" > file$i.txt
done
The script takes two arguments, the number to start at, and the number to finish. This is useful for cases when you create files then discover you want more.
Example
$ ./create_files.sh 5 9$ ls -la
drwxrwxr-x ./
drwxrwxr-x ../
-rwxrwxr-- create_files.sh*
-rw-rw-r-- file5.txt
-rw-rw-r-- file6.txt
-rw-rw-r-- file7.txt
-rw-rw-r-- file8.txt
-rw-rw-r-- file9.txt
I also created a script to copy files, as I also wanted to test uploading images and other file types
create a file called copy_files.sh and make is executable
$ touch copy_files.sh
$ chmod 774 copy_files.sh
Then open copy_files.sh and paste the following script
# Set period as delimiter
IFS='.'
read -a strarr <<< "$1"
for (( i=1; i&lt;=$2; i++ ))
do
cp "$1" "${strarr[0]}-${i}.${strarr[1]}"
done
This script also takes two arguments, the file name to copy and the number of copies to make.
Example
$ ./copy_files.sh test-image.jpg 3$ ls -la
drwxrwxr-x ./
drwxrwxr-x ../
-rwxrwxr-- copy_files.sh*
-rw-r--r-- test-image-1.jpg
-rw-r--r-- test-image-2.jpg
-rw-r--r-- test-image-3.jpg
-rw-r--r-- test-image.jpg
Comments
Post a Comment