Skip to main content
added 12 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Assuming the names of the files and directories follow the same naming convention in that they share some common grouping prefix followed by a dot, and assuming we don't know the filename suffixes of files or directories:

topdir=.

for dirname in "$topdir"/*/; do
    prefix=$( basename "$dirname" )  # .$topdir/FileC.directory/ --> FileC.directory
    prefix=${prefix%%.*}             # FileC.directory          --> FileC

    for filename in "$topdir/$prefix".*; do
        if [ ! -d "$filename" ]; then
            mv -i "$filename" "$dirname"
        fi
    done
done

The outer loop iterates over all directories in the directory $topdir (here set to ., the current directory). The $prefix will be the base name of the directory name, with the bit after the first dot removed.

Once the prefix has been computed, non-directories (files) in the same $topdir directory that share the same prefix are moved to the directory.

Assuming the names of the files and directories follow the same naming convention in that they share some common grouping prefix followed by a dot, and assuming we don't know the filename suffixes of files or directories:

topdir=.

for dirname in "$topdir"/*/; do
    prefix=$( basename "$dirname" )  # ./FileC.directory/ --> FileC.directory
    prefix=${prefix%%.*}             # FileC.directory    --> FileC

    for filename in "$topdir/$prefix".*; do
        if [ ! -d "$filename" ]; then
            mv -i "$filename" "$dirname"
        fi
    done
done

The outer loop iterates over all directories in the directory $topdir (here set to ., the current directory). The $prefix will be the base name of the directory name, with the bit after the first dot removed.

Once the prefix has been computed, non-directories (files) in the same $topdir directory that share the same prefix are moved to the directory.

Assuming the names of the files and directories follow the same naming convention in that they share some common grouping prefix followed by a dot, and assuming we don't know the filename suffixes of files or directories:

topdir=.

for dirname in "$topdir"/*/; do
    prefix=$( basename "$dirname" )  # $topdir/FileC.directory/ --> FileC.directory
    prefix=${prefix%%.*}             # FileC.directory          --> FileC

    for filename in "$topdir/$prefix".*; do
        if [ ! -d "$filename" ]; then
            mv -i "$filename" "$dirname"
        fi
    done
done

The outer loop iterates over all directories in the directory $topdir (here set to ., the current directory). The $prefix will be the base name of the directory name, with the bit after the first dot removed.

Once the prefix has been computed, non-directories (files) in the same $topdir directory that share the same prefix are moved to the directory.

added 1 character in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Assuming the names of the files and directories follow the same naming convention in that they share some common grouping prefix followed by a dot, and assuming we don't know the filename suffixes of files or directories:

topdir=.

for dirname in "$topdir"/*/; do
    prefix=$( basename "$dirname" )  # ./FileC.directory/ --> FileC.directory
    prefix=${prefix%%.*}             # FileC.directory    --> FileC

    for filename in "$topdir/$prefix".*; do
        if [ ! -d "$filename" ]; then
            mv -i "$filename" "$dirname"
        fi
    done
done

The outer loop iterates over all directories in the directory $topdir (here set to ., the current directory). The prefix$prefix will be the base name of the directory name, with the bit after the first dot removed.

Once the prefix has been computed, non-directories (files) in the same $topdir directory that share the same prefix are moved to the directory.

Assuming the names of the files and directories follow the same naming convention in that they share some common grouping prefix followed by a dot, and assuming we don't know the filename suffixes of files or directories:

topdir=.

for dirname in "$topdir"/*/; do
    prefix=$( basename "$dirname" )
    prefix=${prefix%%.*}

    for filename in "$topdir/$prefix".*; do
        if [ ! -d "$filename" ]; then
            mv -i "$filename" "$dirname"
        fi
    done
done

The outer loop iterates over all directories in the directory $topdir (here set to ., the current directory). The prefix will be the base name of the directory name, with the bit after the first dot removed.

Once the prefix has been computed, non-directories (files) in the same $topdir directory that share the same prefix are moved to the directory.

Assuming the names of the files and directories follow the same naming convention in that they share some common grouping prefix followed by a dot, and assuming we don't know the filename suffixes of files or directories:

topdir=.

for dirname in "$topdir"/*/; do
    prefix=$( basename "$dirname" )  # ./FileC.directory/ --> FileC.directory
    prefix=${prefix%%.*}             # FileC.directory    --> FileC

    for filename in "$topdir/$prefix".*; do
        if [ ! -d "$filename" ]; then
            mv -i "$filename" "$dirname"
        fi
    done
done

The outer loop iterates over all directories in the directory $topdir (here set to ., the current directory). The $prefix will be the base name of the directory name, with the bit after the first dot removed.

Once the prefix has been computed, non-directories (files) in the same $topdir directory that share the same prefix are moved to the directory.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Assuming the names of the files and directories follow the same naming convention in that they share some common grouping prefix followed by a dot, and assuming we don't know the filename suffixes of files or directories:

topdir=.

for dirname in "$topdir"/*/; do
    prefix=$( basename "$dirname" )
    prefix=${prefix%%.*}

    for filename in "$topdir/$prefix".*; do
        if [ ! -d "$filename" ]; then
            mv -i "$filename" "$dirname"
        fi
    done
done

The outer loop iterates over all directories in the directory $topdir (here set to ., the current directory). The prefix will be the base name of the directory name, with the bit after the first dot removed.

Once the prefix has been computed, non-directories (files) in the same $topdir directory that share the same prefix are moved to the directory.