bash:directories:loop_through_files_in_a_directory_recursively
Differences
This shows you the differences between two versions of the page.
bash:directories:loop_through_files_in_a_directory_recursively [2022/06/13 09:11] – created peter | bash:directories:loop_through_files_in_a_directory_recursively [2022/06/13 09:12] (current) – peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== BASH - Directories - Loop Through Files in a Directory Recursively ====== | ====== BASH - Directories - Loop Through Files in a Directory Recursively ====== | ||
+ | |||
+ | **find** is one of the best commands to find files that satisfy specific criteria. | ||
+ | |||
+ | <code bash> | ||
+ | find . -type f -print0 | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | * **dot(.)** specifies to find files in our present working directory. | ||
+ | * **-type f** to specify that we want to search for only files and not directories. | ||
+ | * **-print0** will use a null byte to delimit the filenames it prints. | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <code bash> | ||
+ | for i in $(find . -type f -print0) | ||
+ | do | ||
+ | # code to perform task on each file. | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
bash/directories/loop_through_files_in_a_directory_recursively.1655111482.txt.gz · Last modified: 2022/06/13 09:11 by peter