Skip to main content
added 411 characters in body
Source Link

The following script does what you want:

#!/bin/bash
counter=0
mkdir foldNew
for i in fold?/dirA/aa*; do
    counter=$((counter + 1))
    mv $i foldNew/aa$counter
done

It keeps count of how many folders it moved already, and it uses Bash's wildcard system to iterate over all the folders you want to move.

I tested it with the setup you described, and it did what you wanted, with the only exception that it moved them to aa1 through aa11, because dirA has five subdirectories, not four.

That script moves aa20 earlier than aa3. If the order of the subdirectories really matters, you can try this code:

#!/bin/bash
counter=0
mkdir foldNew
for i in $(echo fold?/dirA/aa* | sort -V); do
    counter=$((counter + 1))
    mv $i foldNew/aa$counter
done

I think that it doesn't handle spaces and newlines in filenames well, however, so be careful if you use it.

The following script does what you want:

#!/bin/bash
counter=0
mkdir foldNew
for i in fold?/dirA/aa*; do
    counter=$((counter + 1))
    mv $i foldNew/aa$counter
done

It keeps count of how many folders it moved already, and it uses Bash's wildcard system to iterate over all the folders you want to move.

I tested it with the setup you described, and it did what you wanted, with the only exception that it moved them to aa1 through aa11, because dirA has five subdirectories, not four.

The following script does what you want:

#!/bin/bash
counter=0
mkdir foldNew
for i in fold?/dirA/aa*; do
    counter=$((counter + 1))
    mv $i foldNew/aa$counter
done

It keeps count of how many folders it moved already, and it uses Bash's wildcard system to iterate over all the folders you want to move.

I tested it with the setup you described, and it did what you wanted, with the only exception that it moved them to aa1 through aa11, because dirA has five subdirectories, not four.

That script moves aa20 earlier than aa3. If the order of the subdirectories really matters, you can try this code:

#!/bin/bash
counter=0
mkdir foldNew
for i in $(echo fold?/dirA/aa* | sort -V); do
    counter=$((counter + 1))
    mv $i foldNew/aa$counter
done

I think that it doesn't handle spaces and newlines in filenames well, however, so be careful if you use it.

Changed the wildcard to match multiple digits instead of just one
Source Link

The following script does what you want:

#!/bin/bash
counter=0
mkdir foldNew
for i in fold?/dirA/aa?;aa*; do
    counter=$((counter + 1))
    mv $i foldNew/aa$counter
done

It keeps count of how many folders it moved already, and it uses Bash's wildcard system to iterate over all the folders you want to move.

I tested it with the setup you described, and it did what you wanted, with the only exception that it moved them to aa1 through aa11, because dirA has five subdirectories, not four.

The following script does what you want:

#!/bin/bash
counter=0
mkdir foldNew
for i in fold?/dirA/aa?; do
    counter=$((counter + 1))
    mv $i foldNew/aa$counter
done

It keeps count of how many folders it moved already, and it uses Bash's wildcard system to iterate over all the folders you want to move.

I tested it with the setup you described, and it did what you wanted, with the only exception that it moved them to aa1 through aa11, because dirA has five subdirectories, not four.

The following script does what you want:

#!/bin/bash
counter=0
mkdir foldNew
for i in fold?/dirA/aa*; do
    counter=$((counter + 1))
    mv $i foldNew/aa$counter
done

It keeps count of how many folders it moved already, and it uses Bash's wildcard system to iterate over all the folders you want to move.

I tested it with the setup you described, and it did what you wanted, with the only exception that it moved them to aa1 through aa11, because dirA has five subdirectories, not four.

Source Link

The following script does what you want:

#!/bin/bash
counter=0
mkdir foldNew
for i in fold?/dirA/aa?; do
    counter=$((counter + 1))
    mv $i foldNew/aa$counter
done

It keeps count of how many folders it moved already, and it uses Bash's wildcard system to iterate over all the folders you want to move.

I tested it with the setup you described, and it did what you wanted, with the only exception that it moved them to aa1 through aa11, because dirA has five subdirectories, not four.