Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I am currently trying to figure out how to Copy and Paste files (more than one file) into the same directory using Terminal.

I am trying to create a script to create the same file. If there is a better way to do this, please let me know.

What I need to do with this script is to be able to create certain file types with specific sizes. Example: a image file (let's say a PNG file) that is 10MB in size and I need 4 of them. When running a command to create this file in Terminal it looks like:

mkfile 10m image.png

I created a script to repeat the command but it fails as it creates the same file and overwrites it.

Thank you,

K

share|improve this question
    
Please add your script to the question. Also: if you want to create four files, how should they be named? –  patrix Jul 23 '13 at 6:01
add comment

1 Answer

So, does it matter if the file is the same file?

ie: Let say there is a picture google.png

enter image description here

and you want it to copied into the same dir 4 times.

as an in that directory you would have google.png google 2.png google 3.png google 4.png?

If thats what you want:

for i in {1..4}
  do
     cp google.png "google$i.png"
  done

But if you want the "images" files to be different, and they are going to be gibrish files, but 10m in size exactly

you wanna do something like

for i in {1..5}
   do
      dd if=/dev/random of="yourfilename$i.test" bs=12428800 count=1
   done

This will make four files that are 10m in size filled with bunch of zeros.

Comment and let me know what you really want and I can go back and redo this.

It would help if you posted your script that fails so I can see what youre trying to do.

EDIT:

Changed the in device from /dev/zero to /dev/random to generate random file content.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.