To just output the full pathname for each .partial
file relative to the current directory:
printf '%s\n' ./*/*.partial
Setting the nullglob
shell option in bash
would make this not output the pattern itself if there is no match (there would still be an empty line outputted), and setting dotglob
would additionally match hidden names.
The following splits these pathnames up in a directory path and a filename part:
for name in ./*/*.partial; do
[ -f "$name" ] && printf '%s\t%s\n' "${name%/*}" "${name##*/}"
done
This would print the subdirectory name and the .partial
filename for each .partial
name found in any subdirectory of the current directory.
In bash
, you may additionally want to set the shell option dotglob
if you need to be able to match hidden names as well.
The two parameter substitutions could be replaced by calls to dirname
and basename
:
for name in ./*/*.partial; do
[ -f "$name" ] && printf '%s\t%s\n' "$(dirname "$name")" "$(basename "$name")"
done
A variation of the above for printing the subdirectory name only once (this requires a bash
-like shell for the ${*%%*/}
parameter expansion which removes the directory paths and leaves the filenames, for each positional parameter):
IFS=$'\t'
for dirname in ./*/; do
set -- "$dirname"/*.partial;
[ -f "$1" ] && printf '%s\t%s\n' "$dirname" "${*##*/}"
done
This loops over each subdirectory and expands the *.partial
globbing pattern in each. If the first match is a regular file (or a link to one), the subdirectory name is printed followed by the names that matched the pattern, with the directory path removed.
.partial
files in each subdirectory?