Find the answer to your Linux question:
Results 1 to 3 of 3
I have the following script which is supposed to remove directories after reading a file with the directories list. Though it prints the directores, it always removes the last directory ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    2

    Remove directories in a For Loop


    I have the following script which is supposed to remove directories after reading a file with the directories list. Though it prints the directores, it always removes the last directory (54515) keeping the first 2 intact. Any help is highly appreciated.


    dirnames=`cat filename.csv`

    for i in $dirnames; do

    echo $i
    rm -rvdf /home/mydir/$i

    done



    Contents of filename.csv

    56231
    25265
    54515

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    478
    welcome to the forum

    try it like this--

    for i in `cat filename.csv`; do
    echo $i
    rm -rvdf /home/mydir/$i
    done
    the sun is new every day (heraclitus)

  3. #3
    Just Joined!
    Join Date
    May 2008
    Posts
    2

    remove directories in a for loop

    Thanks for the reply. I found an issue with the .csv file. which has a carraige return at the end of each folder. So I used 'tr' to remove the '\r' at the end of the file name and the scipt worked. Thanks once again.

    Nrupendra

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •