for i in CPU*; do num=$(echo "$i" | cut -c4 -); cp file$num.txt $i; done [root@herlo-lap ~]# ls -lR CPU* CPU1: total 0 -rw-rw-r-- 1 root root 0 May 23 21:51 file1.txt CPU3: total 0 -rw-rw-r-- 1 root root 0 May 23 21:51 file3.txt CPU4: total 0 -rw-rw-r-- 1 root root 0 May 23 21:51 file4.txt CPU5: total 0 -rw-rw-r-- 1 root root 0 May 23 21:51 file5.txt CPU6: total 0 -rw-rw-r-- 1 root root 0 May 23 21:51 file6.txt