Tag Archives: bash

bash script: run command on every file

To run a command line on every file within a given directory, simply rely on ‘find’ with ‘-exec’ argument! This is by far the easiest and quickest way to do it (run ‘man find’ for more information on how to use ‘-exec’ argument). Here is how it works: find <path_to_folder> -type f -maxdepth 1 -exec <my_command_line_using_{}_as file_name> \; replace <path_to_folder> with actual path to the folder containing the files -type f will restrict command to files only (ie. not to directories) -maxdepth 1 will prevent going recursively into subdirectory, feel free to change its value if you require to go […]