Link to home
Start Free TrialLog in
Avatar of aimui
aimui

asked on

Remove Directory With Infinite Sub Directories

Without having to reformat the harddisk, how can i remove a directory with subdirectories, for example m/m/m/m/m/m/m/m............/m/m/m/m/m (more than 300 levels)?

Thanks.
Avatar of ozo
ozo
Flag of United States of America image

rm -r
Avatar of aimui
aimui

ASKER

I have used this command but i get the error message : File name too long!
Try going halfway down the tree and running the command ozo gave you.
There's a few ways to do this.
1- You could find the inode of the dir and write a little
C program or perl to unlink the inode.
2- Try to do a find with the -exec rm arg, not sure this
will work. find will recurse into the subdir and hopefully
the -exec rm args will work at these sub levels.
3- mv dirname /dev/null - Not sure if this work. :))

ASKER CERTIFIED SOLUTION
Avatar of tfabian
tfabian

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
while test -d m; do cd m; done
cd ..
while test -d m; do rmdir m; cd ..; done
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  Or if you are an EE Pro user, click the link below to select open items for your Member ID using Power Search:
https://www.experts-exchange.com/jsp/qPowerSearch.jsp.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
https://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange