Search code examples
bashshellncftp

How to get a filename list with ncftp?


So I tried

ncftpls -l

which gives me a list

-rw-r--r--    1 100        ftpgroup      3817084 Jan 29 15:50 1548773401.tar.gz
-rw-r--r--    1 100        ftpgroup      3817089 Jan 29 15:51 1548773461.tar.gz
-rw-r--r--    1 100        ftpgroup      3817083 Jan 29 15:52 1548773521.tar.gz
-rw-r--r--    1 100        ftpgroup      3817085 Jan 29 15:53 1548773582.tar.gz
-rw-r--r--    1 100        ftpgroup      3817090 Jan 29 15:54 1548773642.tar.gz

But all I want is to check the timestamp (which is the name of the tar.gz) How to only get the timestamp list ?

As requested, all I wanted to do is delete old backups, so awk was a good idea (at least it was effective) even it wasn't the right params. My method to delete old backup is probably not the best but it works

ncftpls *authParams* | (awk '{match($9,/^[0-9]+/, a)}{ print a[0] }') | while read fileCreationDate; do
    VALIDITY_LIMIT="$((`date +%s`-600))"
    a=$VALIDITY_LIMIT
    b=$fileCreationDate
    if [ $b -lt $a ];then
        deleteFtpFile $b
    fi
done;

Solution

  • You can use awk to only display the timestamps from the output like so:

    ncftpls -l | awk '{ print $5 }'