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.
Answers were Sorted based on User's Feedback
Answer / ramit
Hi Nagesh,
Thanks for the reply but I dont think this will work
as $file= myFile.txt
and mv $file $file.my will rename to myFile.txt.my
I found the solution by extracting basedirectory and
filename then renaming it to req. extension.
thanks
| Is This Answer Correct ? | 2 Yes | 4 No |
Answer / 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 |
Answer / bindu
its very simple
try this out
rename .txt .my *.txt
all the files with .txt extension will be converted into .my
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / jks
It can be done using the xargs command of Unix ...
cd to the dir containing the *.txt files
$ls *.txt | xargs -i mv \{\} \{\}.my
| Is This Answer Correct ? | 5 Yes | 15 No |
c program the catches the ctrl-c(SIGINT) Signal for the first time and prints a output rather and exit on pressing Ctrl-C again
How to redirect both standard output and standard error to the same location?
Hi All, Is it possible to create one file name only space or space in file name in UNIX and we can able to run that on Unix?
Write a shell script to check whether a number is Armstrong number or not?
Which shell is the best?
How to add some content in any file at some desired location without using VI or some other editor in UNIX
What is a shell environment?
In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc.
What is the meaning of $1 in shell script?
What is the command to find out users on the system?
What is shell chemistry?
Rewrite the command to print the sentence and convert the variable to plural: echo “i like $variable”.