大网数据广告活动
服务器运维问答

ls -lt not working in SFTP

· 52CE 我爱测

I log into sftp: sftp user@server Then I run: ls -lt I expect files to be sorted by date. sftp> ls -lt *.csv -rw------- 0 76547986 200 5073032 Mar 14 08:42 file1.csv -rw------- 0 76547986 200 5073032 Mar 15 08:41 file2.csv -rw---…

问题原文

原帖链接 · cheesesticksricepuck · CC BY-SA 3.0

I log into sftp:

sftp user@server

Then I run:

ls -lt

I expect files to be sorted by date.

sftp>  ls -lt *.csv
-rw-------    0 76547986 200       5073032 Mar 14 08:42 file1.csv
-rw-------    0 76547986 200       5073032 Mar 15 08:41 file2.csv
-rw-------    0 76547986 200       5073032 Mar 16 08:41 file3.csv
-rw-------    0 76547986 200       5072802 Mar 17 08:42 file4.csv
-rw-------    0 76547986 200       1117736 Sep 30 14:44 file5.csv
-rw-------    0 76547986 200       1120419 Oct  2 08:45 file6.csv
-rw-------    0 76547986 200       1119763 Oct  1 08:43 file7.csv
-rw-------    0 76547986 200       5073258 Mar 13 08:41 file8.csv

But they are not.

Here is the version of OpenSSH

OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016

Any idea why date sorting for ls in sftp is not working?

NOTE: ls -lt works in bash on the sftp server just not through sftp prompt. Maybe a bug in sftp?

已采纳解答

原帖链接 · Martin Prikryl · CC BY-SA 4.0

If the ls argument includes a mask (and the mask does not match a single folder only), all sorting flags are ignored.

Note a lack of LS_*_SORT flags use in the do_globbed_ls function.

Contrary to non-globbed do_ls_dir.


It seems like a bug to me. Hence I have posted a bug report:
sftp ls command ignores sorting flags for globbed listing

A fix is included since OpenSSH 7.6.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-03-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。