findzsh

Remove parts of filenames that are not floating numbers


I have a directory which contains filenames including IDs in front, e.g:

32.04 Wybrane wzory matematyczne
32.01 Funkcje
31.01 Opracowania lektur EM 2023

The desired filenames after the change would respectively be:

32.04
32.01
31.01

I have other number formats in the directory, such as 30-39, or 31 {filename} so I want to specifically target the files with this floating notation.

The script should run from parent through all its subdirectories.


Solution

  • autoload zmv
    zmv -i '(**/)(<->.<->) *' '$1$2'
    

    More about zmv.
    More zmv examples.
    A longer zmv explanation. The description there covers many of the operators used in a previous version of this answer (zmv '(*/)#<->.<-> *' '${f:h}/${${f:t}%% *}').