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
What is shell variable?
Is shell scripting a language?
How to print the first array element?
What is the use of .sh file?
What is sudo command?
How do I run a shell script in powershell?
What exactly is a shell?
What is the difference between bash and shell?
How does shell scripting work?
What command needs to be used to take the backup?
How to check if the previous command was run successfully?
Is powershell a language?
What are the zombie processes?
What is console line?
How many fields are present in a crontab file and what does each field specify?