S
S
Sergey_Lomakin2020-10-22 10:40:18
linux
Sergey_Lomakin, 2020-10-22 10:40:18

How to create identical files in directories and subdirectories with a script?

#!/bin/bash
mkdir -p 201{0..7}/{01..12}
for a in *
do
    for b in *
    do
        touch file_1
        echo 'file 1' > file_1
        touch file_2
        echo 'file 2' > file_2
    done
done

Files should be created only in directories 201{0..7}/{01..12}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-10-22
@Sergey_Lomakin

I don’t understand why, but this is how you can do it in 2 lines:

mkdir -p 201{0..7}/{01..12}
for file in ~/201{0..7}/{01..12}*; do echo "file 1" > $file/file_1; echo "file 2" > $file/file_2; done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question