copying the latest file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copying the latest file
# 8  
Old 05-23-2008
Code:
latest_file=`ls -ltr | tail -1| awk '{print $9}'`

cp $latest_file <source_destination>

This is the simplest way you can do it.. This should not have any problems..
# 9  
Old 05-23-2008
copying the latest file

thank you its working fine when i am in the normal unix mode but when i login into a remote server thru ftp this command is not working..
Is there any other command that shud be used when u r in ftp mode.

Thanks.
# 10  
Old 05-23-2008
If you are using ftp, use the fllowing commands:


Code:
recv remote-file [local-file]

This would Copy remote file to local PC

Code:
send local-file [remote-file]

This would copy local file to remote host.
# 11  
Old 05-23-2008
copying the latest file

recv remote-file [local-file]
how can we get the file name in the place of [local_file] in the above cmd.
do we have to use any other cmd for that if so pls let me know the cmd also.

thanks.
# 12  
Old 05-23-2008
I guess you are not reading all the posts for this thread..

Code:
latest_file=`ls -ltr | tail -1| awk '{print $9}'`

This has the file you want to copy right..?
# 13  
Old 05-23-2008
copying the latest file

I tried using the same cmd in the ftp mode but it throws the foll error.
usage: ls remote-directory local-file

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Picking the latest file based on a timestamp for a Dynamic file name

Hi , I did the initial search but could not find what I was expecting for. 15606Always_9999999997_20160418.xml 15606Always_9999999998_20160418.xml 15606Always_9999999999_20160418.xml 9819Always_99999999900_20160418.xml 9819Always_99999999911_20160418.xmlAbove is the list of files I... (4 Replies)
Discussion started by: chillblue
4 Replies

2. Shell Programming and Scripting

Shell script to get the latest file from the file list and move

Hi, Anybody help me to write a Shell Script Get the latest file from the file list based on created and then move to the target directory. Tried with the following script: got error. A=$(ls -1dt $(find "cveit/local_ftp/reflash-parts" -type f -daystart -mtime -$dateoffset) | head... (2 Replies)
Discussion started by: saravan_an
2 Replies

3. Shell Programming and Scripting

Perl : copying only the latest file to other directory

In linux.. In a directory there are 3 files which I want to copy only the latest file (ls -ltr myfiles*.txt|tail -1) to other directory in perl? Could anyone please help me with the code? Regards, J (1 Reply)
Discussion started by: scriptscript
1 Replies

4. UNIX for Dummies Questions & Answers

latest files copying over to new path

ls -lrt | nawk -v D="$(date +'%b%e:'| sed 's/ //g')" 'D==$6$7":"{sub(".*"$9,$9);print}' This picks only the latest files created based on the timestamp for that particular day.. how do i copy over the same files to a different location???? (1 Reply)
Discussion started by: win4luv
1 Replies

5. Shell Programming and Scripting

Copying a directory structure with the latest versions of files

Hello I have three directory structures for code releases. Each directory structure looks like this: bash-3.00$ ls -R | more .: Test_Release_1 Test_Release_2 Test_Release_3 ./Test_Release_1/dbcode: rp_online_import_srdp.pkb-1 srdp_ar_validation.pkb-1... (1 Reply)
Discussion started by: Glyn_Mo
1 Replies

6. Shell Programming and Scripting

To get the latest file

Hi Experts Team, I wish to store the latest file name of partcular pattern in the remote server in a variable. i tried this LATEST_FILE=`ssh ${USER_ID}@${REMOTE_HOSTNAME} 'ls -t ${SOURCE_DIRECTORY}/${SOURCE_FILEPATTERN}'` but its nt working..pls guide me.. Regards, Kanda (2 Replies)
Discussion started by: spkandy
2 Replies

7. Shell Programming and Scripting

get latest file

i have the following in my directory x: 3 files with the word "LIST" inside the files 2 files without the word "LIST" 1 folder (sudirectory) i want to get the filename of the latest file (timestamp) with the word "LIST". by the way the script and the list of files are in seperate... (4 Replies)
Discussion started by: inquirer
4 Replies

8. Shell Programming and Scripting

Copying latest file into a folder

Hello all, this is my first post while i am trying to understand unix. I would basically like to know if i can do this: Lets say i have a folderA and folderB And i save something in folderA Can i make a script that checks folderA latest file, then compares it with the date of latest file in... (16 Replies)
Discussion started by: takissd
16 Replies

9. Shell Programming and Scripting

How do I get the name of latest file?

1) How do I get the name of latest file in a variable? 2) Is it safe to delete all files from a dir I am doing cd $dir_name if return_code > 0 rm * fi what are other alternates to delete all files from a dir in a shell script? :) (5 Replies)
Discussion started by: Hangman2
5 Replies

10. UNIX for Dummies Questions & Answers

Copying files with the latest date

Hi All, I have a situation where I need to copy the files having the latest date. For example I have a file by name bas100e1_jun05. I need to copy it to bas100e1. But when a file by name bas100e1_jul05 is put in the same directory the script should copy the file having the latest month which... (34 Replies)
Discussion started by: shashi_kiran_v
34 Replies
Login or Register to Ask a Question