Moving files to folders and rename

Hello!

I am new to this. I have many files from b_ap00 to b_ap80, and I need to move them to folder 00 to 80 respectively, where b_ap00 is in folder 00, b_ap01 is in folder 01.

On top of this, I need to rename the file once they are inside the folder to b_ot, and subsequently run it (ifort -o b-i.x b_ot followed by ./b-i.x)

Could someone please guide me along? I managed to create the folders somehow but moving them in has problems.

What OS and shell are you using?
Please post the output of:

uname -a
echo $SHELL

Linux atlas5-c01 2.6.18-238.19.1.el5 #1 SMP Sun Jul 10 08:43:41 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

/bin/svush

Sorry what does this mean?

try something like this..

for i in {0..80}
do
name=$(printf "%02d" $i)
file_name="b_ap$name"
mv $file_name /$name
mv /$name/$file_name #what you want to do
#do your operations here
done

Hi!

Thank you so much. But I have this error:
mv: cannot create directory `/080': Permission denied
mv: missing destination file operand after `/80/b_ap80 #for all my files from 00

Basically this is what I did:

split -d -l 98 a01 b_ap

printf "%03d\n" $(seq 0 80) | xargs -I{} mkdir {}

for i in {0..80}
do
name=$(printf "%03d" $i)
file_name="$name"
mv $file_name /$name
mv /$name/$file_name/ #what you want to do
#do your operations here
done

But when I checked the files, they are there. I used ls.

Or did I understand you wrongly?

Do you have create directory rights for your user?

what is output of below command?

mkdir test

mkdir: cannot create directory `TEST': File exists