Deleting lots of files.....


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting lots of files.....
# 1  
Old 05-25-2006
Question Deleting lots of files.....

Hi All,

Thanks in advance for reading and any posts...

I have to delete a lot of files (about 6 pages of a4 (ls -ltr)) but I have to keep some as well. I would normally do an rm * to get rid of them all, but thats not what I want to do. Is there anyway I could rm * but add in a list of files that I don't want to delete.

Thanks for reading and any posts,

Mark.
# 2  
Old 05-25-2006
put a list of "keeper files" into goodfiles then
Code:
ls -1 | grep -v -f goodfiles | \
while read file
do
       rm -f $file
done

# 3  
Old 05-25-2006
Computer

Thanks for the replay will try making a small shell script with it... thanks Mark...
# 4  
Old 05-25-2006
Lightbulb

When I run that I get the following error:

grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .
[2] + Done(2) ls -1 | grep -v -f goodfiles | \;while read filee

Any ideas????

Thanks again,

B14...aka... marky mark....
# 5  
Old 05-25-2006
Check if your grep supports -v and -f options...

type
Code:
man grep

at the command prompt

If you are on Sun Solaris box, some options are supported by

Code:
/usr/xpg4/bin/grep

and some options are supported by

Code:
/usr/bin/grep

Give the entire path of grep...

See if it works!!
# 6  
Old 06-07-2006
MySQL

yeah it works but under solaris you need to use /usr/xpg4/bin/grep in order to get it to work....

...sorry for the slow response had a few other things that took priotry...

Thanks again,

B14... aka... marky mark
# 7  
Old 06-07-2006
Lightbulb

Come across a possibly simpiler way (un specified way), you can do the following if you want delete old files:

HTML Code:
find [path] -mtime +[integer] -exec rm {} \;
This essentially will allow you delete all files in a directory over a certain age, not sure if this is of interest to anyone but it will sort out my problem, I am guessing that you could do something similar with the above as well so that you can delete a pile of files
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to rename lots of files with find?

Can someone help me with this script. I have a bunch of files like this: "2209OS_02_Code" "2209OS_03_Code" "2209OS_04_Code" "2209OS_05_Code" "2209OS_06_Code" "2209OS_07_Code" "2209OS_08_Code" "2209OS_09_Code" "2209OS_10_Code" "2209OS_10_video" and I want to rename them to be like this: ... (2 Replies)
Discussion started by: siegfried
2 Replies

2. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

3. Shell Programming and Scripting

Lots of sed

Hi, I have 200 lines of sed commands in a shellscript sed s/TSTARTO2GPRSEVENTAPNACCSUM_1/TSTARTO2GPRSEVENTAPNACCSUM_24/g sed s/O2GPRSEVENTAPNACCSUM_1/O2GPRSEVENTAPNACCSUM_24/g sed s/TENDO2GPRSEVENTAPNACCSUM_1/TENDO2GPRSEVENTAPNACCSUM_24/g sed s/BSTARTO2EVENTITEM_1/BSTARTO2EVENTITEM_24/g... (6 Replies)
Discussion started by: legolad
6 Replies

4. Shell Programming and Scripting

Deleting files

Hi all, I have developed a shell script to copy the files from source to destination and simultaneously to delete the copied files in source. I can copy the files but the files cannot be deleted in source side. (3 Replies)
Discussion started by: Venkatesan
3 Replies

5. Shell Programming and Scripting

AIX system.... deleting files in remote directory after retrieving files

Hi Friends, I am new to this , I am working on AIX system and my scenario is to retrive the files from remote system and remove the files from the remote system after retreving files. I can able to retrieve the files but Can't remove files in remote system. Please check my code and help me out... (3 Replies)
Discussion started by: vinayparakala
3 Replies

6. IP Networking

netstat showing lots of errors

Hi, I have a server which receive lots of events to it and when I do netstat -Ie1000g0, I'm seeing the errors as below. Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue e1000g0 1500 abc-1.com abc-1.com 3093708246 12757 92069412 0 0 0 If anyone could direct me to right... (3 Replies)
Discussion started by: mohzub
3 Replies

7. Shell Programming and Scripting

Need help comparing two files and deleting some things in those files!

So I have two files: File1 pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2 pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2 ref4948 1.1 treehouse.txt 1.6 ref8573 1.5 ref3284 1.4 ref5838... (24 Replies)
Discussion started by: linuxkid
24 Replies

8. Programming

problem with lots of open sockets

I'm programming in C with lots of sockets, (asynchronous handling), and for a while it goes ok, but after a while it starts to hang, or not get complete connections anymore. checking my router, i see that i get nat tables overflow and even my DNS cacher seems to be having serious issues... ... (4 Replies)
Discussion started by: alien999999999
4 Replies

9. Red Hat

Lots of questions about linux.

I am about 2 months new to Linux, and have only limited experience with PCLinuxOS, (kde) and Redhat. I am installing the latest version of PClinuxOS on my wife's PC right now but running into a problem I dont understand. I have never seen it before so i thought i'd ask how I can get around it.... (1 Reply)
Discussion started by: Methal
1 Replies

10. UNIX for Dummies Questions & Answers

Lots of file copyingand renaming?

I have Approx 1000 files that all need to be copied from one directory to another. However, each file has to be renamed while it is copied. I have a Tab delimited text file containing all of the old and new file names (they are not all the same character length). Is there a way to read in the... (12 Replies)
Discussion started by: AeroEngy
12 Replies
Login or Register to Ask a Question