LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-09-2004, 01:40 PM   #1
mattyk1026
LQ Newbie
 
Registered: Jun 2004
Posts: 4

Rep: Reputation: 0
Cutting in Bash???


I have a project that I am working on for work. I have never used BASH before, but I have to use it for this particular project. What I need to do is to look in a specific directory and then remove all of the files that are older than 5 days old. The file names consist of this: MDC__2004127_012_01.pos, so what I need to do is to cut this file name and get the date, then compare that to the current date and then remove it if it is older than five days from the current date. So, here is what I have so far:

# !/usr/bin/bash
#
# This script remotely deletes .pos files older than 5 days from $see_data_pvat
#

# setup variables
#

set olddir=$cwd
set td=`date -u +%Y%j`
set prevday5=`csh -f $see_batch/get_prev_yyyydoy.csh $td 5`

set thisdir=/home/tethys/kellym/projects/bash/temp_pos
cd $thisdir

set temp=`ls *.pos`

for file in ${temp}
do

So, I don't have very much right now. I am stuck at the part where I need to cut the file name to just get the date out of the file. How do you do this? Do you use cut? Any suggestions how to finish this project? Thanks a lot in advance!!!

Matt
 
Old 06-09-2004, 01:43 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
find will do that in one line
Code:
find /somedirectory -name \* -mtime -5 -exec rm -f {} \;
Make sure you understand what you're doing before you clobber 1000 files by accident.
 
Old 06-09-2004, 01:49 PM   #3
mattyk1026
LQ Newbie
 
Registered: Jun 2004
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks a lot, can you specify though

Can you just tell me what all of the options are in this line.
find /somedirectory -name \* -mtime -5 -exec rm -f {} \
What is -name, -mtime, -exec, and -f? Thanks
 
Old 06-09-2004, 02:07 PM   #4
mattyk1026
LQ Newbie
 
Registered: Jun 2004
Posts: 4

Original Poster
Rep: Reputation: 0
Here is the error that I get when I enter the following command:
Command:
find /home/tethys/kellym/projects/bash/temp_pos -name *'.pos' \* -mtime -5 -exec rm -f {} \
Error:
find: bad option MDC__2004127_012_01.pos
find: path-list predicate-list

How do I fix this?
 
Old 06-09-2004, 02:23 PM   #5
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
*'.pos'

Why have you put in the ' ' marks around pos?
find /home/tethys/kellym/projects/bash/temp_pos -name \*.pos -mtime -5 -exec rm -f {} \;

would be the command, surely (and you missed the ; off the end)
 
  


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
[bash] cutting text with sed Erhnam Programming 3 02-11-2005 05:31 AM
SBC is cutting out BajaNick General 0 06-27-2004 01:32 AM
Cutting with a Blender lectraplayer Linux - Software 6 02-07-2004 08:28 PM
mozilla 1.4 cutting out patrickfreen Red Hat 2 10-08-2003 11:57 AM
rpm2tgz not cutting it Kellvyn Slackware 2 07-28-2002 03:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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