Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove single quotes from file names

Tags:

linux

bash

The files that come in have spaces, single quotes, brackets, square brackets etc.

I remove spaces and replace with dots with the following command

for file in *.mp4; do mv "$file" `echo $file | tr ' ' '.'` ; done

Then I remove special characters with the following command

rename -n 's/[^a-zA-Z0-9_-]//g' "$file"

But for some reason single quotes(') are still present in file names. Is there a way to have clean file names in one command?

like image 794
Andy Avatar asked Nov 21 '16 19:11

Andy


1 Answers

In bash:

for file in *.mp4; do dest="${file//[[:space:]]/.}" && mv -i "$file" "${dest//[^[:alnum:]._-]/}"; done
like image 53
nabin-info Avatar answered Sep 23 '22 01:09

nabin-info