LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-26-2016, 12:36 PM   #1
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Rep: Reputation: 169Reputation: 169
Delete files using a text file


When I run this:
Code:
for f in $(delete.txt) ; do 
  rm -f $f
done
I get this. What is wrong ?

Quote:
# Delete_List.sh
/root/Scripts/Delete_List.sh: line 7: /root/Scripts/delete.txt: Permission denied
 
Old 06-26-2016, 12:52 PM   #2
Keruskerfuerst
Senior Member
 
Registered: Oct 2005
Location: Horgau, Germany
Distribution: Manjaro KDE, Win 10
Posts: 2,199

Rep: Reputation: 164Reputation: 164
Then check the file permisssions of you script.

Must be executable.

chmod +x <file>.
 
Old 06-26-2016, 01:16 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
Script is executable.
 
Old 06-26-2016, 01:39 PM   #4
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
I found this and it works.

Quote:
xargs rm </root/Scripts/delete.txt
 
Old 06-26-2016, 01:46 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,242

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
Code:
while read f; do
    rm -f $f
done < delete.txt
 
Old 06-26-2016, 02:02 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by Fixit7 View Post
When I run this:
Code:
for f in $(delete.txt) ; do 
  rm -f $f
done
I get this. What is wrong ?
You meant
Code:
for f in $(cat delete.txt) ; do
But the xargs, or while read solutions are better.
 
1 members found this post helpful.
Old 06-26-2016, 03:17 PM   #7
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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Rm use text file to delete files Fixit7 Puppy 4 01-18-2016 10:10 PM
[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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:56 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