0

I have a directory A, which contains a hundred sub-directories. Each one of these sub-directories contains a single directory.

How can I rename this single directory inside of each of the hundred directories to be the same name, say X? I have tried the mmv command, with no luck.

Any help would be appreciated!

1 Answer 1

0

Perhaps a better way, but:

Using bash and find

while IFS= read -r dir; do
    mv -- "$dir" "${dir%/*}/X"
done< <(find . -maxdepth 2 -mindepth 2 -type d)

DO a test run first with something like:

while IFS= read -r dir; do
    printf 'mv "%s" "%s"\n' "$dir" "${dir%/*}/X"
done< <(find . -maxdepth 2 -mindepth 2 -type d)

In short:

  • find
    • . current directory as base (Typically A in your case)
    • type d (directory) at minimum and maximum depth of 2
  • bash read $dir from find and move $dir to
    • ${dir%/*} remove last / and everything there after
      • /X append the new directory name.

Use for example find ./A ... if you reside one level below A etc.

Optionally add -v to mv (non-POSIX) to show actions taken.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.