LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 10-15-2011, 05:37 PM   #1
Joufu
LQ Newbie
 
Registered: Oct 2011
Posts: 3

Rep: Reputation: Disabled
bash script that shows date of a file


Hello, I need some help from you guys ;] Can someone help me write a bash scrip? Basically I need to write a script, where you input a date and the script shows files older then the inputed date. Can someone help me with this ? :]
 
Old 10-15-2011, 05:56 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Sounds like homework.

What, exactly, are you stuck on? What have you written so far? What isn't working in the script you've written so far?
 
Old 10-15-2011, 06:02 PM   #3
Joufu
LQ Newbie
 
Registered: Oct 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
gues on evrything ;] Should I use DATE or something else for the input and how to serch for a files date, use find or smth else ? ;/

Last edited by Joufu; 10-15-2011 at 06:33 PM.
 
Old 10-15-2011, 06:09 PM   #4
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
http://www.tldp.org/LDP/abs/html/
http://www.linuxtopia.org/online_boo...ripting_guide/
 
1 members found this post helpful.
Old 10-15-2011, 06:38 PM   #5
Joufu
LQ Newbie
 
Registered: Oct 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you for replie dive, but could you be more specific ? I dont have weary much time to study all the content in thouse links ;]
 
Old 10-15-2011, 06:58 PM   #6
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
Type 'man find' in a console.
 
Old 10-15-2011, 07:03 PM   #7
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Welcome to LQ!!!

Could you be more courteous to the people around. We guys are here to help not to spoonfeed. If you are not willing to devote your time to figure out how you can learn then it will not going to work.

Anyways back to your query. As I can understand you want to find out the files which are older than X days.

Here are some tips:

1. find command is capable of finding the files older than X days. Following is the syntax: find / -type f -mtime +X . Where X will be the number of days.

2. You can use read command in your script to get the user input.

3. Basically what you are looking for is to find the difference between the date entered and today's date and then use as an input for -mtime +X

4. Remember you have to keep a track of date, month and year as well. What I mean to say that year changes after every 365 or 366 days so keep that in consideration.

Now, it is upto you how you can figure out how you could do that. Try to create a script and get back to us if you have any query.


Hint: You can get the today's date in variable using the following: TODAY=$(date '%Y%m%d')"

Last edited by T3RM1NVT0R; 10-15-2011 at 07:17 PM.
 
  


Reply



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
Get file modification date/time in Bash script cmfarley19 Programming 16 04-15-2015 06:25 PM
Bash Script to Copy Modification Date from a file to his folder pjgm Programming 12 07-31-2011 08:33 AM
how to increment the date in a file name via bash script tensigh Programming 10 07-23-2010 03:49 AM
Bash Script - adding file modification date to end of filenames in directory themonkman Programming 2 09-01-2009 11:45 PM
Bash script to read file and alter lines depending on create date ChristianHein Linux - General 13 08-04-2007 05:39 AM

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

All times are GMT -5. The time now is 06:52 PM.

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