There are certain files in the folder, you need to create a folder for each, whose name will be the file name with the addition of "_". After creating a folder, transfer it to another location and copy the source file into it.

#мой скрипт #!/bin/bash for file in `find /root/Desktop/testtest/ -type f -name "*.txt"`; do mkdir $dir1 ${file}_ mv "$dir1" /root/Desktop/testingScript cp "$file" "$dir1" done 

He performs the creation of the folder perfectly, but no further operations (the folder does not transfer, does not copy files into them). Help me find the error and tell me what to add, so that the script looked at the file name before its extension (".txt" in this example) and called the folder name without an extension.

    1 answer 1

    Probably so?

     for file in `find /root/Desktop/testtest/ -type f -name "*.txt"`; do filename=`basename "$file"` dir1="/root/Desktop/testingScript/${filename%.*}_" mkdir -p "$dir1" cp "$file" "$dir1" done 
    • Everything works, thank you very much. - quzty