I have a main directory with 100 .mp4 files. I also have a set of sub-directories that goes dir_1, dir_2, dir_3
, etc, up to 100. What I want do is to loop through the main directory and distribute the .mp4 files to all the subfolders, each having only one. Then, there should be two loops or one loop with two variables, whichever one is possible. This is approximately what I'm trying to achieve in a single line of code.
for file in *.mp4 & x in {1..100}; do mv $file dir_$x; done
x=$((x+1))
. – Quasímodo Dec 10 '21 at 20:55x=\
expr $x + 1`` – David G. Dec 11 '21 at 14:41cmd
) in *sh shells been deprecated? – ilkkachu Dec 12 '21 at 00:12expr
for arithmetic.x=$((x + 1))
(as well as, I think,: $((x++))
) is POSIX-compliant. – chepner Dec 12 '21 at 19:04