LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-22-2008, 07:14 AM   #1
parasdua
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Rep: Reputation: 0
shell script to find modified date and last accessed date of any file.


Hi!
Plz tell me the shell script to find the modified date and last accessed date of any file ASAP!!
 
Old 04-22-2008, 07:20 AM   #2
laucian
Member
 
Registered: Oct 2005
Distribution: Ubuntu 9.04
Posts: 124
Blog Entries: 2

Rep: Reputation: 15
it smells like "homework" spirit..even though, here is the answer of all your questions..click
 
Old 04-22-2008, 07:21 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1986Reputation: 1986Reputation: 1986Reputation: 1986Reputation: 1986Reputation: 1986Reputation: 1986Reputation: 1986Reputation: 1986Reputation: 1986Reputation: 1986
Why ASAP?!? This smells as homework... anyway go through the find and stat commands.
 
Old 04-22-2008, 08:03 AM   #4
parasdua
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Original Poster
Rep: Reputation: 0
ls?

would the following b ok?

for modified time:

ls -lart --full-time

for last accesed time:

ls -laru --full-time

Also how can i do it using pipes?

Last edited by parasdua; 04-22-2008 at 08:07 AM.
 
Old 04-22-2008, 08:11 AM   #5
laucian
Member
 
Registered: Oct 2005
Distribution: Ubuntu 9.04
Posts: 124
Blog Entries: 2

Rep: Reputation: 15
ok i think you need some starter help..

1.
pipes in linux are the commands that you add to each other like a chain...for example, using ps -ef you can list all your running processes und with grep init you can select the lines including init in them..piping them is just combining them

Code:
ps -ef | grep init
2.you need to get familiar with bash scripting..
there are good tutorials on internet..here is one them
http://www.linuxconfig.org/Bash_scripting_Tutorial

just forget your homework for some time, and read this tutorial(which will also give you some ideas about using the pipes)

then start typing your code..if you have problems then paste your code here and ask questions..but do not expect an whole code from someone else..

i hope this one helps a bit
 
Old 04-22-2008, 09:38 AM   #6
parasdua
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Original Poster
Rep: Reputation: 0
thx

thx a lot sir!
 
Old 04-22-2008, 09:59 AM   #7
ksri07091983
Member
 
Registered: Nov 2007
Location: Chennai,TamilNadu,India
Distribution: RedHat,SuSE
Posts: 65

Rep: Reputation: 15
Hi Parasdua

just tried to write a script similar to your requirement.

Code:
#!/bin/bash
#Author: K.Sridhar
#mod_acc.sh: script to find last modified and last accessed time of a file
E_NOARG=65
E_MOREARG=66
if [  $# = 0 ]
then
        echo -e '\E[31m' "Usage: $0 <filename>"
        tput sgr0
        exit $E_NOARG
elif [ $# -gt 1 ]
then
        echo -e '\E[31m' "Please give only one file at a time"
        tput sgr0
        exit $E_MOREARG
fi
LS=`which ls`
MOD_TIME=`$LS -lart $1|cut -f6,7,8 -d" "`
ACC_TIME=`$LS -laru $1|cut -f6,7,8 -d" "`
echo "The modified time of the file is $MOD_TIME"
echo "The accessed time of the file is $ACC_TIME"
Thanks

Sridhar
 
  


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
Shell Script for Unix Date ??? ajeetraina Linux - Newbie 11 02-08-2008 12:58 AM
[bash] Seeing if a file has been modified before/after a date w3stfa11 Programming 7 10-15-2006 06:02 PM
Shell Script.. Date format handling C-RAF. Programming 2 02-14-2006 08:34 AM
php read file creation, modified date problem antony_csf Programming 3 08-18-2004 06:46 AM
Where can I look for the config file for modified date and time ForumKid Linux - General 1 09-19-2003 08:05 AM

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

All times are GMT -5. The time now is 01:25 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