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

It's not clear from the question how the files should be renamed, so I'm going to assume that they should be renamed by appending the name of their original directory to their original name.

The code below assumes that your working directory is the directory holdingholds the subdirectories and that each subdirectory has the index.html file, as shown in the question. The index.html files will be moved to a new directory called allfiles.

mkdir allfiles || exit

for pathname in */index.html
do
    mv -- "$pathname" "allfiles/${pathname%/index.html}-index.html"
done

The pathname variable will hold pathnames like A-Dwelling-Place/index.html, and the parameter expansion ${pathname%/index.html} would remove the /index.html bit from the end of that pathname.

You could instead iterate over the directories rather than the files,

mkdir allfiles || exit

for dirname in */
do
    mv -- "$dirname"/index.html "${dirname%/}-index.html"
done

In this case, the dirname variable would hold pathnames like A-Dwelling-Place/, and ${dirname%/} would delete that trailing slash character.

It's not clear from the question how the files should be renamed, so I'm going to assume that they should be renamed by appending the name of their original directory to their original name.

The code below assumes that your working directory is the directory holding the subdirectories and that each subdirectory has the index.html file, as shown in the question. The index.html files will be moved to a new directory called allfiles.

mkdir allfiles || exit

for pathname in */index.html
do
    mv -- "$pathname" "allfiles/${pathname%/index.html}-index.html"
done

The pathname variable will hold pathnames like A-Dwelling-Place/index.html, and the parameter expansion ${pathname%/index.html} would remove the /index.html bit from the end of that pathname.

It's not clear from the question how the files should be renamed, so I'm going to assume that they should be renamed by appending the name of their original directory to their original name.

The code below assumes that your working directory holds the subdirectories and each subdirectory has the index.html file, as shown in the question. The index.html files will be moved to a new directory called allfiles.

mkdir allfiles || exit

for pathname in */index.html
do
    mv -- "$pathname" "allfiles/${pathname%/index.html}-index.html"
done

The pathname variable will hold pathnames like A-Dwelling-Place/index.html, and the parameter expansion ${pathname%/index.html} would remove the /index.html bit from the end of that pathname.

You could instead iterate over the directories rather than the files,

mkdir allfiles || exit

for dirname in */
do
    mv -- "$dirname"/index.html "${dirname%/}-index.html"
done

In this case, the dirname variable would hold pathnames like A-Dwelling-Place/, and ${dirname%/} would delete that trailing slash character.

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

It's not clear from the question how the files should be renamed, so I'm going to assume that they should be renamed by appending the name of their original directory to their original name.

The code below assumes that your working directory is the directory holding the subdirectories and that each subdirectory has the index.html file, as shown in the question. The index.html files will be moved to a new directory called allfiles.

mkdir allfiles || exit

for pathname in */index.html
do
    mv -- "$pathname" "allfiles/${pathname%/index.html}-index.html"
done

The pathname variable will hold pathnames like A-Dwelling-Place/index.html, and the parameter expansion ${pathname%/index.html} would remove the /index.html bit from the end of that pathname.