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

Write the syntax for "if" conditionals in linux?

836


What language is bash written in?

781


What is c in shell script?

830


What is difference between bash and shell?

777


What is the command to find out today's date?

872


How do scripts work?

817


I want to connect to a remote server and execute some commands, how can I achieve this?

818


What is shell company all about?

773


How will you copy a file from one machine to other?

786


How are shells born?

749


What is shell and shell script?

810


Write a command sequence to find the count of each word?

767


Can you write a script to portray how set –x works?

786


What is a shell script in windows?

805


Write down the syntax for all the loops in shell scripting.

891