copying currentfile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copying currentfile
# 1  
Old 02-10-2007
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
# 2  
Old 02-11-2007
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

Code:
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

Code:
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>


Last edited by ahmedwaseem2000; 02-11-2007 at 04:43 AM..
# 3  
Old 02-11-2007
copying current file

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
# 4  
Old 02-11-2007
another way i ust thought of

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 ;-)
# 5  
Old 02-11-2007
Code:
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:

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

# 6  
Old 02-11-2007
Quote:
Originally Posted by shary
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
You could as well try the absolute path this way
cp <source folder name>/$filename <target Dir Name>
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in copying the file once

hi all , i had a following problem in my script filename=oas/data/output.txt printf"content1" >> $filename printf"content2" >> $filename printf"content3" >> $filename printf"content4" >> $filename printf"content5" >> $filename printf"content6" >> $filename my contents are different... (6 Replies)
Discussion started by: hemanthsaikumar
6 Replies

2. Shell Programming and Scripting

copying with a certain extension

trying to copy all the files without extension then add "*.txt" but its not working is there any other way and i do not want to use cpio -vdump just want to use copy command FROM=/usr/share/doc TO=/aleza/doc #the follow function copies all the files without extensions call(){ cd $FROM... (3 Replies)
Discussion started by: elginmulizwa
3 Replies

3. UNIX for Dummies Questions & Answers

Please, I need help with copying a file.

Hello. I don't know much about UNIX. Here is a problem I need to resolve. There is a file "file1.txt". It contains the line "End Of Copy" somewhere in the middle. I need to copy file1.txt to another file, "file2.txt" until this line. So, if the "file1.txt" is Line 1 Line 2 Line 3... (3 Replies)
Discussion started by: Eugene
3 Replies

4. Solaris

Copying Files and

I am new user to solaris and installed solaris operating system on full Harddisk 120Gb. I am unable to copy music files to desktop and /home directory. One thing happened while registering is- i entered login-root and its password. The message prompted your system is crashed. Is it because of... (1 Reply)
Discussion started by: patilmukundraj
1 Replies

5. Programming

Copying!

Can anybody point out the difference between shallow copying, deep copying and bitwise copying in C++? (2 Replies)
Discussion started by: areef4u
2 Replies

6. UNIX for Dummies Questions & Answers

copying file

is there anyway to copy a file which i don't have permission? (1 Reply)
Discussion started by: dakid
1 Replies

7. UNIX for Dummies Questions & Answers

copying a file to another

hi group... needed some help regarding this requirement actually we have a set of zip files in a server we have two types of zip files one as usual .zip extension and one with .zip_m extension... we need to copy the files from .zip_m extension to .zip extension with same file name ... it... (2 Replies)
Discussion started by: madhu_aqua14
2 Replies

8. Programming

copying a file

hello, i have to copy a file from one directory to another directory in linux. how to do this using a c function? kindly ans to my query. thanks (2 Replies)
Discussion started by: svh
2 Replies

9. UNIX for Dummies Questions & Answers

copying

I am using AIX version 5.1 I would like to copy my log files to another directory and timestamp them or add the date to the file name so I can distinguish them apart and keep 4weeks of files in this directory. so I usally do this cp rptlog /dump/backup.log.files I would like the the file... (5 Replies)
Discussion started by: rocker40
5 Replies
Login or Register to Ask a Question