help: find and modified files script

hello all im a newbie in the linux world ..i have just started creating basic scripts in linux ..i am using rhel 5 ..the thing is i wanted to create a find script where i could find the last modified file and directory in the directory given as input by the user and storing the output in a file so i tried

echo"enter the file you want to search in";
read " " >> a;
/usr/bin/find echo $a -mtime +1 -exec basename {} >> modifies_files.txt \

please help me on this asap ..i can understand there are certain flaws in the script and would greatly appreciate the help
thank you
kumar

try using this..

 
read a?"enter the file you want to search in"
find . -name $a -mtime +1 -exec basename {} \;>>modifiedfiles

I don't know if this *has* to use find... I hope a different approach is OK. The ls command has the ability to sort by modification time. For example, the command ls -alt will sort by mod time, showing long format for all files.

I hope tcsh is acceptable... that's the shell that happened to pop to mind...

#!/bin/tcsh

echo -n "What directory do you want to check? "
set dir = $<

ls -alt $dir | tail +2 | head -n 1

That will output to the shell. It looked like you already know how to modift to send the output to a file instead, so I won't worry about that. Also, you might need to massage the tail value a little to get it working with your OS. If you post the exact output of ls -alt from your command line, we should be able to whip it into shape.

printf "%s: " "Enter the directory you want to search in"
IFS= read -r dir
cd "$dir" || exit 1
last_modified=$(
    ls -t | {
        IFS= read -r file
        printf "%s\n" "$file"
    } )

thanks vidyasagar , treesloth and cfajohnson ..u guys are awesome and truly rockstars ..well treesloth i tried running ur script it gave me some errors here was one of the outputs frm ur script

"What directory do you want to check? /usr/bin/tail: cannot open `+2' for reading: No such file or directory"

the script looked like this
#!/bin/bash /(Changed from /bin/tcsh to /bin/bash)/
echo -n "What directory do you want to check? ";
set dir = $;

/bin/ls -alt $dir | /usr/bin/tail +2 | /usr/bin/head -n 1 ;

i edited the file and put the whole path of the ls tail and head commands .
and the output of command ls -lrt is

total 128
-rw-r--r-- 1 root root 4478 Sep 17 08:28 install.log.syslog
-rw-r--r-- 1 root root 32645 Sep 17 08:28 install.log
-rw------- 1 root root 1232 Sep 17 08:28 anaconda-ks.cfg
-rw-r--r-- 1 root root 480 Sep 24 06:38 gvustudentsbatch1.txt
-rw-r--r-- 1 root root 78 Sep 26 07:32 a.txt
-rw-r--r-- 1 root root 66 Sep 26 07:37 b.txt
drwxr-xr-x 9 root root 4096 Oct 8 16:04 Desktop
-rw-r--r-- 1 root root 0 Oct 8 16:25 tarun
-rw-r--r-- 1 root root 0 Oct 8 16:26 a
-rwxrwxrwx 1 root root 81 Oct 8 18:44 latest.sh
drwxr-xr-x 2 root root 4096 Oct 8 18:46 untitled folder
-rwxrwxrwx 1 root root 122 Oct 10 16:12 mod.sh
-rwxrwxrwx 1 root root 191 Oct 10 16:15 mod1.sh

cfajohnson i tried running ur script too ..it ran perfectly fine it solved first part of desired result which i wanted ...but the thing is .i ran your script , it was asking for a input from the user ...after that the script exited and returned nothing..as in the script ran it asked me to enter the name of the directory i wanted to find the modified files in ..then the output was blank
here is the output
[root@server1 ~]# ./mod1.sh /(i renamed the script as mod1.sh)/
Enter the directory you want to search in: /root /(i gave /root directory)/
[root@server1 ~]#

guys it would be awesome ..if some one can guide me ...what should i do....

The script I posted stores the result in a variable so that you can work with it.

If you want to display the result, add a printf statement to do so.