Forrest logo
back to the for tool

for:ai:430ae

How to remove a suffix like .txt from a number of files in a directory using bash shell
$ for file in *.txt; do mv "$file" "${file%.txt}"; done
try on your machine

This command uses a for loop to iterate through all .txt files in the current directory and removes the .txt suffix from each file by using parameter expansion to remove the suffix.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.

Questions that are answered by this command:

  • how to remove a suffix like .txt from a number of files in a directory using bash shell?
back to the for tool