From the Parent_dir
:
for d in */*/; do f=${d/\//_}; touch -- "$d"/"${f::-1}.txt"; done
Note that touch
will change the timestamp of any existing file.
You can do a dry-run first with replacing touch
with echo
:
for d in */*/; do f=${d/\//_}; echo -- "$d"/"${f::-1}.txt"; done
for d in */*/
lets us iterating over the directories two levels deep
f=${d/\//_}
replaces first directory separator /
with _
and save the output as variable f
"$d"/"${f::-1}.txt"
expands to the directory name, followed by the desired filename; ${f::-1}
strips off the last /
from variable f
Note that, as the directory separator /
is present with variable d
, the /
in "$d"/"${f::-1}.txt"
is redundant; as almost all systems take //
as single /
, this should not be a problem. Alternately, you can drip /
:
for d in */*/; do f=${d/\//_}; touch -- "${d}${f::-1}.txt"; done
name
anddate
placeholders as well? – Hölderlin Apr 09 '17 at 02:57