How to rename all the files in a folder having specific
extension?
Example: I have some files with extension (.txt) in a folder
name 'Test'. I have to rename all the .txt files in a test
and its subdirectories to .my extension.
Answer Posted / vipin
The script given below may work properly.
find command is used to search in all the subdirectories.
basename will extract only filename with .txt extension from
absolute path of file.
cut command will print opnly filename without extension.
mv command is uset to rename.
#!/bin/bash
for i in $(find -name \*.txt)
do
mv $i $(echo `basename $i` | cut -d . -f 1).my
done
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
Is shell scripting difficult?
What can scripts do?
Suppose you execute a command using exec, what will be the status of your current process in the shell?
What is web script?
What is bash command used for?
How to print pid of the current shell?
What is computer cli?
How to calculate the number of passed arguments?
What is echo $shell?
Is powershell a language?
What does .sh file contain?
How to check if a directory exists?
How to write a function?
What is k shell?
How do I set bash as default shell mac?