Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .