Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Every day 2 files are added to a directory, I need to get the latest added file and copy this to a directory for further upload. After this the folder is emptied. I would like to automate this in a batch process.

So far with Putty I only manage to copy the entire directory or manually type the name in the get command. Don't know if this might help but all files start with yyyymmdd1200 or yyyymmdd1600.

Any help is greatly appreciated

share|improve this question
    
How is this related to putty? To my understanding, this is a shell/scripting issue, in which case it may be useful to know the shell you are using (bash, tcsh, zsh, etc.). Putty may be the program you use to connect to the system you're using, but I don't know of a way to directly use it to accomplish what you want. –  GreenMatt Jan 7 '13 at 14:54

1 Answer 1

up vote 0 down vote accepted

Use following:

mv `\ls -t *00 | head -1` -t target_directory

this will move youngest file ending with 00 to target directory

rm *1200 *1600 

this will clear the directory after moving above file.

share|improve this answer
    
Thanks this works! We have a sftp server so a small workaround is required, your scripts works with a SSH server. –  user185080 Jan 7 '13 at 16:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.