LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Puppy
User Name
Password
Puppy This forum is for the discussion of Puppy Linux.

Notices


Reply
  Search this Thread
Old 01-18-2016, 07:53 PM   #1
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Rep: Reputation: 169Reputation: 169
Rm use text file to delete files


I had an ark installation that did not work and left many files in it's wake.

I have a list of files to delete.

Is there a way for rm to use that list to delete the files ?
 
Old 01-18-2016, 09:19 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,337
Blog Entries: 28

Rep: Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144
Yes, but depending on the number of files, it might be time-consuming:

Code:
rm /path/to/file    <---remove an individual file
rm -r /path/to/directory   <----remove a directory and its contents recursively
If the list of files contains the paths to the files in question, it might be possible to script something so that you could start the script and walk away.

If the list of files does not include the paths to them, you can use the locate command to find them.

Depending on the ownership of the files, you may have to be root to do this.

Last edited by frankbell; 01-18-2016 at 09:21 PM.
 
Old 01-18-2016, 09:40 PM   #3
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Quote:
Originally Posted by frankbell View Post
Yes, but depending on the number of files, it might be time-consuming:

Code:
rm /path/to/file    <---remove an individual file
rm -r /path/to/directory   <----remove a directory and its contents recursively
If the list of files contains the paths to the files in question, it might be possible to script something so that you could start the script and walk away.

If the list of files does not include the paths to them, you can use the locate command to find them.

Depending on the ownership of the files, you may have to be root to do this.
Thanks.

Puppy Linux always runs as root.
 
Old 01-18-2016, 09:52 PM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
If it's a list of files with full paths:
Code:
rm $(cat listing_file) </dev/null
or, if the list is so large that the argument list becomes too long:
Code:
xargs rm <listing_file
The "</dev/null" redirection in that first option is so that you don't get prompted for files without write permission. It's not needed in the second option since stdin for the rm command will already be /dev/null.

If the list includes directories, then you would be better off using find with the "-delete" action, which works for both files and directories:
Code:
find $(cat listing_file) -delete
but I don't know how you could get the xargs version of that to work.
 
Old 01-18-2016, 10:10 PM   #5
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Want to delete the image files from a directory which are not listed in a TEXT file praveen.vp Programming 6 08-03-2015 10:30 AM
How to delete files keeping the files listed in a text file -urgent jeesun Linux - General 4 10-21-2011 11:28 AM
Delete line of text from text file via shell? zizou86 Programming 3 01-13-2010 11:25 AM
text match pipe to file then delete from original text file create new dir automatic tr1px Linux - Newbie 6 09-10-2008 09:40 PM
delete all files with certain text dougp23 Linux - General 3 04-21-2008 01:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Puppy

All times are GMT -5. The time now is 07:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration