|
21 October 2009
Posted in
Linux tutorials -
Frequently Asked Questions
Q : How to remove all emply folders from command line ?
A : There is a good way to remove all emply folders in 1 command , everything will be done using a script so please copy the script bellow to a file with name script then make it executable : +x
chmod +x script
then execute the script with
./script path
the script will give you the choice to edit and the approuve the folders found before removing
Â
#!/bin/bash
#Author : Mohamed Clay
clear
echo By : Mohamed clay
echo
if [ $# = 1 ]
then
touch My_Empty_Directories
echo > My_Empty_Directories
echo The directories below are empty : >> My_Empty_Directories
echo >> My_Empty_Directories
for name in `ls -p $1 | grep /`
do
ls -l $1$name | grep 'total 0'
if [ $? = 0 ]
then
ls -l $1$name | grep d
if [ $? = 1 ]
then
hide=`ls -al $1$name | grep . | wc -l`
if [ $hide != 4 ]
then
echo $1$name >> My_Empty_Directories
fi
fi
fi
done
line=`cat My_Empty_Directories | wc -l`
if [ $line = 3 ]
then
echo
echo No empty directorie has been found
echo
rm -rf My_Empty_Directories
else
cat My_Empty_Directories
echo 'Do you want to delete them (yes/no/edit):'
read answer
if [ $answer = yes ]
then
rm -rf `cat My_Empty_Directories`
rm -rf My_Empty_Directories
echo Successfully done
fi
if [ $answer = edit ]
then
nano My_Empty_Directories
rm -rf `cat My_Empty_Directories`
rm -rf My_Empty_Directories
echo Successfully done
else
rm -rf My_Empty_Directories
fi
fi
else
echo Usage : ./script PATH
fi
#END
Â
Â
please enjoy and report if any errors or comments
Â
Â
| < Prev | Next > |
|---|


Thank you hasak. I had a look at Open...
Haloo ,guys ,after all restarts or sw...
I don't think this uses AppleTalk ...
I only have to express my warmest con...
Is not a copy man, this is an opensou...
can you provide credits to the origin...
Thanks, I am using VortexBox as a NAS...