Delete files older than 1 year through FTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete files older than 1 year through FTP
# 8  
Old 06-26-2012
Quote:
Please post your AIX-compatible code to determine if a file is more than a year old based on a ftp (ls) directory listing.

I'm up for a challenge
Code:
M=$(date +%m)
Y=$(date +%Y )
ls -ln | awk -vY=$Y -vM=$M 'BEGIN {
  split("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",mt,",")
  for(i=1;i<13;i++)p[mt[i]]=i;
}
/^[^d]/ && $8>1970 && ($8 < Y - 1 || $8 < Y && p[$6] < M){ print $9 }'

# 9  
Old 06-27-2012
Quote:
Originally Posted by Chubler_XL
Code:
[...] awk -vY=$Y -vM=$M [...]

Just a side note: AFAIK the -v<varname> (with no space between -v and <varname>) is a GNU awk extension, other awk implementations (new awk etc) support the other version: -v <varname> (with a space).
These 2 Users Gave Thanks to radoulov For This Post:
# 10  
Old 06-27-2012
Quote:
Originally Posted by radoulov
Just a side note: AFAIK the -v<varname> (with no space between -v and <varname>) is a GNU awk extension, other awk implementations (new awk etc) support the other version: -v <varname> (with a space).
Thanks - don't think I've come across this before. Seems having the space might turn out to be more portable.
AIX 5.3 doesn’t have any trouble with the space missing, so it's not exclusively a GNU awk feature.

The usage string certainly shows a space:
Code:
$ awk --version
awk: Not a recognized flag: -
Usage: awk [-u] [-F Character][-v Variable=Value][-f File|Commands][Variable=Value|File ...]
 
$ awk -vPI=3.14159 'BEGIN { print PI }'
3.14159
 
$ csum -h MD5 $(which nawk) $(which awk)
ba598e3a4ccee166aa8efc7ef9a05a2e  /usr/bin/nawk
ba598e3a4ccee166aa8efc7ef9a05a2e  /usr/bin/awk

Also interesting to note that awk and nawk on AIX 5.3 are the same binary
This User Gave Thanks to Chubler_XL For This Post:
# 11  
Old 06-27-2012
Thanks!
I didn't know that non-GNU awk implementations (in this case AT&T) support -v<varname>.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delete all files created in specific year

I have more than 200K files created in year 2017 under directory having size of 50GB. I want to all these files in one shot. Is there any faster option available with find command to delete all these file ? (6 Replies)
Discussion started by: sp23029
6 Replies

2. Shell Programming and Scripting

Deleting dated log files whihc are older than an year

Hi. There is a process which creates log files in the below naming format processname.20140425.log processname1.20140425.log And in this path along with these logs there are other files which have the timestamp from 2012 and i want to have a script in place to delete only the above log files... (13 Replies)
Discussion started by: nanz143
13 Replies

3. Shell Programming and Scripting

Delete files using year

Hi All, how can i delete files from my Unix directory on the basis of year, i have files from 2001 to till 2014, but from their, i have to delete only 2013 file.Below is my file name rwxrwxrwx 1 guopt users 5169 Jul 12 00:30 grt592_20130712003000.SAP Thanks Kki (2 Replies)
Discussion started by: kki
2 Replies

4. Shell Programming and Scripting

Delete all the files and subdirectories for the year 2006

Hi I have lot of files and subdirectories inside a directory which are created in the years 2006, 2007, 2008, 2009 and 2010. I want to delete all the files and subdirectories belonging to the year 2006 alone. How can I do that ? (5 Replies)
Discussion started by: samsungsamsung
5 Replies

5. Shell Programming and Scripting

To delete files older than 24 hrs

I have to retain only 1 day files in my system an I have to delete all the other files which are older than 24 hrs. Please let me know the option I have to give in the find -mtime command. (3 Replies)
Discussion started by: rajesh8s
3 Replies

6. UNIX for Dummies Questions & Answers

Delete files by year

can someone provide a command to delete files by year? I have several files created last year 2009. Im trying to list first ls -lrt | grep '/2009/ {print $10}' by it returns no result. Pls advise (2 Replies)
Discussion started by: lhareigh890
2 Replies

7. Shell Programming and Scripting

ftp only older files

Hi All, I want to get those the files which were created before 20 days. Say, we have two server, remote server and local server. I want to get only 20 days older files from remote server to my local server. I have used following code for ftp: (echo " user ${USERNAME}... (2 Replies)
Discussion started by: priyankak
2 Replies

8. UNIX for Dummies Questions & Answers

Reg: delete older files from ftp

Hi, I want to delete older files from ftp server. (files which are more than 5 days old). Please advice Thanks , sam (3 Replies)
Discussion started by: sam99
3 Replies

9. UNIX for Dummies Questions & Answers

delete compressed files from year 2005

I'm trying to delete files that were created/modified in the year 2005 that we compressed and have the .Z extension on them. I tried using the awk utility but the syntax is incorrect. I don't know how to use a wildcard to capture all the compressed files. Here's the code I used ( ls -lR |... (5 Replies)
Discussion started by: igidttam
5 Replies
Login or Register to Ask a Question