Batch (for loop) commands in the terminal

Sometimes I have a command to run on a list of files. Below are some examples of how to do it:

Command on a list of files in the current directory

for file in ls *; do echo $file; done

Of course you can replace echo $file by any other command. In this example it will only print a list of the filenames in the directory.

Command using variables

for i in {1,2,3,4,5}; do touch file_$i; done

This command will create five files named file_01-file_05 if they do not exist, or change their access and modification times to the current time if the already exist.