[SOLVED] rm - delete list of files and directories from .txt file?
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.
rm - delete list of files and directories from .txt file?
I have a .txt file with paths to files and directories that i want to delete. Is it possible to use the rm, or other command, and delete the files and folders that are inside this file? Somehow the delete command to be able to read the information from this .txt file.
There is no single command I am aware of. It is simple enough to convert the text file to a script, though, if it contains only the list of full paths to remove. Open a copy of the file for editing in an editor (I use vim, emacs will work, or any number of others). Do a mass search and replace on the lines containing the paths or filenames to add 'rm' and a space at the beginning of each line (or rm -i and a space to be prompted before each removal). Add a 'shebang' (#!/bin/bash) as the first line. Then close the file, chmod to make it executable and execute it. Sounds complicated but really isn't if you know how to do the search and replace in the editor you are using. If you have vim loaded on your computer I can give you a specific list of the actions if you wish and have never done something like this before.
Habitual method is simpler, much simpler, by the way.
For all those using for loops, I hope there is no white space in the names or paths to be deleted .. or this could get ugly from errors or the wrong thing being deleted real fast
There is no single command I am aware of. It is simple enough to convert the text file to a script, though, if it contains only the list of full paths to remove. Open a copy of the file for editing in an editor (I use vim, emacs will work, or any number of others). Do a mass search and replace on the lines containing the paths or filenames to add 'rm' and a space at the beginning of each line (or rm -i and a space to be prompted before each removal). Add a 'shebang' (#!/bin/bash) as the first line. Then close the file, chmod to make it executable and execute it. Sounds complicated but really isn't if you know how to do the search and replace in the editor you are using. If you have vim loaded on your computer I can give you a specific list of the actions if you wish and have never done something like this before.
Habitual method is simpler, much simpler, by the way.
Can i uninstall a package this way? For example, if i run "locate 'package-name' > file.txt" and then convert the file.txt file to script can i uninstall the package manually?
Question would be why you would even want to? Think about it like this, if we used you locate idea on the gawk package for my machine, you would remove 36 files of the 116 installed for that one package.
As you can see, this is not ideal.
Perhaps you could explain further what your actual question is? (as pointed out above the xyproblem is a good read for you)
By a package do you mean an installation from a distribution's repositories? If so and you installed it by that distribution's package manager, you should use that package manager to remove it. If you are talking about something else then as others have asked, exactly what are you talking about? You are starting to edge into areas that could do nasty things to your system if your aren't careful or if someone thinks you are talking about one thing and you are actually asking about something else.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.