need to create a file with its name having system date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to create a file with its name having system date
# 1  
Old 10-17-2006
need to create a file with its name having system date

Hi,

Iam new to unix . I need to write a scritp which can create a file having sysdate as a part of it.and i also need to delete file which is created five days before in a directory.pls Help me out

thanks in advance
# 2  
Old 10-17-2006
this will help you to create a filename that contains system date:

Code:
touch  my_file`date +%d-%m-%Y`contains_date

# 3  
Old 10-17-2006
Thanks for the info.but how can i delete files in a directory that are created 5 days back.....
# 4  
Old 10-17-2006
/usr/bin/find "Directory Path" -type f -mtime +5 -exec /bin/rm -f {};

Ex: /usr/bin/find /home/justsam -type f -mtime +5 -exec /bin/rm -f {};

Note: The above deletes only the files (mentioned by the type switch) in the directory /home/justsam wich are older than 5 days (mentioned by -mtime). If you want to delete files older than 3 days, make it -mtime +3

Last edited by justsam; 10-17-2006 at 08:32 AM.. Reason: Changing the path
justsam
# 5  
Old 10-17-2006
Thanks i want to delete a file based on the created time not modified.Will the above command works for this.

For ex if i modify a file which was created five days earlier will it also gets deleted
# 6  
Old 10-17-2006
the mtime option of find command lets you select files based on their time of modification.

the atime option of find command lets you select files based on their time of access.

as far as i know, find command does not give you any option to select files based on time of creation.

do man find to know more.
# 7  
Old 10-18-2006
Hello

Hello,

Just an addition to the question , can u pls tell if i want to find files created in last 20 mins then which find option should be used as i was not able to detect in man find.

KRgs,
Aparna
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

3. Shell Programming and Scripting

Compare the system date with date from a text file

I get the date that's inside a text file and assigned it to a variable. When I grep the date from the file, I get this, Not After : Jul 28 14:09:57 2017 GMT So I only crop out the date, with this command echo $dateFile | cut -d ':' -f 2,4The result would be Jul 28 14:57 2017 GMT How do I... (3 Replies)
Discussion started by: Loc
3 Replies

4. Shell Programming and Scripting

Replacing Date in the file with Create date and timestamp

Hello, I have files that with a naming convention as shown below. Some of the files have dates in the file name and some of them don't have dates in the file name. imap-hp-import-20150917.txt imap-dell-gec-import-20150901.txt imap-cvs-import-20150915.txt imap-gec-import.txt... (8 Replies)
Discussion started by: Saanvi1
8 Replies

5. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

6. UNIX for Dummies Questions & Answers

For create file system.

How many ways and how we can create unix file system in sun solaris? (1 Reply)
Discussion started by: anupdas
1 Replies

7. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies

8. UNIX for Dummies Questions & Answers

How to create a new file system

Is there any URL or procedure to create a new file system on solaris 8/9/10.. (3 Replies)
Discussion started by: tintedwindow
3 Replies

9. SCO

create a new file system

I have just installed 5.0.7 of openserver and forgot to create a /u filesystem. I have a root filesystem that takes up most of the hard disc space and I want to reduce the size of that and create a /u. I have tried divvy amd mkdev fs but to no avail. Could somebody give me some idea as to how I... (2 Replies)
Discussion started by: rongrout
2 Replies

10. UNIX for Dummies Questions & Answers

file date vs. system date

Hey all, I know there was a post on here at one point about how to get file properties such as create time and such, but I've searched high and low without success. What I need to do is create a script that runs daily that will expire or remove files that are older than 1 month, or possibly a... (8 Replies)
Discussion started by: ober5861
8 Replies
Login or Register to Ask a Question