0
votes

I need a bash script that will

1) create 10 folders named from 1 to 10

2) create a .txt file with a name that corresponds to the current folder (e.g. 1 folder should have a 1.txt file in it)

3) Each .txt file should contain current date and time inside it

I have written a bash script that is supposed to do the first two tasks, but for some reason I have an error. I have no idea how to implement the third point. Please help!

for i in $(seq 1 10); do 
   mkdir "$i" 
done
for dir in $(find . -maxdepth 1 -type d) do
   touch "$dir"/name_date.txt
done
1
for i in $(seq 1 10); do mkdir $i && date > $i/$i.txt; doneRobᵩ
date=$(stat -c ""%x"" FILENAME) echo ${date\%%.*}Boschko

1 Answers

1
votes

Inspired by @Rob answer :

for i in {1..10}; do mkdir $i && date > $i/$i.txt; done