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
How to pass an argument to a script?
What is @echo off?
What is a command line shell?
What exactly is a shell?
Explain about return code?
How can the contents of a file inside jar be read without extracting in a shell script?
How do you create a shortcut in linux?
I have 2 files and I want to print the records which are common to both.
What is the command to find out users on the system?
How do you debug a script?
what is tickets $ what low,medium,high priorite pls define time also
shell script for reverse the string
How to check if a directory exists?
madhar chod unix ke 10 commands dhang se likh nahi sakta hai
Suppose you execute a command using exec, what will be the status of your current process in the shell?