+5 votes
in Operating Systems by (40.5k points)
edited by
I want to remove the file extension from all ".txt" files in a folder. What bash command should I use to do this?

1 Answer

+2 votes
by (346k points)
selected by
 
Best answer

Since you want to remove ".txt" from all text files in a folder, you can use the "mv" command with the "for" loop.

  • "cd" to the folder of those files.
  • run the following command on the terminal.
for file in $(ls *.txt);  do mv "$file" "${file%.*}" ; done

...