Skip to main content
Change man page excerpt to match edits.
Source Link
RobertL
  • 6.9k
  • 1
  • 22
  • 39

These examples work in any POSIX shell and require no external programs.

This stores the Part*.mp3 files at the same level as the Project directory (provided there are no files/directories already there w/ the same names):

(cd Project && for i in Part*/audio.mp3; do echo mv "$i" ../"${i%/*}".mp3; done)

This keeps the Part*.mp3 files in the Project directory (w/ the same caveat about pre-existing names as the other):

for i in Project/Part*/audio.mp3; do echo mv "$i" ./"${i%/*}".mp3; done

These solutions use the shell's pattern matching parameter expansion to produce the new filename.

 ${parameter%%wordparameter%word}     Remove LargestSmallest Suffix Pattern.  The word is expanded
                       to produce a pattern.  The parameter expansion then
                       results in parameter, with the largestsmallest portion of the
                       the suffix matched by the pattern deleted.

These examples work in any POSIX shell and require no external programs.

This stores the Part*.mp3 files at the same level as the Project directory (provided there are no files/directories already there w/ the same names):

(cd Project && for i in Part*/audio.mp3; do echo mv "$i" ../"${i%/*}".mp3; done)

This keeps the Part*.mp3 files in the Project directory (w/ the same caveat about pre-existing names as the other):

for i in Project/Part*/audio.mp3; do echo mv "$i" ./"${i%/*}".mp3; done

These solutions use the shell's pattern matching parameter expansion to produce the new filename.

 ${parameter%%word}    Remove Largest Suffix Pattern.  The word is expanded
                       to produce a pattern.  The parameter expansion then
                       results in parameter, with the largest portion of the
                       suffix matched by the pattern deleted.

These examples work in any POSIX shell and require no external programs.

This stores the Part*.mp3 files at the same level as the Project directory:

(cd Project && for i in Part*/audio.mp3; do echo mv "$i" ../"${i%/*}".mp3; done)

This keeps the Part*.mp3 files in the Project directory:

for i in Project/Part*/audio.mp3; do echo mv "$i" ./"${i%/*}".mp3; done

These solutions use the shell's pattern matching parameter expansion to produce the new filename.

 ${parameter%word}     Remove Smallest Suffix Pattern.  The word is expanded
                       to produce a pattern.  The parameter expansion then
                       results in parameter, with the smallest portion of
                       the suffix matched by the pattern deleted.
fixed quotes
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242

These examples work in any POSIX shell and require no external programs.

This stores the Part*.mp3 files at the same level as the Project directory (provided there are no files/directories already there w/ the same names):

(cd Project && for i in Part*/audio.mp3; do echo mv "$i" ../$"${i%%i%/audio.mp3*}".mp3; done)

This keeps the Part*.mp3 files in the Project directory (w/ the same caveat about pre-existing names as the other):

for i in Project/Part*/audio.mp3; do echo mv "$i" $./"${i%%i%/audio.mp3*}".mp3; done

These solutions use the shell's pattern matching parameter expansion to produce the new filename.

 ${parameter%%word}    Remove Largest Suffix Pattern.  The word is expanded
                       to produce a pattern.  The parameter expansion then
                       results in parameter, with the largest portion of the
                       suffix matched by the pattern deleted.

These examples work in any POSIX shell and require no external programs.

This stores the Part*.mp3 files at the same level as the Project directory:

(cd Project && for i in Part*/audio.mp3; do echo mv "$i" ../${i%%/audio.mp3}.mp3; done)

This keeps the Part*.mp3 files in the Project directory:

for i in Project/Part*/audio.mp3; do echo mv "$i" ${i%%/audio.mp3}.mp3; done

These solutions use the shell's pattern matching parameter expansion to produce the new filename.

 ${parameter%%word}    Remove Largest Suffix Pattern.  The word is expanded
                       to produce a pattern.  The parameter expansion then
                       results in parameter, with the largest portion of the
                       suffix matched by the pattern deleted.

These examples work in any POSIX shell and require no external programs.

This stores the Part*.mp3 files at the same level as the Project directory (provided there are no files/directories already there w/ the same names):

(cd Project && for i in Part*/audio.mp3; do echo mv "$i" ../"${i%/*}".mp3; done)

This keeps the Part*.mp3 files in the Project directory (w/ the same caveat about pre-existing names as the other):

for i in Project/Part*/audio.mp3; do echo mv "$i" ./"${i%/*}".mp3; done

These solutions use the shell's pattern matching parameter expansion to produce the new filename.

 ${parameter%%word}    Remove Largest Suffix Pattern.  The word is expanded
                       to produce a pattern.  The parameter expansion then
                       results in parameter, with the largest portion of the
                       suffix matched by the pattern deleted.
wording
Source Link
RobertL
  • 6.9k
  • 1
  • 22
  • 39

This worksThese examples work in any POSIX shell and requiresrequire no external programs.

This stores the Part*.mp3 files at the same level as the Project directory:

(cd Project && for i in Part*/audio.mp3; do echo mv "$i" ../${i%%/audio.mp3}.mp3; done)

This keeps the Part*.mp3 files in the Project directory:

for i in Project/Part*/audio.mp3; do echo mv "$i" ${i%%/audio.mp3}.mp3; done

These solutions use the shell's pattern matching parameter expansion to produce the new filename.

 ${parameter%%word}    Remove Largest Suffix Pattern.  The word is expanded
                       to produce a pattern.  The parameter expansion then
                       results in parameter, with the largest portion of the
                       suffix matched by the pattern deleted.

This works in any POSIX shell and requires no external programs.

This stores the Part*.mp3 files at the same level as the Project directory:

(cd Project && for i in Part*/audio.mp3; do echo mv "$i" ../${i%%/audio.mp3}.mp3; done)

This keeps the Part*.mp3 files in the Project directory:

for i in Project/Part*/audio.mp3; do echo mv "$i" ${i%%/audio.mp3}.mp3; done

These solutions use the shell's pattern matching parameter expansion to produce the new filename.

 ${parameter%%word}    Remove Largest Suffix Pattern.  The word is expanded
                       to produce a pattern.  The parameter expansion then
                       results in parameter, with the largest portion of the
                       suffix matched by the pattern deleted.

These examples work in any POSIX shell and require no external programs.

This stores the Part*.mp3 files at the same level as the Project directory:

(cd Project && for i in Part*/audio.mp3; do echo mv "$i" ../${i%%/audio.mp3}.mp3; done)

This keeps the Part*.mp3 files in the Project directory:

for i in Project/Part*/audio.mp3; do echo mv "$i" ${i%%/audio.mp3}.mp3; done

These solutions use the shell's pattern matching parameter expansion to produce the new filename.

 ${parameter%%word}    Remove Largest Suffix Pattern.  The word is expanded
                       to produce a pattern.  The parameter expansion then
                       results in parameter, with the largest portion of the
                       suffix matched by the pattern deleted.
Meet question requirements
Source Link
RobertL
  • 6.9k
  • 1
  • 22
  • 39
Loading
Source Link
RobertL
  • 6.9k
  • 1
  • 22
  • 39
Loading