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
What is the difference between grep and egrep?
What is shell company all about?
Write down the syntax of "for " loop
How do I run a powershell script?
What is the way to do multilevel if-else's in shell scripting?
Explain about debugging?
What is a shell? · Types of shell · what is shell scripting?
What can scripts do?
shell script for reverse the string
How to replace following lines, catch (DAOException e) { objLogger.error(this.getClass () + "addUpdateIssues() " + e); throw new BOException(5122); } catch (BOException e) { objLogger.error(this.getClass () + "addUpdateIssues() " + e); throw e; } catch (Exception e) { objLogger.error(this.getClass () + "addUpdateIssues() " + e); throw new BOException(5122); } Needs to be changed in to, catch (DAOException e) { AppException.handleException (null, null, e, null, null, null, "BOException", this.getClass() + "addUpdateIssues() ", null, null, null, null, null, null, null, null, 5122); } catch (BOException e) { AppException.handleException (null, null, null, e, null, null, "BOException", this.getClass() + "addUpdateIssues() ", null, null, null, null, null, null, null, null, 0); } catch (Exception e) { AppException.handleException (null, null, null, null, null, e, "BOException", this.getClass() + "addUpdateIssues() ", null, null, null, null, null, null, null, null, 5122); }
What is shell scripting used for?
Which is better perl or shell scripting?
Explain about non-login shell files?
How to find duplicate record in file using shell script?
What is echo in shell?