Bash Listing Files in a Directory and Testing whether Specific Files Exist in Directories: Difference between revisions
Jump to navigation
Jump to search
Line 18: | Line 18: | ||
<font color=darkgray> | <font color=darkgray> | ||
To further research, it seems the following approach does not work because if there is more than one directory, the first iteration assigns a multi-line to d: | '''find''': To further research, it seems the following approach does not work because if there is more than one directory, the first iteration assigns a multi-line to d: | ||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
for d in $(find ${dir} -name "*-something"} -type d); do | for d in $(find ${dir} -name "*-something"} -type d); do |
Revision as of 00:22, 4 December 2019
Internal
Overview
To list files:
local dir=...
for f in ${dir}/*; do
[[ -f ${f} ]] && echo -n "$(basename ${f}) "
done
To list directories, replace -f with -d.
find: To further research, it seems the following approach does not work because if there is more than one directory, the first iteration assigns a multi-line to d:
for d in $(find ${dir} -name "*-something"} -type d); do
debug "d: ${d}"
...
done