[英]Linux - Format ls -l command
I'm executing the ls
command in Java using JSCH. 我正在使用JSCH在Java中执行
ls
命令。 I'm trying to format the output by separating it by comma's using the following command: 我正在尝试通过使用以下命令用逗号分隔输出来格式化输出:
ls -l | sed 's/ */,/g'
This works for most cases, but fails for file/directory names which contain spaces. 在大多数情况下,此方法有效,但对于包含空格的文件/目录名称,则无效。 The spaces of the file name will also be split.
文件名的空格也将被分割。 This shouldn't happen.
这不应该发生。
The comma at log,06-11-2018
shouldn't be there because both indices are part of the filename. log,06-11-2018
的逗号不应该在log,06-11-2018
出现,因为两个索引都是文件名的一部分。 Does anyone a solution to this? 有人对此有解决方案吗?
The right way is to use SFTP (thus Jsch's ChannelSftp). 正确的方法是使用SFTP(因此是Jsch的ChannelSftp)。
See https://epaul.github.io/jsch-documentation/javadoc/com/jcraft/jsch/ChannelSftp.html#ls-java.lang.String- for more information. 有关更多信息,请参见https://epaul.github.io/jsch-documentation/javadoc/com/jcraft/jsch/ChannelSftp.html#ls-java.lang.String- 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.