Skip to main content

Creating Multiple Files for Testing

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
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<=$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

Popular posts from this blog

Turning Off SSLv3 in Apache and IIS8, AKA Putting Down the Poodle That Bites

Poodle is a security vulnerability that has been found in SSLv3. Since SSL is over ten years old, and the only browsers that support it as the strongest version of encryption are IE6 and older, in my humble opinion it is safe to turn it off.  Let's start with the easy one, Linux, in particular CentOS. NB you will most likely need to be root or be part of the sudo group to make the following changes 1)     Open the ssl.config file with your favourite text editor. In Red Hat based distributions like CentOS you should find it in /etc/httpd/mods-available/ssl.conf 2)     Find the line starting with  SSLProtocol 3)     Change it to  SSLProtocol all -SSLv2 -SSLv3 This will allow all ciphers expect SSLv2 and SSLv3 4)     Save ssl.conf and exit your text editor 5)     Restart Apache by running the command service httpd restart 6) ...

Change the Colour of Emacs Shell Prompt and Font Highlighting

The project I'm currently working on is Linux based, and I just can’t get my head around vi no matter how hard I try. Fortunately I have root privileges, so Emacs to the rescue :) We are using CentOS so installing is as easy as sudo yum install emacs   One of the many reasons I really like Emacs is you can run a shell inside Emacs. Press Alt – x Type shell Press enter NB the Alt key in Emacs is often called the Meta key and the key combination above would be shortened to M – x This allows me to split the Emacs window and have the shell in the bottom half and what I working on in the top half, see the image below. To switch between the shell and what I’m working on I press M – O (that’s Alt and the letter O and not the number zero, Alt zero will unsplit the screen) If like me you’re running Emacs inside Putty the first thing you might notice is the shell prompt is in dark blue on a black background. Not only is this very difficult to read but it c...

Git: reset the stage after a bad merge

 When working in teams that use branches in git, eventually you're going to get a merge conflict. Most of the time this isn't to much of a problem you just work through the conflicts and commit the changes.  From time to time I mess up the merge and I want to just restart resolving the merge conflict again. Thankfully git make it easy if you haven't committed the changes. Just run the command git checkout -m <file name> That's it, you can now try and do the merge again as if you haven't resolved the latest conflict.