Start from the prefixes, delete script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Start from the prefixes, delete script
# 1  
Old 04-07-2011
Start from the prefixes, delete script

My folder is/app2/istech/scratch, which contain all the below files.

I need to delete the files which start from the prefixes.

dup_events_*.*
Event_*.*
New_time_*.*
New_Loc_*.*
New_Uptime_*.*
Detailed_Reason*.*
cmt_dup_*.*
Uptime_*.*

Can anyone please let me know how to write a shell script for this, it would be of great help.

Thanks,
# 2  
Old 04-07-2011
Try:
Code:
find /app2/istech/scratch -type f \( -name "dup_events_*" -o -name "Event_*" -o name "New_time_*" \) -exec rm {} \;

Add the rest of the file prefixes before the red bracket as: -o name "prefix*"
# 3  
Old 04-07-2011
Code:
DIR=/app2/istech/scratch 
if [[ -d $DIR  ]]; then
  cd $DIR 
else
  exit
fi

for str in dup_events_ Event_ New_time_ New_Loc_ New_Uptime_ Detailed_Reason cmt_dup_ Uptime_
do
  find . -name "$str*.*" -exec rm {} \;
done

# 4  
Old 04-08-2011
Thanks for the replies guys, will try and let you know.

Thanks,

---------- Post updated at 09:24 AM ---------- Previous update was at 01:00 AM ----------

find /is/app2/istech/scratch -name '*WORK_SHFT_INS*.*' -mtime +7 -exec rm {} \;
rm: remove write-protected regular empty file `/is/app2/ispara/node1/dataset/ $PROJDEF\\datasets\\_WORK_SHFT_INS_all.ds.NAMFETL.0000.0000.0000.390d.cf55dc49.0000.2b2311e8'? y
rm: cannot remove `is/app2/istech/scratch/ $PROJDEF\\datasets\\_WORK_SHFT_INS_all.ds.0000.0000.0000.390d.cf55dc49.0000.2b2311e8': Permission denied


Iam using the above syntax to delete the files, Iam getting this permission denied error,
Any idea how to resolve this.

Thanks,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do delete certain lines alone which are matching with start and end string values in file?

Hi, In my previous post ( How to print lines from a files with specific start and end patterns and pick only the last lines? ), i have got a help to get the last select statement from a file, now i need to remove/exclude the output from main file: Input File format: SELECT ABCD, DEFGH,... (2 Replies)
Discussion started by: nani2019
2 Replies

2. Shell Programming and Scripting

Remove prefixes before dot

Shell : Bash shell I have a text file with entries like below srv.sr_num sr_number, atvx.ATTRIB_37 Product_Name, ktx.X_ATTRIB_52 Product_Type, mkx.created sr_created_date, nbv.sr_cat_type_cd sr_type, bkrx.sr_area sr_category, .. frx.order_id, des.stats_name , fpxg.current_id_name, ...... .... (3 Replies)
Discussion started by: John K
3 Replies

3. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

4. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

5. UNIX for Dummies Questions & Answers

How to delete all columns that start with a specific value

I have this space delimited large text file with more than 1,000,000+ columns and about 100 rows. I want to delete all the columns that start with NA such that: File before modification aa bb cc NA100 dd aa b1 c2 NA101 de File after modification aa bb cc dd aa b1 c2 de How would I... (3 Replies)
Discussion started by: evelibertine
3 Replies

6. Shell Programming and Scripting

Delete all lines that start with a bigger number of a specific one.

E.g. the file is like this: I want to delete all lines that begin with a number larger than 2, ignoring the lines that doesn't begin with a number! PS:'2' is actually a variable that can have a lot of values:b:i bet you got it (10 Replies)
Discussion started by: hakermania
10 Replies

7. Shell Programming and Scripting

counting prefixes of files

Hello, at the moment I'm on with programming some kind of version history script for network devices. The configration files are uploaded in the form: devicename-confg_date_time. For keeping the last 10 configurations I want to split the devicename from the rest. This works well with... (5 Replies)
Discussion started by: Sally[-_-]
5 Replies

8. Shell Programming and Scripting

need to delete lines that start with letters

Hi, I need to remove all lines from a file that do not start with numbers For instance, if the first three characters on any line are not numbers, delete those lines I've tried to do it with awk and it's not working, any ideas ? Thanks (5 Replies)
Discussion started by: sfisk
5 Replies

9. UNIX for Dummies Questions & Answers

vi editor prefixes lines with # upon paste

I've been away from Unix and the vi editor for a while, and now I'm using vi (actually vim) in a Cygwin bash shell. When I copy-and-paste code examples (I'm playing with perl now) any time I paste code with lines beginning with the # character, vi inserts a # character at the beginning of every... (2 Replies)
Discussion started by: greenmangroup
2 Replies

10. UNIX for Dummies Questions & Answers

Start Up Script

guys/gals...does anyone have a startup shell script for oracle/sybase...meaning at shutdown the databases stop themselves and at start up they start automatically...thanks much... (3 Replies)
Discussion started by: suntan
3 Replies
Login or Register to Ask a Question