Sponsored Content
Top Forums Shell Programming and Scripting Files with 0 file size and created today Post 302260766 by jim mcnamara on Friday 21st of November 2008 02:47:52 PM
Old 11-21-2008
hmm. Are you on solaris - is there a modern version of touch in the xpg4 directory?

If all else fails -- Here is some older code that sets filetimes. You can try it.
Code:
/* 	mytouch.c  set file mtime & atime        
   	usage: mytouch newfiletime  [file ... ]
   	      source | mytouch newfiletime
	where newfiletime is ONLY one of
	YYYY-mm-dd or today or yesterday
	POSIX.1 version
*/
#define  _INCLUDE_POSIX_SOURCE
#include <utime.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include <errno.h>
#ifndef PATH_MAX
#define PATH_MAX _POSIX_PATH_MAX
#endif
static char *fmt="%Y-%m-%d";

void usage()/* error message */
{
	fprintf(stderr,"%s%s%s",
		"usage: mytouch newfiletime  [file ... ]\n",
		" where newfiletime is ONLY one of: \n",
		"  YYYY-mm-dd (YYYY is 1970-2037)\n  today\n  yesterday\n");
	exit(1);
}

char *today(int which)  /* yesterday & today only */
{
	static char t[80]={0x0};
	time_t lt=time(NULL)-(86400 * which);

	struct tm *tmptr=localtime(&lt);
	(void)strftime(t, sizeof(t), fmt, tmptr);

	return t;
}
/* create struct tm for date desired*/
time_t conv(const char *tspec)
{
	struct tm tms;
	char tmp[80]={0x0};
	int yr=0;

    strcpy(tmp, tspec);
	if(strcmp(tmp, "today")== 0)
		strcpy(tmp, today(0));
	if(strcmp(tmp, "yesterday")== 0)
		strcpy(tmp, today(1));
	yr=atoi(tmp);	
	if( yr > 2037 || yr < 1970 || strptime(tmp, fmt, &tms)==NULL)
		usage();

	return mktime(&tms);
}
/* check file existence && create - set mtime && atime*/
void set_utimes(char *filespec, struct utimbuf *ut)
{	
	FILE *tmp=NULL;

	if(access(filespec, F_OK)== -1 )
	{
		tmp=fopen(filespec, "a");
		if(tmp!=NULL)
			(void)fclose(tmp);
		else
		{
			perror("Cannot create file");
			exit(1);
		}
	}
	if(utime(filespec, ut)== -1)
	{
		perror("File access error");
		exit(1);
	}
}

char *check(char *value, const size_t len) /*limited validation*/
{
	if(*value && memchr(value, 0, len + 1)!=NULL)
	{
		char *p=strchr(value, '\n');
		if(p!=NULL) *p=0x0;
		for(p=value; *p && isprint(*p); p++);
		if(*p)
			usage();
		return value;
	}
	usage(); /* everything else is an error */
}

int main(int argc, char **argv)
{
	char filename[PATH_MAX]={0x0};
	int i=0;

	if(argc > 1)
	{
		time_t when = conv(check(argv[1], 10 ));
		struct utimbuf ut={when, when};
		if(argc > 2)
			for(i=2; i < argc; i++)
			   set_utimes(check(argv[i], PATH_MAX), &ut);

		if(argc == 2)
			while(fgets(filename, sizeof(filename), stdin)!=NULL)
                set_utimes(check(filename, PATH_MAX), &ut);
	}
	if(argc== 1)
		usage();

	return  0;
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Archiving Files by selecting years file created

I have recently taken on a new position and want to clean up several file locations that currently hold data back through 1999. While I need to keep this data for business reasons, I have created directories to help sort out the individual years. Is there a quick command that I can use to archive... (2 Replies)
Discussion started by: dmhammond
2 Replies

2. UNIX for Dummies Questions & Answers

To list all the files created today with directory path

Hi, Can any one tell the command to list all the files that are created as of today from all the directories? The Command "ls -ltR" is listing all the files. But I want the list of files that has been created as of today along with the directory path:) Thank you in advance.:) Regards,... (4 Replies)
Discussion started by: meetusha.b
4 Replies

3. Shell Programming and Scripting

Calculate Files Created Today

I need to figure out how to get all the files from a certian dir ./123/*sat files and ./230/*sat files and several other directories which have these *sat files in them. I need to calculate how many were created today and how many yesterday from 2:00 pm on the 28th to 2pm on the 29th. It's a... (1 Reply)
Discussion started by: xgringo
1 Replies

4. UNIX for Advanced & Expert Users

AT can't be created for you. Max size of the queue is reached..

I have a listener (a batch job written in shell script) that calls a perl file (say apple.pl). The listener runs at scheduled timing (say 11 pm to 6 am)&. Owner of the listener is a common id. My question is.. Once the listener starts running (here, Im NOT attempting to generate any reports... (1 Reply)
Discussion started by: vavjeeva
1 Replies

5. Shell Programming and Scripting

ftp - How to download files which created today?

Hello experts, I have written following script to download files which created today. Unfortunately, it's not working. test.ksh: #Defining variables USR='xxx' PASSWD='yyyy' HT='test.test.com' FILE='S*.pdf' XFILE=$(echo find . -type f -mtime 0) ZFILE=$(echo ls -tR|grep 'Jun 8')... (14 Replies)
Discussion started by: dipeshvshah
14 Replies

6. Shell Programming and Scripting

check file exists and created today issue

Morning My other issue I have seems very simple but im just not seeing it. I have a script that checks on a remote share to see if the backups for some systems have run. Its as simple as: find /mnt/ukwcs-net-config/WLAN-Controllers/ -mtime -1 -ls | egrep '(cfg)' > wlanlog.txt cut -c 1-92... (4 Replies)
Discussion started by: ltodd2
4 Replies

7. UNIX for Advanced & Expert Users

default size of a newly created folder

Hi all, In linux how to create a directory with specified size, so that it can be used only up to the mentioned size. Actually my question is, whether we can do directory quota in linux. mounting the directory in a partiton will do that, but do we have any other option... (1 Reply)
Discussion started by: anishkumarv
1 Replies

8. Shell Programming and Scripting

How to find files created today in a particular directory?

Dear All, I want a Hp Ux command to find out the files created today in a particular directory or mountpoint. Kindly help. Thanks Bhaskar (10 Replies)
Discussion started by: sudiptabhaskar
10 Replies

9. Linux

List all files created today exclude last one

Hi, ALL thanks in advance, i listed all files using this command ls -ltr $(date +%Y%m%d)*.xmlbut i would like to exclude the last one created ; Best regard MEROUAN Use code tags, thanks. (4 Replies)
Discussion started by: merouan
4 Replies

10. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies
FIND(1) 						      General Commands Manual							   FIND(1)

NAME
find - find files meeting a given condition SYNOPSIS
find directory expression EXAMPLES
find / -name a.out -print # Print all a.out paths find /usr/ast ! -newer f -ok rm {} ; # Ask before removing find /usr -size +20 -exec mv {} /big ; # move files > 20 blks find / -name a.out -o -name '*.o' -exec rm {}; # 2 conds DESCRIPTION
Find descends the file tree starting at the given directory checking each file in that directory and its subdirectories against a predi- cate. If the predicate is true, an action is taken. The predicates may be connected by -a (Boolean and), -o (Boolean or) and ! (Boolean negation). Each predicate is true under the conditions specified below. The integer n may also be +n to mean any value greater than n, -n to mean any value less than n, or just n for exactly n. -name s true if current filename is s (include shell wild cards) -size n true if file size is n blocks -inum n true if the current file's i-node number is n -mtime ntrue if modification time relative to today (in days) is n -links ntrue if the number of links to the file is n -newer ftrue if the file is newer than f -perm n true if the file's permission bits = n (n is in octal) -user u true if the uid = u (a numerical value, not a login name) -group gtrue if the gid = g (a numerical value, not a group name) -type x where x is bcdfug (block, char, dir, regular file, setuid, setgid) -xdev do not cross devices to search mounted file systems Following the expression can be one of the following, telling what to do when a file is found: -print print the file name on standard output -exec execute a MINIX command, {} stands for the file name -ok prompts before executing the command SEE ALSO
test(1), xargs(1). FIND(1)
All times are GMT -4. The time now is 08:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy