How to remove a specific part of the file name from a lot of files

Solution 1:

The perl rename command is powerful. It can look for string patterns and replace these. If your files have a similar time stamp, this would work:

rename -n 's/\(2019.*?\)//' *

This would remove all strings looking like (2019...). So it would not matter if some files have a different time stamp.

The match is made non-greedy by appending ? to .* (with thanks to Steeldriver). Thus, the expression will only match characters until the first occurrence of ), instead of possible additional occurrences later in the string.

The -n option causes the command to only show what is going to be done. The rename is not effectively done. This allows you to first check the output carefully, and if it shows that the command will do what you want, rerun it without the -n option to actually proceed with the rename.

The tool may not be installed by default. You can install it with :

sudo apt install rename

Solution 2:

I fixed the issue with this code

find . -maxdepth 20 -type f | while read LINE 
do
mv "$LINE" `echo $LINE | sed 's/\s(2019_04_12 11_03_06 UTC)//'`
done