Skip to main content

Append dirname to all filenames in directory and subdirectories

Took a while to find it out:

find -type f -execdir bash -c 'var=$(basename "$PWD"); mv -- "$1" "${var%-*}_$(cut -c 3- < <(echo ${1}))"' execbash {} \;

 

Also useful: Copy all files of type jpg to one directory:

find . -type f -name '*.jpg'| xargs cp -t /media/ana/Daten/jpgAlle

This has probably to be repeated with file ending JPG and jpeg