'How to change filetype of all files within a directory in bash
I have a directory called letters an a bash script at the same level. What I want to do is change all docx files to txt. As a first step I tried to use the find command to list every docx file. My script is:
#!/bin/bash
letters_dir="$(cd "$(dirname "./letters")"; pwd)/$(basename "./letters")"
$files_docx=$(find $letters_dir -type f -iname "*.docx")
for $file in $files_docx; do
echo $file
done
The error I'm getting is
./05.sh: line 5: =/media/gdisk/Documents: The file or directory does not exist ./05.sh: line 9: `$file': is not a valid identifier
I also tried passing the relative directory to the find command. Like this:
$files_docx=$(find letters -type f -iname "*.docx")
But I get the same result
Solution 1:[1]
Using command rename on ubuntu
$ sudo apt install rename
rename 's/\.docx$/\.txt/' *.docx
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ufopilot |
