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.
1 2 3 4 5 6 7 8 |
#!/bin/bash for f in $(find -type d) do echo "$f" ... done |
If you run this short bash script and you have folders (files) with whitespaces you will run in trouble.
./for_find.sh . ./folder ./folder with whitespace
So my second try was a find command piped into a while loop.
1 2 3 4 5 6 7 8 |
#!/bin/bash find . -type d | while read f do echo "$f" ... done |
If you run this script the folders are shown in the right way.
> ./while_find.sh . ./folder ./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
1 |
find . -name '*.csv' |