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

Posted By yusuf read more
Subscribe to terminal