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
c program which behaves like a shell(command interpreter). it has its own prompt say "NewShell$".any normal shell command is executed from your shell by starting a child process to execute a system program corrosponding to the command
What is the first line of a shell script called?
How to get script name inside a script?
What is shell geeksforgeeks?
Using set -A write a script to print the output of the ls command in 5 columns with two spaces between each column. Pretend that ls does not have multicolumn output.
How do I start a shell script?
What language is used in terminal?
Please give me example of " at command , contrab command " how to use
write a shell script to generate a alert ? like when ur birthday came then generate a alert ur birthday is today like that ?
How do I run a script from command prompt?
What is echo $shell?
I want to create a directory such that anyone in the group can create a file and access any person's file in it but none should be able to delete a file other than the one created by himself.
What is the difference between break and continue commands?
c program the catches the ctrl-c(SIGINT) Signal for the first time and prints a output rather and exit on pressing Ctrl-C again
Is shell scripting easy to learn?