Retrieving the last modified file in a directory over FTP using a bash script with curl

前端 未结 2 1890
粉色の甜心
粉色の甜心 2021-01-22 02:27

I\'m writing a bash script and one of the tasks which needs performing is to connect to an FTP server via curl and find the name of the last modified .zip file.

The name

2条回答
  •  半阙折子戏
    2021-01-22 02:52

    Edit: Sorry I just realised that the files you need were on the remote FTP server. I had thought they were local, and you were hoping to upload to FTP. So everything below is irrelevant.

    Typically I do something like: ls -1rt /path/to/zips/*.zip | tail -n1

    This is not always a good idea, spaces in file names etc. But it will return the most recent file name in the directory.

    There's also find. You can specify a date range, and name. Depending on what you are doing, you might opt to scan a directory every x minutes for files created in the last x minutes. This has the advantage that it will pick up multiple new files.

提交回复
热议问题