Logo 
Search:

Unix / Linux / Ubuntu Articles

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

Write shell script that takes a file name as an argument and deletes this file from every directory above the pwd

Posted By: Raimundo Fischer     Category: Unix / Linux / Ubuntu     Views: 9528

Write shell script that takes a file name as an argument and deletes this file from every directory above the pwd.

Code for Write shell script that takes a file name as an argument and deletes this file from every directory above the pwd in Unix / Linux / Ubuntu

if [ $# -eq 0 ]
then
        echo "pass the file name"
        exit
fi
fl=$1
ch=1
h=/home

while [ $ch -eq 1 ]
do
        cd ..
        p=`pwd`
        echo "$p/$fl"
        rm `echo "$p/$fl"` 2> /dev/nullif [ $p = $h ]
        then
                ch=0
        fi
done

--------------------------------------------------------------------------------

OUTPUT:
[mca264@gama shellscript]$ sh 35.sh file1
/home/symca/mca264/file1
/home/symca/file1
/home/file1
  
Share: 



Raimundo Fischer
Raimundo Fischer author of Write shell script that takes a file name as an argument and deletes this file from every directory above the pwd is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
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!