For files and directories, not recursive
for filename in *; do echo "put ${filename}"; done
For files only (excludes folders), not recursive
for file in *; do
if [ -f "$file" ]; then
echo "$file"
fi
done
For a recursive solution, see Bennet Yee’s answer.
More Related Contents:
- Bash scripting, multiple conditions in while loop
- Expansion of variables inside single quotes in a command in Bash
- How to add a progress bar to a shell script?
- What is the purpose of “&&” in a shell command?
- sudo echo “something” >> /etc/privilegedFile doesn’t work [duplicate]
- Convert absolute path into relative path given a current directory using Bash
- While-loop subshell dilemma in Bash
- How do I escape the wildcard/asterisk character in bash?
- Check existence of input argument in a Bash shell script
- How do I grab an INI value within a shell script?
- How to create a cron job using Bash automatically without the interactive editor?
- Convert date time string to epoch in Bash
- How do I put an already-running process under nohup?
- How to obtain the absolute path of a file via Shell (BASH/ZSH/SH)?
- printf in bash: “09” and “08” are invalid numbers, “07” and “06” are fine
- String comparison in bash. [[: not found
- How to remove filename prefix with a Posix shell
- How to pipe multiple commands into a single command in the shell? (sh, bash, …)
- How do I read user input into a variable in Bash?
- Why do I get “/bin/sh: Argument list too long” when passing quoted arguments?
- Count number of lines in a git repository
- How do I check if a directory exists or not in a Bash shell script?
- Validate date format in a shell script
- shell script respond to keypress
- How do I get both STDOUT and STDERR to go to the terminal and a log file?
- -bash: __git_ps1: command not found
- Use GNU find to show only the leaf directories
- Get the name of the caller script in bash script
- Reading lines in a file and avoiding lines with # with Bash
- docker entrypoint running bash script gets “permission denied”