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
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.
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 = $;
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 ~]#