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 ms powershell?
write a shell script to check the failed jobs?
What does it mean by #!/Bin/sh or #!/Bin/bash at the beginning of every script?
c program to display the information of given file similar to givan by the unix or linux command ls -l
i have 2 tables 4 colums table 1 respective values a1 6, a2 8,a3 9,a4 14 & table 2 respective values a1 6, a2 8, a3 9, a4 12. if compare 2 tables 3 colums values same then 4th column values 1)Qes diff >5 then (5 * diff value ) 2)Qes diff <5 the 5 3)Qes diff 5 then 5 print respective values..
What is a batch file used for?
I want to connect to a remote server and execute some commands, how can I achieve this?
What is an sh file?
What does $1 mean in bash?
How will you pass and access arguments to a script in linux?
State the advantages of shell scripting?
What is shell and shell script?
Is cmd a shell?
What is awk in shell script?
What is batch file programming?