-2

I have a simple problem and I need your help.

I want the files in a specific folder, conditionally '1.txt', '2.txt', 'and three.txt' whose sizes are also conditional 1kb, 3mb, 55kb. There are thousands of files that I can do this manually. I want to insert all the above mentioned files in dd command, to be produced with the same name and size.

find . -name "*.txt" -print | while IFS= read -r fn
do
        echo "$fn"
done
size=$(ls -nl *.txt | awk '{print $5}')
for size in $size
do
        echo "$size"
done

exec dd if=/dev/random of=$fn bs=$size count=1"

I want something like that, thanks in advance.

1 Answers1

0

At first, you could join these two loops into one.

Here is one possible solution using find to get filename and sizes, the echo command is only for debbuging.

find . -type f -name '*.txt' -printf '%f %s\n' | 
while read file size; do
    echo dd if=/dev/random of=/tmp/$file bs=$size count=1
done