I have folder named 'data' in the terminal folder. Some of the file names in data have a ',' in them. I am able to list them by

$ cd data
$ ls -i |grep -E '\,'

But I don't know how to remove ',' from those filenames. From my research I tried something like grep -E '\,' | sed ',' but it did not work. If I can't remove the commas from the file filenames, I am willing to delete those files but I can't delete them either (it says no such file or directory) on terminal folder or with the command line using rm.

1 Answer 1


Using the bash shell, you could loop over all of the filenames that have a comma in them and rename them to remove all the commas:

for f in *,*; do mv -- "$f" "${f//,/}"; done

With a sample run:

$ touch foo,bar a,b,c,d
$ ls
a,b,c,d  foo,bar

The results are:

$ for f in *,*; do mv -- "$f" "${f//,/}"; done
$ ls
abcd  foobar

This will clobber any destination filenames that already exist.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.