copying currentfile

Dear Experts

in my system after some time the new file is generating
ans the naming convention can be of any type of that file
so what i need i just want to make a script which will run and copy the current file to my folder cany any one tell me how to do this ...........

take care
Regards,
shary

you could acheive this by 2 methods. first one with the find command and the second one with the ls command. you could try the option

find <Path to search> -mtime <current time> -name * -print {}|xargs cp <target foldername>

Note: In the above command event the sub directories would be included

or


ls -ltr <path> >result # this will give you the last line as the most recent file
sed -n '$p' <path/filename>| awk '{print $9}' | read filename#this will give you the filename
cp filename <target folder>


Dear Experts

i am already in that director where i want the latest file.
so i am using this command but its not working properly can any body tell me whats wrong in this.
#ls -lrt|sed -n '$p' |awk '{print $9}' |read abc |cp abc /home/SHARY/

but after executing this command it will give the message
cp :cannot stat 'abc' :no such file or directory

please correct the syntax

Regards,
shary

cat file | tee $OLDPWD
cat file > $OLDPWD

this should work from where ever you are in the database. if you hit cd <enter>
this will place you in your home directory. from there type the word set

you might do a set | page you can view it slowly. Look for OLDPWD this is where it will be placed :wink:

cp "$(ls -t|head -1)" /your/dir

If you have no spaces (or other pathological characters)
in the file names, you can do it like this:

set -- $(ls -t)
cp "$1" /your/dir

You could as well try the absolute path this way
cp <source folder name>/$filename <target Dir Name>