简体   繁体   中英

How to get list of files alphanumerically greater than text specified in Linux command line (bash) via ftp connection?

I have new job and instead of designing and solving complicated problems in C++ architecture on Windows, I have to finish issues using bash scripts on Linux. I forgot bash commands and haven't ever written any .sh script. So now I have environment running and I am connected to remote folder via ftp. My simple problem is following: There are files like batch_something20160818012830, batch_something20160818012925, batch_something20160818013100, .. and the end of the filename is date time, for example batch_something20160818012830 has date 8.18.2016 and time 1:28:30, all of the filenames have same length and I need to get all the filenames alpanumerically larger then some datetime, for example I want larger than 8.18.2016 1:29:30, so I create text batch_something20160818012930 and I want to compare this text with filenames and get filenames greater than it, so batch_something20160818012925 and batch_something20160818013100 from the 3 above, how to do it? I need it to be working via ftp, so I found commands ls and dir and there will be a lot of the files so if it's possible, then I want to receive only the final file names without sending the list of all files inside the remote folder.

Maybe ls/dir --ignore=PATTERN or somehow use ls/dir with regex?

EDIT: I am already connected via ftp -i localhost and the amount of files can be big, so I think that using pipes to send some semi-results between commands is not good and I would prefer to use 1 command does the work on it's own.

lftp "-e cls -1 --sort name; quit" ftp://ftp.kernel.org:/pub/linux/kernel/v4.x|sed -n '/patch-4.5.xz/,$p'

Use lftp to logint to ftp, get a list in alphabetically order ( --sort ), quit; then piping it to sed which cuts the heading lines before the match patch-4.5.xz , so you get the alphabetically larger files list on stdout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM