user1875841 user1875841 - 1 year ago 107
Linux Question

How to prefix folders and files within?

I'm stuck looking for a one-liner to add a prefix to all subfolder names and file names in a directory

eg "AAA" in the examples below




I've tried using xargs and find, but can't get them to go recursively through the subdirectories and their contents. Any suggestions?

Answer Source

You could use something like that

find . -mindepth 1 | sort -r | xargs -l -I {} bash -c 'mv $1 ${1%/*}/AAA${1##*/}' _ {}

Tested with your folder structure, executed from the root (same as AAAfile.txt).