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 / aravind s

basename is the appropriate command to cut the unwanted
string from a filename

for example
$basename unix.txt txt #txt stripped off
unix.
-----------------------
for your problem the solution is

for i in `find . -name '*.txt'`|xargs ls; do
leftname=`basename $i txt`
mv $i ${leftname}doc
done
-----------------------

basename isn't a shell bulletin, but an external command.
The reason why we deal with it here is that it's most
effective when used with the for loop.

Ref: Unix Concepts & Applications - Sumitabha Das

Is This Answer Correct ?    2 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is shell variable?

530


Is shell scripting a language?

584


How to print the first array element?

552


What is the use of .sh file?

608


What is sudo command?

553






How do I run a shell script in powershell?

554


What exactly is a shell?

606


What is the difference between bash and shell?

643


How does shell scripting work?

617


What command needs to be used to take the backup?

528


How to check if the previous command was run successfully?

597


Is powershell a language?

562


What are the zombie processes?

567


What is console line?

572


How many fields are present in a crontab file and what does each field specify?

585