Вот несколько методов, которые можно использовать для перебора списка файлов на языке программирования Bash:
-
Использование цикла for:
for file in /path/to/directory/*; do if [[ -f "$file" ]]; then # Perform operations on the file echo "$file" fi done
-
Использование команды поиска:
find /path/to/directory -type f -print0 | while IFS= read -r -d '' file; do # Perform operations on the file echo "$file" done
-
Использование цикла while с командой чтения:
ls -1 /path/to/directory | while IFS= read -r file; do if [[ -f "/path/to/directory/$file" ]]; then # Perform operations on the file echo "$file" fi done