#!/bin/bash # settings ; PLEASE ADAPT LOCAL_FOLDER=/Users/XXX/Desktop/CPU SUBJ_PATTERN=CPU* SUBFOLDERS="functional onsets structural" RAWFOLDER=raw # Note: the SUBFOLDERS variable can be easily adapted to create # several levels of folders: # SUBFOLDERS="functional functional/raw functional/prepro ..." # for every folder found (matching the pattern) find $LOCAL_FOLDER -type d -mindepth 1 -maxdepth 1 -name "$SUBJ_PATTERN" | while read subject_folder ; do # make sure all subfolders we need exist for sub in $SUBFOLDERS ; do mkdir $subject_folder/$sub 2>/dev/null done # rename original folder, if existent, to raw find $subject_folder -type d -mindepth 1 -maxdepth 1 -name "$SUBJ_PATTERN" -exec mv {} $RAWFOLDER \; done