I have a folder with following mp4 file which are needed to be renamedfor filename in /media/usama/CRUNCH/RO_Plant/RO_Videos/*; do    File1=$filename    echo $File1done/media/usama/CRUNCH/RO_Plant/RO_Videos/Desal RO 16' Desalination Plants-JdN_Yx_5HzI.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/How Desalination Works-_H8EDLFNDtI.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/how membrane filter works with water-M3mpJysa6zQ.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Hydranautics - Spiral Wound Reverse Osmosis Elements-YlMGZWmh_Mw.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Industrial Reverse Osmosis Startup Part 1 of 3-6xD9FhbAIvY.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Industrial Reverse Osmosis Startup Part 2 of 3-Dt23yzCXaVA.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Industrial Reverse Osmosis Startup Part 3 of 3-VXyK20P6HD4.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/MED Desalination Process-5nDcxhkq8Js.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Reverse Osmosis Membrane Replacement Procedure-zNXYkH3uj-I.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Reverse Osmosis or RO System-BeXHKpuHVZg.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Reverse Osmosis Pressure Vessel-BeXHKpuHVZg.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/RO Process Equipments by R S Engineering, Mumbai-ijJ6QyaQ-Bk.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/The BioSand Water Filter-SlqAitfBbdQ.mp4Now I want to trim the random words starting from - till .mp4 such that this filename is converted from The BioSand Water Filter-SlqAitfBbdQ.mp4 to The BioSand Water Filter.mp4for this I got partial success as is shown belowfor filename in /media/usama/CRUNCH/RO_Plant/RO_Videos/*; do    File1=$filename    Out=${File1:0:${#File1}-16}.mp4    echo $Outdone/media/usama/CRUNCH/RO_Plant/RO_Videos/Desal RO 16' Desalination Plants.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/How Desalination Works.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/how membrane filter works with water.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Hydranautics - Spiral Wound Reverse Osmosis Elements.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Industrial Reverse Osmosis Startup Part 1 of 3.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Industrial Reverse Osmosis Startup Part 2 of 3.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Industrial Reverse Osmosis Startup Part 3 of 3.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/MED Desalination Process.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Reverse Osmosis Membrane Replacement Procedure.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Reverse Osmosis or RO System.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/Reverse Osmosis Pressure Vessel.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/RO Process Equipments by R S Engineering, Mumbai.mp4/media/usama/CRUNCH/RO_Plant/RO_Videos/The BioSand Water Filter.mp4Now when I add the last piece, it boils down to nothing?for filename in /media/usama/CRUNCH/RO_Plant/RO_Videos/*; do    File1=$filename    Out=${File1:0:${#File1}-16}.mp4    echo $Out    mv $filename $Outdone/media/usama/CRUNCH/RO_Plant/RO_Videos/Desal RO 16' Desalination Plants.mp4mv: target Plants.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/How Desalination Works.mp4mv: target Works.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/how membrane filter works with water.mp4mv: target water.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/Hydranautics - Spiral Wound Reverse Osmosis Elements.mp4mv: target Elements.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/Industrial Reverse Osmosis Startup Part 1 of 3.mp4mv: target 3.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/Industrial Reverse Osmosis Startup Part 2 of 3.mp4mv: target 3.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/Industrial Reverse Osmosis Startup Part 3 of 3.mp4mv: target 3.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/MED Desalination Process.mp4mv: target Process.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/Reverse Osmosis Membrane Replacement Procedure.mp4mv: target Procedure.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/Reverse Osmosis or RO System.mp4mv: target System.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/Reverse Osmosis Pressure Vessel.mp4mv: target Vessel.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/RO Process Equipments by R S Engineering, Mumbai.mp4mv: target Mumbai.mp4 is not a directory/media/usama/CRUNCH/RO_Plant/RO_Videos/The BioSand Water Filter.mp4mv: target Filter.mp4 is not a directory
Trimming Filenames from the end
bash;rename
Since your file names contain spaces, you need to quote them before passing them to mv in order to avoid word splitting: ... mv $filename $Out ...