LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-20-2011, 01:18 AM   #1
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
Knowing the age of a file


Hi all

Can someone help me with this?
I need to know the 'age' of a file printed in seconds.
So if a file is 60 minutes old, i need to know how much that is in seconds (i know it's 3600 seconds).
But is there a command which i can use to do this? (so the command 'reads' the date and recalculates it in seconds)

Can i do this with the commands date?

thanks in advance


P.S.: which command do i use to know which distro i use?
Code:
# uname -a
Linux wlsdev3 2.6.9-89.ELsmp #1 SMP Mon Apr 20 10:34:33 EDT 2009 i686 i686 i386 GNU/Linux
Code:
# dmesg | head -1
Linux version 2.6.9-89.ELsmp (mockbuild@hs20-bc1-2.build.redhat.com) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-11)) #1 SMP Mon Apr 20 10:34:33 EDT 2009
 
Old 04-20-2011, 01:35 AM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
This is one way:

Code:
echo "$((`date '+%s'`-`stat --printf='%Y' somefile`))"
 
Old 04-20-2011, 01:37 AM   #3
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
oke guys, i think i found something, but i need some clearification

i use this at the moment:
Code:
# find /folder/ -cmin -60
and this is what i get:
Code:
/folder/
/folder/test.txt
which is good, but not good enoug... you see i get two results, the folder where he needs to search (or find) and the folder he found, but i only want the file he found, not the folder (i made the folder a couple of seconds before i made the file, so probably that's my problem, but i'm not sure, so that's my question ... )
 
Old 04-20-2011, 01:39 AM   #4
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
Quote:
Originally Posted by macemoneta View Post
This is one way:

Code:
echo "$((`date '+%s'`-`stat --printf='%Y' somefile`))"
thanks.

I did try it, and i got:
Code:
# echo "$((`date '+%s'`-`stat --printf='%Y' /folder/test.txt`))"
stat: unrecognized option `--printf=%Y'
Try `stat --help' for more information.
-bash: 1303278278-: syntax error: operand expected (error token is "-")
 
Old 04-20-2011, 01:50 AM   #5
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
Quote:
Originally Posted by brownie_cookie View Post
oke guys, i think i found something, but i need some clearification

i use this at the moment:
Code:
# find /folder/ -cmin -60
and this is what i get:
Code:
/folder/
/folder/test.txt
Guys, i'm so confused :s ...
I've put a file in a folder which is made a couple of days ago, also in this folder are other folders (which are created or last modified or whatever couple months or years ago).. so actually the folder i just made is the only new one

so i tried again
Code:
# find /folder/ -cmin 60
WITHOUT the '-' before the '60' because the man pages says:
Code:
 -cmin n
              Fileās status was last changed n minutes ago.
but i don't get any results....
and if i use

Code:
# find /folder/ -cmin -60
i get every file, folder, subfolder :s

can someone PLEASE explain what this is all about and why it's not working...

Thanks in advance
 
Old 04-20-2011, 02:10 AM   #6
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
i do now:
Code:
# find /tmp -name "*.*" -type f -mmin -60
and i get the 'right' result, i get the wanted file but the find commands check if it has changed within 60 minutes( probably because of the '-') but i need to get that file as a result when it has been 60 minutes ago...so i geuss it's without the '-'... but why don't i get the other files then???

am i doing something wrong??

Last edited by brownie_cookie; 04-20-2011 at 02:24 AM.
 
Old 04-20-2011, 02:29 AM   #7
ongte
Member
 
Registered: Jun 2009
Location: Penang, Malaysia
Distribution: Mageia, CentOS, Ubuntu
Posts: 468

Rep: Reputation: 72
Quote:
Originally Posted by brownie_cookie View Post
...
P.S.: which command do i use to know which distro i use?
You could try:

Code:
cat /etc/*release
 
1 members found this post helpful.
Old 04-20-2011, 02:31 AM   #8
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
Quote:
Originally Posted by ongte View Post
You could try:

Code:
cat /etc/*release
thx
Code:
Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
do you know what my problem is with the find command?
 
Old 04-20-2011, 03:01 AM   #9
ongte
Member
 
Registered: Jun 2009
Location: Penang, Malaysia
Distribution: Mageia, CentOS, Ubuntu
Posts: 468

Rep: Reputation: 72
You also have to use + / - for more than or less than. You can even specify a range.

For modified more than 60 mins ago:
Code:
# find /some/folder -mmin +60
For more than 30 mins but less then 60 mins:
Code:
# find /some/folder -mmin +30 -mmin -60
 
1 members found this post helpful.
Old 04-20-2011, 03:07 AM   #10
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
yeah, i found it too just saw your post

but thx ^^ !!!

this is my command:
Code:
VAR=`find $dirpath -name "*.*" -type f -mmin +60 | wc -l`
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
disk usage by file age michael.barnes Linux - General 1 06-30-2010 02:29 PM
Assign file name to a variable w/out knowing file name... dots Linux - Newbie 3 07-02-2009 03:19 PM
Knowing if the File is already in use or open. sameergk Programming 1 10-10-2006 04:33 AM
file age checking Oinopion Slackware 8 03-11-2006 06:37 AM
Can't get Age of Empires II: Age of Kings started (I've could it before !!!) vegetassj2 Linux - Games 44 08-28-2005 04:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:44 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration