You can export the last commands from your terminal by using the command “tail”.
tail -n 1 $file1 >> $file2
-n is the total number of rows you want to copy, the location of bash_history is:
The end code should like like this:
tail -5 /home$USER/.bash_history >> ~/commands