get_multiple files

I need the shell script to get the last 5 files from the recently modified files.

I know that i have to some how loop and get the result, but not sure!

Can someone help!

Please state what Operating System and version you are running and what Shell you use.

Please expand your post substantially to include example directory listings (blotting anything confidential with X's) and a full description of the process and sample matching output.

Simple answer based on the information provided would be:

ls -latr | tail -5

Or.
ls -1tr | tail -5

Thanks for the reply! Am using XP os, and the bash shell!

I have got a bunch of files which are ftp'd on a box. i can list them.. out of them, i need the names of the lastest 5 updated files[Sorting by time] Assuming 5 files gets posted for a day.

otherwise, i need the script which can give me the names of the files posted the day before.[Sorting by date]

---------- Post updated at 04:37 PM ---------- Previous update was at 04:29 PM ----------

Methyl,
Hope i can explain more clearly!!
i am on one particular server [say xyz] and i can use the command "ftp" to connect to remote server to see the files on a particular directory [abc] on that server.

Now my script on my sever [xyz] should give me the files uploaded to the directory on the remote server on that particular directory [abc] the day before, assuming we are running the script today!

Now that we know that there is more than one server involved here and that "ftp" is involved, please post the exact Operating System and version of both servers and the product and version of ftp on both servers.

If Microsoft software is involved we will need Server O/S and ftp software versions to the last decimal place.

Please note that "ftp" is not Shell. Any commands I posted earlier are not necessarily relevant to "ftp" (it all depends on what environment we have here).

Please post what relevant commands you have tried (including any error messages) or other useful information.

Big question. Do you have "root" or perhaps "Administrator" access to both of the remote server and the local server? Can you make changes on both servers?

Please do post detailed examples describing input , processing and expected output.

both the servers have microsoft XP os i have IPv6 , but i dont know about product version of ftp on the remote server.

I have used the following script

#!/bin/sh
SERVER=example.com
DIR=some_directory
FILE="$(echo ls -t | sftp -b- $SERVER:$DIR | head -n2 | tail -n1)"
echo get "$FILE" | sftp -b- $SERVER:$DIR

and am getting an error. file not found.

yes,, and i have all access on both servers!

The script syntax does not make a lot of sense to me though I think that I know what you are trying to do.
Please post the output from:

#!/bin/sh
SERVER=example.com
DIR=some_directory
FILE="$(echo ls -t | sftp -b- $SERVER:$DIR | head -n2 | tail -n1)"
echo "${FILE}"

I suspect that this output will contain either error messages, nothing, or MSDOS directory listing detail. My guess is error messages.

Ps. It is extraordinarily difficult to get a files list in updated date order from a Microsoft ftp server. The secret is to change the environment variable DIRCMD for the account concerned (see help "dir"). This is an old MSDOS trick which still works for Windows.

Hi, My error message is "file not found".

" The secret is to change the environment variable DIRCMD for the account concerned (see help "dir"). This is an old MSDOS trick which still works for Windows. " Am sorry, i didnt understand this!

this is probably because, as stated above, ftp is not a shell. It's very simple and stupid, so has no idea what to do with "ls -t".

Some randomly selected quotes from O/P.

We have reached Post #9 an I have no real idea what release kit software is involve on either computer here or whether this is a question about unix or Linux or Windows XP or whatever. It is also not clear whether the Shell commands posted are actually being typed into a "ftp" session.