Create multiple directories and files in Bash

0 minute read

Create many directories and subdirectories under every directory:

1mkdir dir_prefix{1..50}
2for dir in $(ls); do mkdir "$dir"/subdir; done;

Create file in within every folder and under subdirectories:

1find . -type d -exec touch {}/file.dat \;
2for dir in $(ls); do touch "$dir"/subdir/file.dat; done;

Find or remove files created some days ago:

1for f in $(find /directory -mtime +5); do rm $f; done