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
Write the syntax for "if" conditionals in linux?
What language is bash written in?
What is c in shell script?
What is difference between bash and shell?
What is the command to find out today's date?
How do scripts work?
I want to connect to a remote server and execute some commands, how can I achieve this?
What is shell company all about?
How will you copy a file from one machine to other?
How are shells born?
What is shell and shell script?
Write a command sequence to find the count of each word?
Can you write a script to portray how set –x works?
What is a shell script in windows?
Write down the syntax for all the loops in shell scripting.