I'm working on a script to manage my dotfiles. Although I'm aware of tools like Stow, I prefer the challenge of doing it myself. My goal is to iterate through all items in a specific folder, but since many of these items are hidden files (starting with a dot), my current approach using `ls -a` is causing issues. When I list the contents using this command, I end up including the `.` and `..` directories, which complicates my plan to delete files and create symlinks afterward. What's the best way to iterate through all the files and subfolders in my directory while avoiding those undesired entries?
4 Answers
A solid method for looping through files is to use the `shopt` command in bash. For instance:
```bash
shopt -s nullglob
for file in *; do
echo "$file"
done
```
If you want to include hidden files too, enable `dotglob` as well. This way, you can handle both visible and hidden files without issues!
Be careful with your command! Using `ls -a` isn't the best way to go about it because it can mess things up with files that have spaces or special characters in their names. Instead, consider using shell globbing or `find` with specific options to target only the files you want.
You might want to try using the `find` command. It has a ton of options that can make this easier for you. You can use it to list files and directories without `.` and `..`. Just keep in mind that `find` is recursive by default, but you can control how deep it goes if you only want top-level files and folders.
Using `ls -A` can also be useful since it lists all entries except for the `.` and `..` directories, so you get exactly what you're looking for without including the current and parent directory links.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically