Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hope someone have script or can show me how to write a short script file to read file (text) contains a list of directories name and delete everything in it.
There are 10,000 directories - So there is NO WAY I can do manually. Hope some expert out there has a scripts in place. That would be greatly appreciated.
You'll have to look into the find command. You wouldn't even need to write a script to just delete directories and there contents if that's what you want to do. Have a look at the man page for starters.
Code:
man find
If like you said you have a file that contains a list of the directories, then you'll only need to write a script to loop through the file, check if the directory exists and delete it (and it's contents).
You'll need to put in the work and when you encounter problems with it, then you come to LQ to ask for help. Don't expect LQ users to give you ready made solutions.
If you already have a file with all the directories a command like
Code:
for name in `cat dirlist`; do rm -rf $name; done
Note1: Make sure the directory names in your dirlist have complete path specifications or that your current directory is the one that contains all the directories you want to remove.
Note2: Make sure you understand what you are doing before you issue above command. Because rm will remove the directories and its contents with only a very, very small and painful chance to recover them.
Distribution: Ubuntu, played with Puppy Slitaz & OpenSUSE
Posts: 40
Rep:
Hi
If I'm manipulating large numbers of files or directories I normally use a command which outputs the required command lines (for example using echo "rm -rf ..."). I can then redirect the output to a file with ">", check that the file contains sensible commands, and then run the file.
This way has saved me from more than a few mistakes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.