LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 03-07-2007, 11:50 PM   #1
Nana
LQ Newbie
 
Registered: Mar 2007
Posts: 6

Rep: Reputation: 0
How to delete list of files


Hi everyone

I'm quite new to Linux but still need to get the job done. My email server is running out of disk space.I need to delete some emails direct from the server and my first attempt is to delete emails dedicated to allstaff@mycompanyemail

I've grep the absalute path of those emails and store them into another files like this

grep r allstaff@mycompanyemail* > /tmp/allstaff

Can anybody give the idea on how can i delete those emails by using the information in /tmp/allstaff. Should you have any other way is also can.

Thanks
 
Old 03-08-2007, 12:12 AM   #2
sn68
Member
 
Registered: Oct 2005
Distribution: FC5
Posts: 338

Rep: Reputation: 30
grep –r allstaff@mycompanyemail* | xargs rm

find . -name 'allstaff@mycompanyemail*' | xargs rm
 
Old 03-08-2007, 12:48 AM   #3
sumguy231
Member
 
Registered: Apr 2004
Location: North America
Distribution: Kubuntu 7.04 - Feisty Fawn
Posts: 296

Rep: Reputation: 30
Never mind, misread post...
 
Old 03-08-2007, 01:54 AM   #4
Nana
LQ Newbie
 
Registered: Mar 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by sn68
grep r allstaff@mycompanyemail* | xargs rm

find . -name 'allstaff@mycompanyemail*' | xargs rm
That command will not display anything. How if I want to display what file being deleted and the total size of deleted files? I may want to confirm that it will not delete the wrong file

Thanks
 
Old 03-08-2007, 02:13 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,832

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
If you have them in /tmp/allstaff, presumably you have vetted them there. Simple variation on the above
Code:
cat /tmp/allstaff | xargs rm
 
Old 03-08-2007, 02:43 AM   #6
Nana
LQ Newbie
 
Registered: Mar 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Talking

Quote:
Originally Posted by syg00
If you have them in /tmp/allstaff, presumably you have vetted them there. Simple variation on the above
Code:
cat /tmp/allstaff | xargs rm
Unfortunately, the thing is not as easy as I thought. My grep command was not only return the path but plus other info at the end of it like this

a/b/filename: for <allstaff@mycompanydomain>; Tue, 6 Mar 2007 12:05:41 +0800


I think I may need to remove the unnecessary character before can execute rm command. I'm not good in doing script. Please help

Thanks for your time

____________________________________________________________

I create some files in my own directory and do a test on it first. Hope that could consider BACKUP :>
 
Old 03-08-2007, 03:19 AM   #7
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Quote:
a/b/filename: for <allstaff@mycompanydomain>; Tue, 6 Mar 2007 12:05:41 +0800
To select a/b/filename part from this, use the command
"cut -d':' -f1"
The pipe sequence then becomes: cat | cut | xargs where the cat may be replaced with the grep or find commands.

To make sure that you don't delete anything by accident, you could add the -i option (interactive mode) to rm, which makes it ask for confirmation before actually deleting anything.
You could also use a harmless command, like echo or ls -l instead of the rm at the end of your pipe sequence.

An all-in-one solution could look something like this:
Code:
cat your_file |cut -d':' -f1 > some_filelist #instead of cat, you can also use the grep or find already posted
for i in `cat some_filelist`; do
ls -l ${i}; #get the filesize
rm -i ${i}; #delete it, but with confirmation
done;
 
Old 03-08-2007, 05:10 AM   #8
Nana
LQ Newbie
 
Registered: Mar 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by timmeke
Code:
cat your_file |cut -d':' -f1 > some_filelist #instead of cat, you can also use the grep or find already posted
for i in `cat some_filelist`; do
ls -l ${i}; #get the filesize
rm -i ${i}; #delete it, but with confirmation
done;
Thank you timmeke. It almost solved my problem. However there are few file names with double dot and numbers or characters like this :

a/d/filenamewith':'and'number'or'char':for <allstaff@mycompanydomain>; Tue, 6 Mar 2007 12:05:41 +0800

eg : a/d/fgfg:2,S:To: <allstaff@mycompanydomain>

Actually I don't really know how to use the option for cut command

Thanks
 
Old 03-08-2007, 05:56 AM   #9
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Maybe you can split up the strings on spaces rather than the colons ("double dots")?
eg use cut -d' ' -f1

-d => delimiter character
-f => cuts out certain fields (that are separated by the delimiter)

Note that "cut" only works on single character delimiters. So if we need to split up your lines on let's say the " To: " string, we'll need to look at "sed" or "awk", rather than "cut".
 
Old 03-09-2007, 03:40 AM   #10
Nana
LQ Newbie
 
Registered: Mar 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Ok. Thanks everyone for your time and assistence. I'm done!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
List of arguments too long, need to delete 59,000 files stefaandk Linux - General 4 07-12-2006 03:14 AM
Not delete items in list twantrd Programming 14 05-08-2006 03:15 PM
Delete Linked List Function Mistro116@yahoo.com Programming 6 12-10-2005 03:43 PM
can't access/delete/list files even as root... tenshi Linux - General 7 10-13-2004 05:29 AM
Can't delete or list contents of an old kio_http cache,... JaseP Linux - General 3 06-09-2002 04:00 AM


All times are GMT -5. The time now is 11:58 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration