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 ...
- 07-27-2009 #1Just 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
- 07-27-2009 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
welcome to the forum
try it like this--
for i in `cat filename.csv`; do
echo $i
rm -rvdf /home/mydir/$i
donethe sun is new every day (heraclitus)
- 07-27-2009 #3Just 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


Reply With Quote