We can use a simple for loop to iterate over folder content and use an if statement to check whether the path is a directory or a file:
#!/bin/bash for path in /home/likegeeks/* do if [ -d "$path" ] then echo "$path is a directory" elif [ -f "$path" ] then echo "$path is a file" fi done
![](https://static.packt-cdn.com/products/9781788990554/graphics/assets/812eacd0-590e-4c82-aea1-ff797f45ea55.png)
This is pretty straightforward script. We iterate over directory content and then we use an if statement to check whether the path is a directory or a file. Finally, we print beside each path whether it's a file or a directory.
We used quotes for the path variable because the file could contain a space.