SFTP: return number of files in remote directory?

前端 未结 4 1454
谎友^
谎友^ 2021-01-13 11:34

I sent a batch of files to a remote server via SFTP. If it were a local directory I could do something like this ls -l | wc -l to get the total number of files.

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-13 12:11

    echo ls -l | sftp server | grep -v '^sftp' | wc -l
    

    If you want to count the files in a directory the directory path should be put after the ls -l command like

    echo ls -l /my/directory/ | sftp server | grep -v '^sftp' | wc -l
    

提交回复
热议问题