Bash – Working recursive through folders

If you use the bash to create or modify files, it could be necessary to process all subfolders. For testing I produced the following folders in a dircetory:

> tree
├── folder
└── folder with whitespace

2 directories, 0 files

My first idea was to use the find command in a for-loop. Here you see an example which prints out all folders on in the terminal.

If you run this short bash script and you have folders (files) with whitespaces you will run in trouble.


So my second try was a find command piped into a while loop.

If you run this script the folders are shown in the right way.

> ./ 
./folder with whitespace

The find command gives you the opportunity to limit the commands in your script to particular files in your folder (and your subfolders). The following find command will only show files which end on csv