Skip to main content
deleted 16 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 237

Using Bash globbing:

for i in *.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo if you're happy with it.


If you need to go into subdirectories:

shopt -s globstar
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo when you're happy with it.


Using find:

find . -name '*.ext' -exec bash -c 'echo mv -nv -- "$0" "${0/firstname.lastname/}"' {} \;

Remove the echo when you're happy with it.


How about a method that will rename, removing any pattern of the form xxx.yyy (so it will remove the firstname.lastname of the filename, being john.doe or james.brown): for this (using the first method):

shopt -s extglob
for i in *.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph]])/}"
done

or using the second method:

shopt -s globstar extglob
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph:]])/}"
done

or using the find method:

find . -name '*.ext' -exec bash -c 'shopt -s extglob; echo mv -nv -- "$0" "${0/+([[:graph:]])\.+([[:graph:]])/}"' {} \;

If the firstname.lastname pattern is always enclosed between spaces, you could also use the pattern substitution:

"${i/*([[:space:]])+([[:graph:]])\.+([[:graph:]])*([[:space:]])/ }"

so as to only leave one space.


Note. All these methods are 100% safe regarding filenames with spaces and other funny symbols.

Hope this helps!

Using Bash globbing:

for i in *.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo if you're happy with it.


If you need to go into subdirectories:

shopt -s globstar
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo when you're happy with it.


Using find:

find . -name '*.ext' -exec bash -c 'echo mv -nv -- "$0" "${0/firstname.lastname/}"' {} \;

Remove the echo when you're happy with it.


How about a method that will rename, removing any pattern of the form xxx.yyy (so it will remove the firstname.lastname of the filename, being john.doe or james.brown): for this (using the first method):

shopt -s extglob
for i in *.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph]])/}"
done

or using the second method:

shopt -s globstar extglob
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph:]])/}"
done

or using the find method:

find . -name '*.ext' -exec bash -c 'shopt -s extglob; echo mv -nv -- "$0" "${0/+([[:graph:]])\.+([[:graph:]])/}"' {} \;

If the firstname.lastname pattern is always enclosed between spaces, you could also use the pattern substitution:

"${i/*([[:space:]])+([[:graph:]])\.+([[:graph:]])*([[:space:]])/ }"

so as to only leave one space.


Note. All these methods are 100% safe regarding filenames with spaces and other funny symbols.

Hope this helps!

Using Bash globbing:

for i in *.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo if you're happy with it.


If you need to go into subdirectories:

shopt -s globstar
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo when you're happy with it.


Using find:

find . -name '*.ext' -exec bash -c 'echo mv -nv -- "$0" "${0/firstname.lastname/}"' {} \;

Remove the echo when you're happy with it.


How about a method that will rename, removing any pattern of the form xxx.yyy (so it will remove the firstname.lastname of the filename, being john.doe or james.brown): for this (using the first method):

shopt -s extglob
for i in *.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph]])/}"
done

or using the second method:

shopt -s globstar extglob
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph:]])/}"
done

or using the find method:

find . -name '*.ext' -exec bash -c 'shopt -s extglob; echo mv -nv -- "$0" "${0/+([[:graph:]])\.+([[:graph:]])/}"' {} \;

If the firstname.lastname pattern is always enclosed between spaces, you could also use the pattern substitution:

"${i/*([[:space:]])+([[:graph:]])\.+([[:graph:]])*([[:space:]])/ }"

so as to only leave one space.


Note. All these methods are 100% safe regarding filenames with spaces and other funny symbols.

added 694 characters in body
Source Link

Using Bash globbing:

for i in *.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo if you're happy with it.


If you need to go into subdirectories:

shopt -s globstar
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo when you're happy with it.


Using find:

find . -name '*.ext' -exec bash -c 'echo mv -nv -- "$0" "${0/firstname.lastname/}"' {} \;

Remove the echo when you're happy with it.


How about a method that will rename, removing any pattern of the form xxx.yyy (so it will remove the firstname.lastname of the filename, being john.doe or james.brown): for this (using the first method):

shopt -s extglob
for i in *.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph]])/}"
done

or using the second method:

shopt -s globstar extglob
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph:]])/}"
done

or using the find method:

find . -name '*.ext' -exec bash -c 'shopt -s extglob; echo mv -nv -- "$0" "${0/+([[:graph:]])\.+([[:graph:]])/}"' {} \;

If the firstname.lastname pattern is always enclosed between spaces, you could also use the pattern substitution:

"${i/*([[:space:]])+([[:graph:]])\.+([[:graph:]])*([[:space:]])/ }"

so as to only leave one space.


Note. All these methods are 100% safe regarding filenames with spaces and other funny symbols.

Hope this helps!

Using Bash globbing:

for i in *.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo if you're happy with it.


If you need to go into subdirectories:

shopt -s globstar
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo when you're happy with it.


Using find:

find . -name '*.ext' -exec bash -c 'echo mv -nv -- "$0" "${0/firstname.lastname/}"' {} \;

Remove the echo when you're happy with it.


How about a method that will rename, removing any pattern of the form xxx.yyy (so it will remove the firstname.lastname of the filename, being john.doe or james.brown): for this (using the first method):

shopt -s extglob
for i in *.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph]])/}"
done

or using the second method:

shopt -s globstar extglob
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph:]])/}"
done

or using the find method:

find . -name '*.ext' -exec bash -c 'shopt -s extglob; echo mv -nv -- "$0" "${0/+([[:graph:]])\.+([[:graph:]])/}"' {} \;

Note. All these methods are 100% safe regarding filenames with spaces and other funny symbols.

Hope this helps!

Using Bash globbing:

for i in *.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo if you're happy with it.


If you need to go into subdirectories:

shopt -s globstar
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo when you're happy with it.


Using find:

find . -name '*.ext' -exec bash -c 'echo mv -nv -- "$0" "${0/firstname.lastname/}"' {} \;

Remove the echo when you're happy with it.


How about a method that will rename, removing any pattern of the form xxx.yyy (so it will remove the firstname.lastname of the filename, being john.doe or james.brown): for this (using the first method):

shopt -s extglob
for i in *.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph]])/}"
done

or using the second method:

shopt -s globstar extglob
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph:]])/}"
done

or using the find method:

find . -name '*.ext' -exec bash -c 'shopt -s extglob; echo mv -nv -- "$0" "${0/+([[:graph:]])\.+([[:graph:]])/}"' {} \;

If the firstname.lastname pattern is always enclosed between spaces, you could also use the pattern substitution:

"${i/*([[:space:]])+([[:graph:]])\.+([[:graph:]])*([[:space:]])/ }"

so as to only leave one space.


Note. All these methods are 100% safe regarding filenames with spaces and other funny symbols.

Hope this helps!

added 694 characters in body
Source Link

Using Bash globbing:

for i in *.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo if you're happy with it.


If you need to go into subdirectories:

shopt -s globstar
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo when you're happy with it.


Using find:

find . -name '*.ext' -exec bash -c 'echo mv -nv -- "$0" "${0/firstname.lastname/}"' {} \;

Remove the echo when you're happy with it.


How about a method that will rename, removing any pattern of the form xxx.yyy (so it will remove the firstname.lastname of the filename, being john.doe or james.brown): for this (using the first method):

shopt -s extglob
for i in *.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph]])/}"
done

or using the second method:

shopt -s globstar extglob
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph:]])/}"
done

or using the find method:

find . -name '*.ext' -exec bash -c 'shopt -s extglob; echo mv -nv -- "$0" "${0/+([[:graph:]])\.+([[:graph:]])/}"' {} \;

Note. All these methods are 100% safe regarding filenames with spaces and other funny symbols.

Hope this helps!

Using Bash globbing:

for i in *.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname}"
done

Remove the echo if you're happy with it.


If you need to go into subdirectories:

shopt -s globstar
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname}"
done

Remove the echo when you're happy with it.


Using find:

find . -name '*.ext' -exec bash -c 'echo mv -nv -- "$0" "${0/firstname.lastname/}"' {} \;

Remove the echo when you're happy with it.


Note. All these methods are 100% safe regarding filenames with spaces and other funny symbols.

Using Bash globbing:

for i in *.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo if you're happy with it.


If you need to go into subdirectories:

shopt -s globstar
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/firstname.lastname/}"
done

Remove the echo when you're happy with it.


Using find:

find . -name '*.ext' -exec bash -c 'echo mv -nv -- "$0" "${0/firstname.lastname/}"' {} \;

Remove the echo when you're happy with it.


How about a method that will rename, removing any pattern of the form xxx.yyy (so it will remove the firstname.lastname of the filename, being john.doe or james.brown): for this (using the first method):

shopt -s extglob
for i in *.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph]])/}"
done

or using the second method:

shopt -s globstar extglob
for i in **/*.ext; do
    echo mv -nv -- "$i" "${i/+([[:graph:]])\.+([[:graph:]])/}"
done

or using the find method:

find . -name '*.ext' -exec bash -c 'shopt -s extglob; echo mv -nv -- "$0" "${0/+([[:graph:]])\.+([[:graph:]])/}"' {} \;

Note. All these methods are 100% safe regarding filenames with spaces and other funny symbols.

Hope this helps!

Source Link
Loading