Reputation: 3413
I want to iterate through all files in a specified directory including hidden files in a script
i tried something like this:
for f in /home/pedja/test/*; do
Which shows only visible files (files that don't start with .
)
If i do this:
for f in /home/pedja/test/.*; do
It shows only hidden files (files that starts with .
)
How can i list all files in a single for loop
Upvotes: 0
Views: 446
Reputation: 75578
This form runs it on a subshell but that's the safest you can have when your shell does not support process substitution.
find /home/pedja/test/ -mindepth 1 -maxdepth 1 -name '.*' | while read -r file; do
...
done
Upvotes: 0
Reputation: 781
use brace expansion:
for f in /home/pedja/test/{,.}*; do echo "$f"; done
Upvotes: 1