Skip to main content
deleted 214 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

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.

In zsh:

print -rC1 -- ./*/*.partial(-.ND)

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

In zsh, also matching hidden names, and restricting to regular files and symbolic links to regular files (as in the above):

print -raC2 -- ./*/*.partial(ND-.e['reply=($REPLY:h $REPLY:t)'])

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 from, 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.

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.

In zsh:

print -rC1 -- ./*/*.partial(-.ND)

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

In zsh, also matching hidden names, and restricting to regular files and symbolic links to regular files (as in the above):

print -raC2 -- ./*/*.partial(ND-.e['reply=($REPLY:h $REPLY:t)'])

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 from 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.

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.

use the head and tail modifiers instead
Source Link
Stéphane Chazelas
  • 584.9k
  • 96
  • 1.1k
  • 1.7k

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.

In zsh:

print -rC1 -- ./*/*.partial(-.ND)

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

In zsh, also matching hidden names, and restricting to regular files and symbolic links to regular files (as in the above):

print -rC2raC2 -- ./*/*.partial(ND-.e['reply=(${REPLY%/*}$REPLY:h ${REPLY##*/}$REPLY:t)'])

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 from 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.

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.

In zsh:

print -rC1 -- ./*/*.partial(-.ND)

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

In zsh, also matching hidden names, and restricting to regular files and symbolic links to regular files (as in the above):

print -rC2 -- ./*/*.partial(ND-.e['reply=(${REPLY%/*} ${REPLY##*/})'])

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 from 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.

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.

In zsh:

print -rC1 -- ./*/*.partial(-.ND)

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

In zsh, also matching hidden names, and restricting to regular files and symbolic links to regular files (as in the above):

print -raC2 -- ./*/*.partial(ND-.e['reply=($REPLY:h $REPLY:t)'])

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 from 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.

added 130 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

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.

In zsh:

print -rC1 -- ./*/*.partial(-.ND)

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

In zsh, also matching hidden names, and restricting to regular files and symbolic links to regular files (as in the above):

print -rC2 -- ./*/*.partial(ND-.e['reply=(${REPLY%/*} ${REPLY##*/})'])

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 from 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.

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

In zsh, also matching hidden names, and restricting to regular files and symbolic links to regular files (as in the above):

print -rC2 -- ./*/*.partial(ND-.e['reply=(${REPLY%/*} ${REPLY##*/})'])

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 from 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.

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.

In zsh:

print -rC1 -- ./*/*.partial(-.ND)

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

In zsh, also matching hidden names, and restricting to regular files and symbolic links to regular files (as in the above):

print -rC2 -- ./*/*.partial(ND-.e['reply=(${REPLY%/*} ${REPLY##*/})'])

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 from 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.

added 130 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading
added 11 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading
added 258 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading
added 220 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading