Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Write a shell script to search all files and rename them such that they do not contain the shell PID.

Posted By: Idelia Miller     Category: Unix / Linux / Ubuntu     Views: 4005

Suppose a user has renamed some files in a current directory using a command like mv filename filename.$$. Write a shell script to search all files and rename them such that they do not contain the shell PID.

Code for Write a shell script to search all files and rename them such that they do not contain the shell PID. in Unix / Linux / Ubuntu

a=`echo $$`
echo $a

ls | grep $a > mvl.lst
c=`wc -l mvl.lst | cut -d " " -f 1`

while [ $c -gt 0 ]
do
    old=`sed  '1q' mvl.lst`
    new=`sed '1q' mvl.lst | cut -d "." -f 1`
    mv $old $new
    sed '/'$old'/d' mvl.lst > mv1.lst
    mv mv1.lst mvl.lst
    c=`expr $c - 1`
done
  
Share: 



Idelia Miller
Idelia Miller author of Write a shell script to search all files and rename them such that they do not contain the shell PID. is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in Unix / Linux / Ubuntu:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!