single line command to delete a 6 months old file

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers single line command to delete a 6 months old file
# 1  
Old 07-28-2009
single line command to delete a 6 months old file

i had this scenario where i need to delete a file that is 6 months old which is no longer needed. basically the filename is in the format of PCARDDAILYmmddyyyy.txt where the mm is the month, dd is the day, and yyyy is the year.


assuming that there is PCARDDAILY05262009.txt and PCARDDAILY07252009.txt files. these files are more than 6 months and needs to be deleted. is there a single command that will delete these files? the reason why i need a single line of command is that i will put this command on a scheduler tool called TIDAL Enterprise Scheduler.

# 2  
Old 07-28-2009
you can make use of find command if you wanna delete them on the basis of creation date rather than filename basis..
# 3  
Old 07-28-2009
please provide an example. thanks.
# 4  
Old 07-28-2009
I mean if you file PCARDDAILY05262009.txt PCARDDAILY05252009.txt
created 6 months back then you can delete them, using find command..
find . -mtime +180 -exec rm -rf {} \;

# 5  
Old 07-28-2009
great thanks. assuming that i have other files that are not in PCARDDAILYmmddyyyy.txt such as EATVDAILmmddyyyy.txt and i am only restricted to delete files that starts with PCARDDAILY*.txt. are other files that resides on the same directory will be deleted with this command:

find . -mtime +180 -exec rm -rf {} \;

# 6  
Old 07-28-2009
i guess that will delete other files other than PCARDDAILYmmddyyyy.txt ...
so try this...

find . -type f -name "PCARDDAILY*.txt" -mtime +180 -exec rm -rf {} \;

# 7  
Old 07-29-2009
that works thanks so much.
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 delete line from file using sed command?

hello Team, I want to delete below linux using sed command but I am getting error.sed -i '/url=/status.cgi?hostgroup=/d' 3 error:sed: -e expression #1, char 32: unknown option to `s' Could you please help me with correct syntax. My line contain / character because of that I am getting... (4 Replies)
Discussion started by: ghpradeep
4 Replies

2. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

3. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 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. Shell Programming and Scripting

delete the line with a particular string in a file using sed command.

Hello, I want to delete all lines with given string in file1 and the string val is dynamic. Can this be done using sed command. Sample: vars="test twinning yellow" for i in $vars do grep $i file1 if then echo "Do Nothing" else sed `/$i/d` file1 fi done Using the above... (5 Replies)
Discussion started by: PrasadAruna
5 Replies

6. Shell Programming and Scripting

how to delete the line if the first letter is a single digit

Hi, I'm trying to acheive the following, I have a dat file in which i have several addresses, If the address starts with a single digit then i have to delete the line, if it starts with 2 or more digits then i have to keep the line Here is a sample of my file: 377 CARRER DE LA... (5 Replies)
Discussion started by: ramky79
5 Replies

7. UNIX for Dummies Questions & Answers

Bash script to delete file input on command line

1) I wrote a script and gave the desired permissions using "chmod 755 scriptname". Now if i edit the script file, why do i need to set the permission again? Didn't i set the permission attribute.. or if i edit the file, does the inode number of file changes? 2) I am running my unix on a server... (1 Reply)
Discussion started by: animesharma
1 Replies

8. Shell Programming and Scripting

delete a single space in a line

hi i have a line like TL1330000000800 000DE9248737900 08000TS0231DE92 87379AMEX0000.T N 0080000000 00000. if there any single space between strings, i need to delete, if more than one keep the space as it is can some one help thanks Satya (1 Reply)
Discussion started by: Satyak
1 Replies

9. Shell Programming and Scripting

Delete files older than 3 months.(read date from the name of the file)

Guys, My log files stored in the date format format below(log_20080714072942): TIMESTAMP=`date +%Y%m%d%H%M%S` LOG=/log/log_${TIMESTAMP}.log I'm looking for a shell script which deletes all files which is older than 3 months from today. Regards, Bhagat (3 Replies)
Discussion started by: bhagat.singh-j
3 Replies

10. Shell Programming and Scripting

Single line file editing command?

Hello everyone. I have been reading a lot about the various different text editors at my disposal through Unix, but I just can't seem to close the deal for what I am trying to do. Is there a way to issue a single line command to edit a file where pattern=x, and do it non-destructively AND in-place?... (1 Reply)
Discussion started by: gator76
1 Replies
Login or Register to Ask a Question