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
Why are shell scripts used?
What are scripts in psychology?
What is sh in shell script?
How do you find out What is your shell?
What shell is bin sh?
What is path variable bash?
Write a shell script to get current date, time, user name and current working directory.
one folder contains lot of students name but I want to fetch hello with every student name individually using shell script
What is bash command used for?
How do I debug a shell script?
How do you know which shell I am using?
What are the various stages of a linux process it passes through?
What will happen to my current process when I execute a command using exec?
How do I edit a .sh file?
What are the 3 standard streams in linux?